Skip to content

Allow sending Mcp-Param-* headers without calling ListToolsAsync first #1577

@tarekgh

Description

@tarekgh

Problem

Currently, the client can only send \Mcp-Param-*\ headers (SEP-2243 custom parameter headers) if \ListToolsAsync\ has been called first. This is because the transport relies on a cached \Tool\ definition (populated during \ListToolsAsync) to know which parameters have \x-mcp-header\ annotations and what header names to use.

If a caller already has prior knowledge of the tool schema (e.g., from a previous session, hardcoded configuration, or an out-of-band source), there is no way to provide that information without first calling \ListToolsAsync.

Note: \Mcp-Method\ and \Mcp-Name\ headers are not affected — they are derived directly from the request parameters and always sent regardless of whether \ListToolsAsync\ was called.

Current behavior

  1. \ListToolsAsync\ → caches \Tool\ objects in \McpClientImpl._toolCache\
  2. \CallToolAsync\ → \McpClientImpl.SendRequestAsync\ looks up tool by name in cache → attaches \Tool\ to
    equest.Context.Items\
  3. \StreamableHttpClientSessionTransport.AddMcpRequestHeaders\ reads \Tool\ from context → extracts \x-mcp-header\ annotations → sends \Mcp-Param-*\ headers

If step 1 is skipped, no \Mcp-Param-*\ headers are sent (silently).

Desired behavior

Allow callers to provide tool schema information without requiring a \ListToolsAsync\ call, so that \Mcp-Param-*\ headers can be sent based on prior knowledge.

Possible approaches

  1. *Accept a \Tool\ object in \CallToolAsync* — add an overload or option property where the caller provides the tool definition
  2. Expose a method to pre-populate the cache — e.g., \RegisterTool(Tool tool)\ that adds tools without querying the server
  3. *Accept explicit headers in \RequestOptions* — let the caller provide custom headers directly, bypassing the schema-based mechanism

Related

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions