You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/tasks/tasks.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,7 +13,7 @@ uid: tasks
13
13
14
14
The Model Context Protocol (MCP) supports [task-based execution] for long-running operations. Tasks enable a "call-now, fetch-later" pattern where clients can initiate operations that may take significant time to complete, then poll for status and retrieve results when ready.
Copy file name to clipboardExpand all lines: docs/concepts/tools/tools.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -340,3 +340,50 @@ Rules and constraints:
340
340
- Values containing non-ASCII characters, control characters, or leading/trailing whitespace are Base64-encoded using the `=?base64?{value}?=` wrapper.
341
341
- Header names must be case-insensitively unique within the tool's input schema.
342
342
- Header validation is enforced only for protocol versions that support the HTTP Standardization feature (currently `DRAFT-2026-v1` and later).
343
+
344
+
### Pre-loading tool definitions on the client
345
+
346
+
By default, `Mcp-Param-*` headers are sent only for tools discovered via <xref:ModelContextProtocol.Client.McpClient.ListToolsAsync*>. If a client already has tool schema information (for example, from a previous session, hardcoded configuration, or an out-of-band source), it can pre-load those definitions so that headers are sent immediately—without a round trip to the server.
347
+
348
+
```csharp
349
+
// Build the tool definition with x-mcp-header annotations
350
+
vartool=newTool
351
+
{
352
+
Name="execute_sql",
353
+
InputSchema=JsonDocument.Parse("""
354
+
{
355
+
"type": "object",
356
+
"properties": {
357
+
"region": {
358
+
"type": "string",
359
+
"x-mcp-header": "Region"
360
+
},
361
+
"query": {
362
+
"type": "string"
363
+
}
364
+
}
365
+
}
366
+
""").RootElement.Clone(),
367
+
};
368
+
369
+
// Pre-load the tool definition — no ListToolsAsync needed
370
+
client.AddKnownTools([tool]);
371
+
372
+
// This call now sends an Mcp-Param-Region header automatically
Known tools survive <xref:ModelContextProtocol.Client.McpClient.ListToolsAsync*> cache clears—they remain in the cache even when the server's tool list is refreshed. If the server returns a tool with the same name, the server's definition overwrites the cached one, but the tool keeps its known status.
378
+
379
+
To remove known tools, use <xref:ModelContextProtocol.Client.McpClient.RemoveKnownTools*> for specific tools or <xref:ModelContextProtocol.Client.McpClient.ClearKnownTools*> to remove all:
380
+
381
+
```csharp
382
+
// Remove specific known tools by name
383
+
client.RemoveKnownTools(["execute_sql"]);
384
+
385
+
// Or remove all known tools at once
386
+
client.ClearKnownTools();
387
+
```
388
+
389
+
All tools passed to <xref:ModelContextProtocol.Client.McpClient.AddKnownTools*> are validated for correct `x-mcp-header` annotations. If any tool in the batch fails validation, an <xref:System.ArgumentException> is thrown and no tools are added (all-or-nothing).
Copy file name to clipboardExpand all lines: docs/list-of-diagnostics.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,7 +23,7 @@ If you use experimental APIs, you will get one of the diagnostics shown below. T
23
23
24
24
| Diagnostic ID | Description |
25
25
| :------------ | :---------- |
26
-
|`MCPEXP001`| Experimental APIs for features in the MCP specification itself, including Tasks and Extensions. Tasks provide a mechanism for asynchronous long-running operations that can be polled for status and results (see [MCP Tasks specification](https://modelcontextprotocol.io/specification/draft/basic/utilities/tasks)). Extensions provide a framework for extending the Model Context Protocol while maintaining interoperability (see [SEP-2133](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2133)). |
26
+
|`MCPEXP001`| Experimental APIs for features in the MCP specification itself, including Tasks and Extensions. Tasks provide a mechanism for asynchronous long-running operations that can be polled for status and results (see [MCP Tasks specification](https://modelcontextprotocol.io/seps/1686-tasks)). Extensions provide a framework for extending the Model Context Protocol while maintaining interoperability (see [SEP-2133](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2133)). |
27
27
|`MCPEXP002`| Experimental SDK APIs unrelated to the MCP specification itself, including subclassing `McpClient`/`McpServer` (see [#1363](https://github.com/modelcontextprotocol/csharp-sdk/pull/1363)) and `RunSessionHandler`, which may be removed or change signatures in a future release (consider using `ConfigureSessionOptions` instead). |
/// Registers one or more tool definitions in the client's tool cache, enabling the transport
76
+
/// to send <c>Mcp-Param-*</c> headers for those tools without requiring a prior <see cref="McpClient.ListToolsAsync(RequestOptions?, CancellationToken)"/> call.
77
+
/// </summary>
78
+
/// <param name="tools">The tool definitions to register.</param>
79
+
/// <remarks>
80
+
/// <para>
81
+
/// This method allows callers who already have tool schema information (e.g., from a previous session,
82
+
/// hardcoded configuration, or an out-of-band source) to provide it directly to the client. Once registered,
83
+
/// any <see cref="McpClient.CallToolAsync(string, IReadOnlyDictionary{string, object?}?, IProgress{ProgressNotificationValue}?, RequestOptions?, CancellationToken)"/>
84
+
/// call for a registered tool will automatically include <c>Mcp-Param-*</c> HTTP headers based on
85
+
/// the tool's <c>x-mcp-header</c> schema annotations, exactly as if the tool had been discovered
86
+
/// via <see cref="McpClient.ListToolsAsync(RequestOptions?, CancellationToken)"/>.
87
+
/// </para>
88
+
/// <para>
89
+
/// <b>Cache interaction behavior:</b>
90
+
/// <list type="bullet">
91
+
/// <item>Registered tools are added to the same internal tool cache used by <see cref="McpClient.ListToolsAsync(RequestOptions?, CancellationToken)"/>.</item>
92
+
/// <item>Calling <see cref="McpClient.ListToolsAsync(RequestOptions?, CancellationToken)"/> after <see cref="AddKnownTools"/> preserves
93
+
/// manually registered tools — only server-discovered tools are cleared and repopulated.</item>
94
+
/// <item>If the server returns a tool with the same name as a manually registered tool, the server's
95
+
/// definition overwrites the registered one in the cache, but the tool retains its known status
96
+
/// and will survive subsequent cache clears. This registration is sticky for the lifetime of the
97
+
/// <see cref="McpClient"/>; use <see cref="RemoveKnownTools"/> or <see cref="ClearKnownTools"/> to
98
+
/// explicitly drop known tools that are no longer needed.</item>
99
+
/// <item>Tools can be registered at any time — before or after <see cref="McpClient.ListToolsAsync(RequestOptions?, CancellationToken)"/>,
100
+
/// and across multiple calls.</item>
101
+
/// <item>Re-registering a tool with the same name overwrites the previous definition in the cache (last write wins).</item>
102
+
/// </list>
103
+
/// </para>
104
+
/// <para>
105
+
/// Tools with invalid <c>x-mcp-header</c> annotations cause an <see cref="ArgumentException"/> to be thrown.
106
+
/// No tools are added to the cache if any tool in the batch fails validation (all-or-nothing).
107
+
/// </para>
108
+
/// </remarks>
109
+
/// <exception cref="ArgumentNullException"><paramref name="tools"/> is <see langword="null"/>.</exception>
110
+
/// <exception cref="ArgumentException">One or more tools have invalid <c>x-mcp-header</c> annotations.</exception>
0 commit comments