Skip to content

MCP: close the command context when a tool call ends - #2645

Open
erichare wants to merge 2 commits into
fix/mcp-protocol-foundationfrom
fix/mcp-request-context-cleanup
Open

erichare wants to merge 2 commits into
fix/mcp-protocol-foundationfrom
fix/mcp-request-context-cleanup

Conversation

@erichare

@erichare erichare commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does:

MCP tool calls build a CommandContext, which puts the request ID and schema names into the logging context (MDC), but nothing removes them when the call ends. The HTTP resources close the context on termination; McpResource does not. Keyspace tools also build a second RequestContext for the command context, so one call starts under one request ID and runs under another.

This PR makes the MCP path do what GeneralResource already does:

  • McpResource.processCommand() closes the command context with onTermination(), so it runs on success, on failure, when the MCP feature is disabled, and on cancellation. A failure while closing is logged and does not replace the tool result or the original error.
  • McpResource.buildKeyspaceContext() passes the RequestContext it already created to the context builder instead of creating a second one. Database and collection/table calls already did this.

Which issue(s) this PR fixes:
Part of #2629. Leaves #2629 open for the trace-context audit, see NOTE above.

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant