@@ -692,11 +692,11 @@ func generateAI5xxErrorResponse(op OpenAPIOperation, inputSchemaJSON []byte, arg
692692 // Add tool usage information for AI agents
693693 var schemaObj map [string ]any
694694 _ = json .Unmarshal (inputSchemaJSON , & schemaObj )
695-
695+
696696 if properties , ok := schemaObj ["properties" ].(map [string ]any ); ok && len (properties ) > 0 {
697697 response .WriteString ("\n TOOL USAGE INFORMATION:\n " )
698698 response .WriteString (fmt .Sprintf ("Tool Name: %s\n " , op .OperationID ))
699-
699+
700700 // Show required parameters
701701 if required , ok := schemaObj ["required" ].([]any ); ok && len (required ) > 0 {
702702 response .WriteString ("Required Parameters (mandatory for all calls):\n " )
@@ -716,11 +716,11 @@ func generateAI5xxErrorResponse(op OpenAPIOperation, inputSchemaJSON []byte, arg
716716 }
717717 }
718718 }
719-
719+
720720 // Generate example usage with correct parameters
721721 response .WriteString ("\n Example Usage (retry with these correct parameters):\n " )
722722 exampleArgs := map [string ]any {}
723-
723+
724724 // Add required parameters to example
725725 if required , ok := schemaObj ["required" ].([]any ); ok {
726726 for _ , req := range required {
@@ -731,7 +731,7 @@ func generateAI5xxErrorResponse(op OpenAPIOperation, inputSchemaJSON []byte, arg
731731 }
732732 }
733733 }
734-
734+
735735 // Add a few optional parameters for completeness
736736 count := 0
737737 for paramName , paramDef := range properties {
@@ -742,7 +742,7 @@ func generateAI5xxErrorResponse(op OpenAPIOperation, inputSchemaJSON []byte, arg
742742 }
743743 }
744744 }
745-
745+
746746 exampleJSON , _ := json .MarshalIndent (exampleArgs , "" , " " )
747747 response .WriteString (fmt .Sprintf ("call %s %s\n " , op .OperationID , string (exampleJSON )))
748748 }
@@ -1003,8 +1003,20 @@ func RegisterOpenAPITools(server *mcpserver.MCPServer, ops []OpenAPIOperation, d
10031003 }
10041004 // Build request body if needed
10051005 var body []byte
1006+ var requestContentType string
10061007 if opCopy .RequestBody != nil && opCopy .RequestBody .Value != nil {
1007- if mt := opCopy .RequestBody .Value .Content .Get ("application/json" ); mt != nil && mt .Schema != nil && mt .Schema .Value != nil {
1008+ // Check for application/json first, then application/vnd.api+json
1009+ mt := opCopy .RequestBody .Value .Content .Get ("application/json" )
1010+ if mt != nil {
1011+ requestContentType = "application/json"
1012+ } else {
1013+ mt = opCopy .RequestBody .Value .Content .Get ("application/vnd.api+json" )
1014+ if mt != nil {
1015+ requestContentType = "application/vnd.api+json"
1016+ }
1017+ }
1018+
1019+ if mt != nil && mt .Schema != nil && mt .Schema .Value != nil {
10081020 if v , ok := args ["requestBody" ]; ok && v != nil {
10091021 body , _ = json .Marshal (v )
10101022 }
@@ -1016,9 +1028,11 @@ func RegisterOpenAPITools(server *mcpserver.MCPServer, ops []OpenAPIOperation, d
10161028 if err != nil {
10171029 return nil , err
10181030 }
1019- if len (body ) > 0 {
1020- httpReq .Header .Set ("Content-Type" , "application/json" )
1031+ if len (body ) > 0 && requestContentType != "" {
1032+ httpReq .Header .Set ("Content-Type" , requestContentType )
10211033 }
1034+ // Set Accept header to accept both JSON and JSON:API responses
1035+ httpReq .Header .Set ("Accept" , "application/json, application/vnd.api+json" )
10221036 // --- AUTH HANDLING: inject per-operation security requirements ---
10231037 // For each security requirement object, try to satisfy at least one scheme
10241038 securitySatisfied := false
@@ -1134,7 +1148,7 @@ func RegisterOpenAPITools(server *mcpserver.MCPServer, ops []OpenAPIOperation, d
11341148 }
11351149
11361150 contentType := resp .Header .Get ("Content-Type" )
1137- isJSON := strings .HasPrefix (contentType , "application/json" )
1151+ isJSON := strings .HasPrefix (contentType , "application/json" ) || strings . HasPrefix ( contentType , "application/vnd.api+json" )
11381152 isText := strings .HasPrefix (contentType , "text/" )
11391153 isBinary := ! isJSON && ! isText
11401154
0 commit comments