{"record":{"id":"1ca65de9afe205f1","repo":"googleapis/mcp-toolbox","slug":"internal-error","errorCode":"INTERNAL_ERROR","errorMessage":"unable to retrieve enableDraftSpecs from context","messagePattern":"unable to retrieve enableDraftSpecs from context","errorType":"http","errorClass":"jsonrpc.Error","httpStatus":null,"severity":"error","filePath":"internal/server/mcp/mcp.go","lineNumber":62,"sourceCode":"\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:\n\t\treturn v20251125.ProcessMethod(ctx, id, method, g, primitiveMgr, body, header)\n\tcase mcputil.VERSION_20250618:\n\t\treturn v20250618.ProcessMethod(ctx, id, method, g, primitiveMgr, body, header)\n\tcase mcputil.VERSION_20250326:\n\t\treturn v20250326.ProcessMethod(ctx, id, method, g, primitiveMgr, body, header)\n\tcase \"\", mcputil.VERSION_20241105:\n\t\treturn v20241105.ProcessMethod(ctx, id, method, g, primitiveMgr, body, header)\n\tdefault:\n\t\treturn jsonrpc.NewUnsupportedProtocolVersionError(id, mcpVersion, enableDraft)\n\t}\n}\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/mcp/mcp.go#L44-L80","documentation":"ProcessMethod reads the enableDraftSpecs flag from the request context via util.EnableDraftSpecsFromContext; if the value was never injected into the context (it should be set by the HTTP handler middleware before dispatch), it returns an INTERNAL_ERROR. This indicates an internal wiring bug rather than a client mistake.","triggerScenarios":"Calling ProcessMethod directly (tests, custom embeddings) with a bare context.Context that lacks the enableDraftSpecs value; a server code path that builds the context without running the middleware that stores the flag.","commonSituations":"Custom forks or wrappers around the MCP server that bypass the standard httpHandler; unit/integration tests constructing requests manually; upgrades where middleware registration was dropped.","solutions":["Ensure requests go through the standard server handler that injects the enableDraftSpecs value into the context (util.WithEnableDraftSpecs or equivalent).","If calling ProcessMethod directly, add the flag to the context first: ctx = util.WithEnableDraftSpecs(ctx, true|false).","Update the toolbox binary/server wiring if you patched or forked internal handlers.","Report/inspect upstream if a stock server path reproduces this — it signals missing middleware in that path."],"exampleFix":"// before: direct call with a plain context\nres, err := mcp.ProcessMethod(ctx, ver, id, method, g, pmgr, body, hdr)\n// after: inject the draft-specs flag expected by ProcessMethod\nctx = util.WithEnableDraftSpecs(ctx, false)\nres, err := mcp.ProcessMethod(ctx, ver, id, method, g, pmgr, body, hdr)","handlingStrategy":"try-catch","validationCode":"_, ok := util.EnableDraftSpecsFromContext(ctx)\nif !ok {\n    ctx = util.WithEnableDraftSpecs(ctx, false)\n}","typeGuard":null,"tryCatchPattern":"res, err := mcp.ProcessMethod(ctx, ver, id, method, g, pmgr, body, hdr)\nif err != nil && strings.Contains(err.Error(), \"enableDraftSpecs\") {\n    ctx = util.WithEnableDraftSpecs(ctx, false)\n    res, err = mcp.ProcessMethod(ctx, ver, id, method, g, pmgr, body, hdr)\n}","preventionTips":["Route all MCP traffic through the stock HTTP handler that injects context values","In tests, always build contexts with util.WithEnableDraftSpecs before calling ProcessMethod","Treat INTERNAL_ERROR responses as server wiring bugs and check middleware setup first"],"tags":["mcp","context","internal-error","middleware"],"backgroundTag":"missing-context-value","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"}