Replies: 2 comments 1 reply
-
|
Update: Implementation Complete! I've implemented a comprehensive solution for client-level request identifiers in the MCP TypeScript SDK: Pull Request: modelcontextprotocol/typescript-sdk#666 Key Features Delivered
Usage Example// Client with default trace context
const client = new Client(serverInfo, {
identifiers: {
"trace-id": "req-abc123",
"tenant-id": "acme-corp"
}
});
// Server with forwarding enabled
const server = new McpServer(serverInfo, {
identifierForwarding: {
enabled: true,
allowedKeys: ["trace-id", "tenant-id", "user-id"]
}
});
// Tool automatically forwards identifiers as X-MCP-* headers
server.registerTool("api_call", config, async (args, extra) => {
const options = extra.applyIdentifiersToRequestOptions({
headers: { "Content-Type": "application/json" }
});
// Headers now include: X-MCP-Trace-Id, X-MCP-Tenant-Id
return fetch("https://api.example.com", options);
});Production-Ready Security
Perfect for Enterprise Use Cases
The implementation addresses all the use cases discussed here and is ready for production use. Would love feedback from the community on the approach! |
Beta Was this translation helpful? Give feedback.
-
|
Ideally, We should have both |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Pre-submission Checklist
Discussion Topic
Proposal: Add Client-Level Request Identifiers for Distributed Tracing and Multi-Tenancy
Pre-submission Checklist
Summary
Add support for client-level identifier configuration that automatically applies to all MCP tool calls, with optional per-request additional identifiers. MCP servers would automatically forward these identifiers as HTTP headers to downstream APIs, enabling end-to-end tracing and multi-tenant context passing without requiring server-side code changes.
Scope
Abstract
The current MCP protocol lacks a standardized mechanism for passing request-scoped metadata (trace IDs, user context, tenant IDs) from clients through servers to downstream APIs. This proposal introduces an optional
identifiersfield for client configuration and tool requests, with automatic HTTP header forwarding by MCP servers. The feature is backward-compatible and provides clean separation between business logic and infrastructure concerns.Motivation
Current Problem
Use Cases
Proposal Details
Client-Level Configuration
Configure identifiers when creating MCP clients - applies to ALL tool calls:
Per-Request Additional Identifiers
Optional extra identifiers for specific tool calls:
{ "jsonrpc": "2.0", "method": "tools/call", "params": { "name": "api_tool", "arguments": { "data": "value" }, "identifiers": { "request-id": "req-001", "operation": "create-ticket" } }, "id": 1 }Automatic Header Forwarding
MCP servers automatically forward identifiers as HTTP headers:
Client Configuration
MCP clients can configure identifier forwarding per server:
{ "mcpServers": { "time": { "command": "python", "args": ["-m", "mcp_server_time"], "env": {}, "identifier_forwarding": { "enabled": true, "header_prefix": "X-MCP-", "allowed_keys": ["trace-id", "user-id", "tenant-id"], "max_identifiers": 20, "max_value_length": 256 } } } }Implementation Work Required
Protocol Changes
identifiersfield toCallToolRequestschemaidentifier_forwardingconfiguration to client connection specificationsSDK Implementation
ClientandMcpServerclassesValidation
Backward Compatibility
identifiersfieldSecurity Considerations
Future Work
This proposal focuses on the core identifier forwarding mechanism. Future enhancements could include:
Questions for Discussion
X-MCP-or something else?trace-id,span-id)?Reference Implementation
To demonstrate the feasibility of this proposal, here's how identifier forwarding could be implemented in the MCP SDKs:
TypeScript SDK Changes
Client-side identifier configuration:
Server-side automatic forwarding:
Protocol Schema Updates
Updated CallToolRequest:
{ "type": "object", "properties": { "name": { "type": "string" }, "arguments": { "type": "object" }, "identifiers": { "type": "object", "additionalProperties": { "type": "string" }, "description": "Optional identifiers to forward as HTTP headers" } }, "required": ["name"] }Example Integration
Client usage:
Resulting HTTP request to downstream API:
This proposal would significantly improve MCP's observability and multi-tenancy capabilities while maintaining full backward compatibility. The automatic header forwarding in official SDKs ensures widespread adoption without requiring server developers to implement custom logic.
Beta Was this translation helpful? Give feedback.
All reactions