Repository navigation
MCP: Keep request IDs and logs separate between tool calls #2629
Description
Use one request context per MCP tool call and clean it up when the call ends. This prevents inconsistent request IDs within a call and request-specific logging fields carrying into another call.
This is Data API cleanup, separate from the framework's object cleanup. It is an independent follow-up under #2408. Coordinate with #2628 at the shared execution boundary. The related tracing audit is included in the detailed requirements.
This ticket is done when tests show exactly one cleanup on success, failure, cancellation, and disabled-feature responses. Interleaved calls must keep their request and trace information separate, and a cleanup failure must preserve the original result or error.
The cleanup implementation is in #2645, stacked on #2644. The trace-context audit remains separate and keeps this issue open.
Status on October 23, 2026
PR #2645 closes each command context when a tool call ends, and keyspace tools reuse their original request context. PR #2656 tests overlapping calls on one worker and documents that the current build does not enable OpenTelemetry. Both sit in the MCP stack with no CI run yet. Enabling distributed tracing and setting the allowed baggage keys and size limits keep this issue open.
Implementation requirements and source references
Tracking issue: #2408.
Tracking correspondence: Related changelog IDs are listed below. This is an independent follow-up, outside the launch milestone unless promoted for a demonstrated release blocker. Shared requirement IDs remain stable across the delivery plan and #2408.
Why
Data API adds request IDs and schema information to its logging context. HTTP handlers remove those fields when a command ends, but the MCP path does not call the same cleanup. Keyspace tools also construct two request contexts for a single call, which can give it inconsistent request IDs.
This is Data API-owned cleanup. Quarkiverse 2.0.3 fixes the framework's separate request-scoped object cleanup in upstream #1057, but it does not add calls to Data API's CommandContext.close().
Work
- Create and reuse one request context per tool call.
- Close each constructed command context on success, failure, disabled-feature results, and cancellation.
- Ensure a cleanup failure does not replace the command's result or original error.
Done when
Tests show that cleanup runs exactly once, one call uses one request ID, and request-specific logging fields do not carry into another call.
This can ship independently of the package upgrade. Coordinate with #2628, which handles errors at the same boundary. Framework teardown regression coverage belongs in #2625.
Data API cleanup and MCP execution.
Modern protocol and OAuth acceptance details
Audit traceparent, tracestate and baggage propagation through request _meta and the framework. Test two interleaved calls and cancellation so trace and request identity do not cross-contaminate. Filter/bound baggage and never use trace fields as identity or credentials. Record whether framework propagation already satisfies the convention before adding code. This tracing audit is distinct from the required Data API context cleanup.
Changelog traceability
- m2 Propagate trace context, lines 33 — Recommended.
Normative detail: Streamable HTTP, authorization, caching.
Required base protocol/schema behavior remains owned by #2625 and verified by #2626. This follow-up owns only its stated enhancement or proven gap.
Activity
[-]Close MCP command contexts and reuse one request context[/-][+]MCP: Close command contexts and reuse one request context[/+][-]MCP: Close command contexts and reuse one request context[/-][+]MCP: Clean up Data API request logging context[/+]erichare commentedon Oct 13, 2026
Cleanup half is up in #2645, stacked on #2644 so it merges second.
It closes the command context on termination in
McpResource.processCommand()(success, failure, feature disabled, cancellation) and stopsbuildKeyspaceContext()creating a secondRequestContext, with unit tests inMcpResourceTest.Leaving this issue open: the trace-context audit for
traceparent/tracestate/baggagein request_metais not in #2645 and still needs its own check.[-]MCP: Clean up Data API request logging context[/-][+]MCP: Keep request IDs and logs separate between tool calls[/+]