Add support for sending MCP metadata#340
Merged
evalstate merged 2 commits intoevalstate:mainfrom Aug 14, 2025
Merged
Conversation
feat: Add per-request metadata support for MCP operations
Use case:
We have a Customers MCP. In our organization, each user gets access only to certain customers. Our agents are in a session-managed multi-user environment, so we needed a way to send user details on a per-request basis (Headers are supported globally, but only set at initialization, leaving no way to send different headers with different requests). While it would be possible to send this information as tool call parameters for example, this really would bloat our tool schemas.
Implementation:
- Added RequestParams.mcp_metadata field for passing custom metadata
- Uses contextVar at augmented_llm level to store metadata across async tasks
- Extends agent method signatures to accept RequestParams (send, interactive, prompt, etc.)
- Enhanced MCPAgentClientSession with _meta parameter support for call_tool, read_resource, get_prompt
- Implements safe merging to preserve existing meta fields (e.g. progressToken)
- Metadata flows from RequestParams → Context Variable → MCPAggregator → MCPAgentClientSession → MCP Server
Usage:
```python
request_params = RequestParams(mcp_metadata={"user_id": "123", "auth0_id": "auth0|..."})
await agent.generate("Get customers", request_params)
# MCP server can access via: ctx.request_context.meta.user_id
```
Supports all agent methods and MCP operation types (tools, resources, prompts).
internal ticket: DEV-1888
Owner
|
This looks good - and was hoping to use something similar for modelcontextprotocol/modelcontextprotocol#1003 (comment) @jdecker76 - i'm going to tag you in a thread in issues about 0.3.0 development; would be great to coordinate this and the other PRs. |
add the new request_parameters to the send() overrides to fix this test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: Add per-request metadata support for MCP operations
Use case:
We have a Customers MCP In our organization, each user gets access only to certain customers. Our agents are in a session-managed multi-user environment, so we needed a way to send user details on a per-request basis (Headers are supported globally, but only set at initialization, leaving no way to send different headers with different requests). While it would be possible to send this information as tool call parameters for example, this really would bloat our tool schemas.
Implementation:
Usage:
Supports all agent methods and MCP operation types (tools, resources, prompts).
internal ticket: DEV-1888