googleapis/mcp-toolbox · error

INTERNAL_ERROR

INTERNAL_ERROR

Error message

unable to retrieve enableDraftSpecs from context

What it means

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).

Solutions

  1. Route the request through the standard MCP server wiring so the middleware that injects enableDraftSpecs runs.
  2. In tests or custom handlers, populate the context with util.WithEnableDraftSpecs(ctx, <bool>) before calling serverDiscoverHandler.
  3. Update to a current toolbox version if you maintain a patched fork where the context-injection middleware was removed.

Example fix

// before
handler(ctx, id, body, header) // ctx lacks the flag
// after
ctx = util.WithEnableDraftSpecs(ctx, true)
handler(ctx, id, body, header)
Defensive patterns

Strategy: validation

Validate before calling

// Go: ensure the context carries the flag before invoking the handler
if _, ok := util.EnableDraftSpecsFromContext(ctx); !ok {
    ctx = util.WithEnableDraftSpecs(ctx, false)
}

Try / catch

res, err := serverDiscoverHandler(ctx, id, body, header)
if err != nil && strings.Contains(err.Error(), "unable to retrieve enableDraftSpecs") {
    // handler was invoked without the standard middleware; reroute or fix wiring
    log.Printf("misconfigured handler wiring: %v", err)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/a0c62097dfc09d88. Report an issue: GitHub.

Appendix: source

Thrown at internal/server/mcp/v20260728/method.go:167

		return resMeta, nil
	}

	newMeta := make(map[string]any)
	// copy current Metadata into the new meta obj
	for k, v := range curMeta {
		newMeta[k] = v
	}
	// copy the ResultMetaObject items over
	for k, v := range resMeta {
		newMeta[k] = v
	}
	return newMeta, nil
}

func serverDiscoverHandler(ctx context.Context, id jsonrpc.RequestId, body []byte, header http.Header) (any, error) {
	enableDraft, ok := util.EnableDraftSpecsFromContext(ctx)
	if !ok {
		err := fmt.Errorf("unable to retrieve enableDraftSpecs from context")
		return jsonrpc.NewError(id, jsonrpc.INTERNAL_ERROR, err.Error(), nil), err
	}

	var req DiscoverRequest
	if err := json.Unmarshal(body, &req); err != nil {
		err = fmt.Errorf("invalid server discover request: %w", err)
		return jsonrpc.NewError(id, jsonrpc.INVALID_REQUEST, err.Error(), nil), err
	}
	validateHeaderErr, err := validateHeader(id, header, SERVER_DISCOVER, "")
	if err != nil {
		return validateHeaderErr, err
	}
	validateErr, err := validateMetadata(id, req.Params, header == nil)
	if err != nil {
		return validateErr, err
	}

	toolsListChanged := false

View on GitHub (pinned to 8cc6e09de2)