{"record":{"id":"a0c62097dfc09d88","repo":"googleapis/mcp-toolbox","slug":"internal-error-a0c620","errorCode":"INTERNAL_ERROR","errorMessage":"unable to retrieve enableDraftSpecs from context","messagePattern":"unable to retrieve enableDraftSpecs from context","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/server/mcp/v20260728/method.go","lineNumber":167,"sourceCode":"\t\treturn resMeta, nil\n\t}\n\n\tnewMeta := make(map[string]any)\n\t// copy current Metadata into the new meta obj\n\tfor k, v := range curMeta {\n\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","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/server/mcp/v20260728/method.go#L149-L185","documentation":"serverDiscoverHandler reads the enableDraftSpecs flag from the request context via util.EnableDraftSpecsFromContext; it must always be present for server/discover requests. If missing, the context was not populated by the middleware/route that normally injects it, so the handler returns a jsonrpc INTERNAL_ERROR rather than guessing a default (internal/server/mcp/v20260728/method.go:167).","triggerScenarios":"Invoking serverDiscoverHandler through a custom route, test harness, or ProcessMethod path that bypasses the middleware which calls util.WithEnableDraftSpecs (or equivalent) to store the flag in ctx.","commonSituations":"Custom HTTP handlers wrapping the MCP processor without the spec-version middleware; unit/integration tests constructing a context manually; framework adapters that create a fresh context.Context for handlers.","solutions":["Route the request through the standard MCP server wiring so the middleware that injects enableDraftSpecs runs.","In tests or custom handlers, populate the context with util.WithEnableDraftSpecs(ctx, <bool>) before calling serverDiscoverHandler.","Update to a current toolbox version if you maintain a patched fork where the context-injection middleware was removed."],"exampleFix":"// before\nhandler(ctx, id, body, header) // ctx lacks the flag\n// after\nctx = util.WithEnableDraftSpecs(ctx, true)\nhandler(ctx, id, body, header)","handlingStrategy":"validation","validationCode":"// Go: ensure the context carries the flag before invoking the handler\nif _, ok := util.EnableDraftSpecsFromContext(ctx); !ok {\n    ctx = util.WithEnableDraftSpecs(ctx, false)\n}","typeGuard":null,"tryCatchPattern":"res, err := serverDiscoverHandler(ctx, id, body, header)\nif err != nil && strings.Contains(err.Error(), \"unable to retrieve enableDraftSpecs\") {\n    // handler was invoked without the standard middleware; reroute or fix wiring\n    log.Printf(\"misconfigured handler wiring: %v\", err)\n}","preventionTips":["Always invoke MCP handlers through the standard server wiring/middleware.","In tests, construct contexts with util.WithEnableDraftSpecs.","When porting handlers into custom frameworks, replicate all context-injection middlewares.","Keep patched forks in sync with upstream middleware changes."],"tags":["mcp","context","internal-error","go"],"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"}