{"record":{"id":"5510386599db8a0c","repo":"googleapis/mcp-toolbox","slug":"invalid-notification-request-w","errorCode":null,"errorMessage":"invalid notification request: %w","messagePattern":"invalid notification request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/server/mcp/mcp.go","lineNumber":50,"sourceCode":"\t\"github.com/googleapis/mcp-toolbox/internal/util\"\n)\n\n// ProtocolOptions contains configuration passed during server initialization to protocol handlers.\ntype ProtocolOptions struct {\n\tDisableExt []string\n}\n\n// InitializeProtocols performs version-specific protocol setup across all supported MCP versions.\nfunc InitializeProtocols(opts ProtocolOptions) {\n\tv20260728.Initialize(opts.DisableExt)\n}\n\n// NotificationHandler process notifications request. It MUST NOT send a response.\n// Currently Toolbox does not process any notifications.\nfunc NotificationHandler(ctx context.Context, body []byte) error {\n\tvar notification jsonrpc.JSONRPCNotification\n\tif err := json.Unmarshal(body, &notification); err != nil {\n\t\treturn fmt.Errorf(\"invalid notification request: %w\", err)\n\t}\n\t// Since we do not enforce notifications, we do not need to check the\n\t// `Mcp-Method` header here\n\treturn nil\n}\n\n// ProcessMethod returns a response for the request.\n// This is the Operation phase of the lifecycle for MCP client-server connections.\nfunc ProcessMethod(ctx context.Context, mcpVersion string, id jsonrpc.RequestId, method string, g group.Group, primitiveMgr *primitives.PrimitiveManager, 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\tswitch mcpVersion {\n\tcase mcputil.VERSION_20260728:\n\t\treturn v20260728.ProcessMethod(ctx, id, method, g, primitiveMgr, body, header)\n\tcase mcputil.VERSION_20251125:","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/mcp/mcp.go#L32-L68","documentation":"NotificationHandler parses an MCP notification body; since Toolbox does not process notifications, its only failure mode is that the body is not valid JSON or does not decode into a JSONRPCNotification. The underlying json.Unmarshal error is wrapped as \"invalid notification request: %w\".","triggerScenarios":"POSTing a notification (notifications/initialized, notifications/cancelled, etc.) with a malformed or non-JSON body, an empty body, or content-type/body mismatch (e.g. form-encoded or truncated payload).","commonSituations":"Hand-rolled MCP clients sending notifications with wrong JSON shape (missing jsonrpc/method fields); curl tests with quoting mistakes; intermediaries compressing or truncating the body; sending the notification to the wrong endpoint so a non-notification payload is parsed as one.","solutions":["Log/print the exact body being sent and confirm it is complete, valid JSON shaped like {\"jsonrpc\":\"2.0\",\"method\":\"...\"}.","Ensure the Content-Type is application/json and the body is not truncated or double-encoded.","Send the notification to the correct MCP endpoint path for the server version in use.","If testing manually, use a minimal valid notification payload via curl or an MCP SDK client instead of hand-crafting."],"exampleFix":"// before: malformed notification body\ncurl -X POST $URL -d 'notifications/initialized'\n// after: valid JSON-RPC notification\ncurl -X POST $URL -H 'Content-Type: application/json' \\\n  -d '{\"jsonrpc\":\"2.0\",\"method\":\"notifications/initialized\"}'","handlingStrategy":"validation","validationCode":"// Validate the notification before sending\nfunction isValidNotification(body) {\n  try {\n    const n = JSON.parse(body);\n    return n.jsonrpc === \"2.0\" && typeof n.method === \"string\";\n  } catch { return false; }\n}","typeGuard":"function isJSONRPCNotification(n) {\n  return typeof n === \"object\" && n !== null &&\n    n.jsonrpc === \"2.0\" && typeof n.method === \"string\" && n.id === undefined;\n}","tryCatchPattern":null,"preventionTips":["Always serialize notifications with JSON.stringify and Content-Type: application/json","Use SDK notification builders rather than hand-written JSON strings","Send notifications to the dedicated MCP endpoint, not other API routes"],"tags":["mcp","json","notification","request-validation"],"backgroundTag":"malformed-json-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"}