Skip to content

Add support for sending MCP metadata#340

Merged
evalstate merged 2 commits intoevalstate:mainfrom
jdecker76:feat-request-param-metadata
Aug 14, 2025
Merged

Add support for sending MCP metadata#340
evalstate merged 2 commits intoevalstate:mainfrom
jdecker76:feat-request-param-metadata

Conversation

@jdecker76
Copy link
Copy Markdown
Contributor

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:

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

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
@evalstate
Copy link
Copy Markdown
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
@evalstate evalstate merged commit d9abb14 into evalstate:main Aug 14, 2025
6 checks passed
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.

3 participants