{"record":{"id":"1f58e66defd210aa","repo":"googleapis/mcp-toolbox","slug":"invalid-request-1f58e6","errorCode":"INVALID_REQUEST","errorMessage":"invalid mcp initialize request: %w","messagePattern":"invalid mcp initialize request: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/mcp/v20250326/method.go","lineNumber":73,"sourceCode":"\t\treturn promptsGetHandler(ctx, id, g, primitiveMgr, body)\n\tdefault:\n\t\terr := fmt.Errorf(\"invalid method %s\", method)\n\t\treturn jsonrpc.NewError(id, jsonrpc.METHOD_NOT_FOUND, err.Error(), nil), err\n\t}\n}\n\n// InitializeResponse runs capability negotiation and protocol version agreement.\n// This is the Initialization phase of the lifecycle for MCP client-server connections.\n// Always start with the latest protocol version supported.\nfunc initializeHandler(ctx context.Context, id jsonrpc.RequestId, body []byte) (any, error) {\n\tv, err := util.ToolboxVersionFromContext(ctx)\n\tif err != nil {\n\t\treturn jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err\n\t}\n\n\tvar req InitializeRequest\n\tif err := json.Unmarshal(body, &req); err != nil {\n\t\terr = fmt.Errorf(\"invalid mcp initialize request: %w\", err)\n\t\treturn jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err\n\t}\n\n\ttoolsListChanged := false\n\tpromptsListChanged := false\n\tresult := InitializeResult{\n\t\tProtocolVersion: PROTOCOL_VERSION,\n\t\tCapabilities: ServerCapabilities{\n\t\t\tTools: &ListChanged{\n\t\t\t\tListChanged: &toolsListChanged,\n\t\t\t},\n\t\t\tPrompts: &ListChanged{\n\t\t\t\tListChanged: &promptsListChanged,\n\t\t\t},\n\t\t},\n\t\tServerInfo: Implementation{\n\t\t\tBaseMetadata: BaseMetadata{\n\t\t\t\tName: SERVER_NAME,","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/mcp/v20250326/method.go#L55-L91","documentation":"initializeHandler unmarshals the request body into InitializeRequest. This INVALID_REQUEST error wraps the JSON unmarshal failure, meaning the body of an initialize request is malformed or does not match the MCP initialize schema (missing/incorrectly typed protocolVersion, capabilities, clientInfo).","triggerScenarios":"json.Unmarshal(body, &req) fails in initializeHandler because the body is not valid JSON or the fields don't match InitializeRequest's types.","commonSituations":"Hand-rolled MCP clients sending wrong field types (e.g. capabilities as a string); empty bodies; clients built against a divergent MCP schema; proxies mangling the payload.","solutions":["Send a valid JSON body matching the MCP InitializeRequest schema: {protocolVersion, capabilities, clientInfo}","Validate the payload with a JSON linter or MCP schema before sending","Check that Content-Type and encoding are correct and the body isn't truncated","Update the client SDK to a version compatible with the 2025-03-26 schema"],"exampleFix":"// before\n{\"protocolVersion\":\"2025-03-26\",\"capabilities\":\"all\"}\n// after\n{\"protocolVersion\":\"2025-03-26\",\"capabilities\":{},\"clientInfo\":{\"name\":\"my-client\",\"version\":\"1.0.0\"}}","handlingStrategy":"try-catch","validationCode":"const body = JSON.parse(raw)\nif (typeof body.protocolVersion !== \"string\" ||\n    typeof body.capabilities !== \"object\" ||\n    typeof body.clientInfo?.name !== \"string\") {\n  throw new Error(\"malformed initialize request\")\n}","typeGuard":"function isInitializeRequest(b: unknown): b is InitializeRequest {\n  const r = b as InitializeRequest\n  return typeof r === \"object\" && r !== null &&\n    typeof r.protocolVersion === \"string\" &&\n    typeof r.capabilities === \"object\" &&\n    typeof r.clientInfo === \"object\"\n}","tryCatchPattern":"try {\n  const res = await client.initialize(req)\n} catch (e) {\n  if (e.code === -32600) { // INVALID_REQUEST\n    console.error(\"initialize body rejected:\", e.message, JSON.stringify(req))\n  }\n  throw e\n}","preventionTips":["Use an official MCP client SDK instead of hand-rolled JSON","Validate initialize payloads against the MCP schema in tests","Log the raw body on -32600 responses to spot schema drift"],"tags":["go","mcp","json","initialize","invalid-request"],"backgroundTag":"json-unmarshal-failed","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"}