Skip to content

Support for Parameter Passing in MCP Configuration and Runtime Context #1023

Closed

Description

@magicbrighter

Description

Title: Support for Parameter Passing in MCP Configuration and Runtime Context

Issue Description:

I would like to request support for parameter passing in MCP (Model Context Protocol) in two key scenarios:

1. Configuration-time Parameter Passing

Use Case: When configuring streamable HTTP connections, there's a need to pass business-specific parameters to the MCP server during initialization.

Request:

  • How can we configure additional business parameters in the MCP configuration?
  • What's the proper way for MCP servers to receive and process these configuration parameters?
  • Is there a dedicated entry point or configuration section for custom parameters?

Example Scenario:

{"mcpServers": {
     "weather": {
              "url": "http://localhost:8000/mcp",
              "transport": "streamable_http",
              "customParams": {
                    "apiKey": "xxx",
                    "environment": "production",
                    "businessConfig": {...}
               }
          }
  }
}

2. Runtime Context Parameter Passing

Use Case: During MCP tool invocation, there's a need to pass sensitive or context-specific parameters that should:

  • Be accessible to the MCP server tools
  • Remain hidden from the AI model for security reasons
  • Be transmitted transparently through the MCP protocol

Request:

  • Support for header-like parameter passing mechanism in MCP SDK
  • Secure context parameter transmission that bypasses model visibility
  • Runtime parameter injection for tool execution

Previous Implementation Reference:
In previous business implementations, we used HTTP headers to pass such parameters. We're looking for similar functionality in the MCP SDK.

Expected Behavior:

// Client side - passing context parameters
await mcpClient.callTool('my-tool', {arguments: {...},
  context: {userId: "user123",
    sessionId: "session456",
    securityToken: "token789"// Hidden from model}
});

// Server side - accessing context parameters
function myTool(args, context) {
  const userId = context.userId;const securityToken = context.securityToken;
  // Tool implementation
}

Would appreciate guidance on current capabilities and potential roadmap for these features.

References

No response

Activity

  1. tsitsimis commented on Aug 5, 2025

    @tsitsimis

    That would be very useful, lack of this feature led us use the alternative fastmcp that supports it: https://gofastmcp.com/patterns/tool-transformation

  2. added
    enhancementRequest for a new feature that's not currently supported
    ready for workEnough information for someone to start working on
    P2Moderate issues affecting some users, edge cases, potentially valuable feature
    on Oct 6, 2025
  3. added
    needs decisionIssue is actionable, needs maintainer decision on whether to implement
    and removed
    ready for workEnough information for someone to start working on
    on Apr 17, 2026
  4. maxisbey commented on Jul 24, 2026

    @maxisbey
    Contributor

    Both of these have a channel in v2:

    Connection-time parameters. The mcpServers JSON is your host's config format rather than something the SDK defines, but connection-scoped values (an API key, an environment, a tenant) travel as HTTP headers: set them on an httpx2.AsyncClient and pass it via streamable_http_client(url, http_client=...) (Bring your own httpx2.AsyncClient), then read them in the handler with ctx.headers (The Context).

    Per-call context hidden from the model. That's the request's _meta field: the client sends call_tool(name, arguments, meta={...}), it rides alongside the model-authored arguments rather than inside them, and the handler reads it as ctx.request_context.meta on MCPServer (or ctx.meta on the low-level Server).

    Example
    import anyio
    
    from mcp import Client
    from mcp.server.mcpserver import Context, MCPServer
    
    mcp = MCPServer("demo")
    
    
    @mcp.tool()
    def whoami(ctx: Context) -> str:
        meta = ctx.request_context.meta or {}
        return f"user_id={meta.get('myapp/user_id')}"
    
    
    async def main() -> None:
        async with Client(mcp) as client:
            result = await client.call_tool("whoami", {}, meta={"myapp/user_id": "user123"})
            print(result.structured_content)  # {'result': 'user_id=user123'}
    
    
    anyio.run(main)

    One caveat: headers and _meta are both client-supplied input, so they're fine for a locale or a feature flag but shouldn't be trusted as identity; for that, use OAuth (Authorization).

    Closing this as part of a wider backlog cleanup around the v2 release. Feel free to reopen if this is still relevant.

    AI Disclaimer

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Moderate issues affecting some users, edge cases, potentially valuable featureenhancementRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions