{"record":{"id":"90631d02ba3c520c","repo":"googleapis/mcp-toolbox","slug":"invalid-request-90631d","errorCode":"INVALID_REQUEST","errorMessage":"invalid server discover request: %w","messagePattern":"invalid server discover request: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/mcp/v20260728/method.go","lineNumber":173,"sourceCode":"\t\tnewMeta[k] = v\n\t}\n\t// copy the ResultMetaObject items over\n\tfor k, v := range resMeta {\n\t\tnewMeta[k] = v\n\t}\n\treturn newMeta, nil\n}\n\nfunc serverDiscoverHandler(ctx context.Context, id jsonrpc.RequestId, body []byte, header http.Header) (any, error) {\n\tenableDraft, ok := util.EnableDraftSpecsFromContext(ctx)\n\tif !ok {\n\t\terr := fmt.Errorf(\"unable to retrieve enableDraftSpecs from context\")\n\t\treturn jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err\n\t}\n\n\tvar req DiscoverRequest\n\tif err := json.Unmarshal(body, &req); err != nil {\n\t\terr = fmt.Errorf(\"invalid server discover request: %w\", err)\n\t\treturn jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err\n\t}\n\tvalidateHeaderErr, err := validateHeader(id, header, SERVER_DISCOVER, \"\")\n\tif err != nil {\n\t\treturn validateHeaderErr, err\n\t}\n\tvalidateErr, err := validateMetadata(id, req.Params, header == nil)\n\tif err != nil {\n\t\treturn validateErr, err\n\t}\n\n\ttoolsListChanged := false\n\tpromptsListChanged := false\n\tmeta, err := getResultMetadata(ctx, nil)\n\tif err != nil {\n\t\treturn jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err\n\t}\n\tresult := DiscoverResult{","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/mcp/v20260728/method.go#L155-L191","documentation":"serverDiscoverHandler unmarshals the request body into DiscoverRequest before doing anything else. If the JSON is malformed or doesn't match the expected shape (jsonrpc envelope with params), the wrapped error is returned as a jsonrpc INVALID_REQUEST error (internal/server/mcp/v20260728/method.go:173).","triggerScenarios":"POSTing a server/discover request whose body is not valid JSON, is empty, or has fields of the wrong type for DiscoverRequest (e.g. \"params\": \"string\" instead of an object).","commonSituations":"Hand-written curl/Postman requests with quoting mistakes; clients sending form-encoded or non-JSON payloads; a proxy truncating the body; JSON with BOM or trailing garbage.","solutions":["Validate the request body is well-formed JSON matching the JSON-RPC 2.0 structure with the correct params object.","Log/print the raw body before sending to spot encoding issues (BOM, encoding, truncation).","Use an official MCP client SDK to construct the request instead of hand-rolling JSON.","Ensure Content-Type is application/json so no intermediary transforms the payload."],"exampleFix":"// before\n-d '{jsonrpc: 2.0, method: server/discover}'  // invalid JSON\n// after\n-d '{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"server/discover\",\"params\":{}}'","handlingStrategy":"validation","validationCode":"function buildDiscoverRequest() {\n  const body = JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'server/discover', params: {} });\n  JSON.parse(body); // throws early if serialization is broken\n  return body;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await discover();\n} catch (e) {\n  if (e.code === -32600) { // INVALID_REQUEST\n    console.error('Malformed discover request:', e.message);\n    // re-serialize and retry\n  }\n}","preventionTips":["Always send application/json with well-formed JSON-RPC 2.0 envelopes.","Run JSON.parse on the payload before sending in scripts/tests.","Avoid hand-rolled JSON strings; use SDK serializers.","Check for encoding issues (BOM, truncation) introduced by proxies."],"tags":["mcp","json","invalid-request","go"],"backgroundTag":"invalid-json-in-request","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}