Skip to content

Commit 82e5ed9

Browse files
committed
Add docs for working with experimental APIs
1 parent dc16056 commit 82e5ed9

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

docs/concepts/tasks/tasks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ uid: tasks
88
# MCP Tasks
99

1010
> [!WARNING]
11-
> Tasks are an **experimental feature** in the MCP specification (version 2025-11-25). The API may change in future releases.
11+
> Tasks are an **experimental feature** in the MCP specification (version 2025-11-25). The API may change in future releases. See the [Experimental APIs](../../experimental.md) documentation for details on working with experimental APIs.
1212
1313
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.
1414

docs/experimental.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: Experimental APIs
3+
author: MackinnonBuck
4+
description: Working with experimental APIs in the MCP C# SDK
5+
uid: experimental
6+
---
7+
8+
The Model Context Protocol C# SDK uses the [`[Experimental]`](https://learn.microsoft.com/dotnet/api/system.diagnostics.codeanalysis.experimentalattribute) attribute to mark APIs that are still in development and may change without notice. For more details on the SDK's versioning policy around experimental APIs, see the [Versioning](versioning.md) documentation.
9+
10+
## Suppressing experimental diagnostics
11+
12+
When you use an experimental API, the compiler produces a diagnostic (e.g., `MCPEXP001`) to ensure you're aware the API may change. If you want to use the API, suppress the diagnostic in one of these ways:
13+
14+
### Project-wide suppression
15+
16+
Add the diagnostic ID to `<NoWarn>` in your project file:
17+
18+
```xml
19+
<PropertyGroup>
20+
<NoWarn>$(NoWarn);MCPEXP001</NoWarn>
21+
</PropertyGroup>
22+
```
23+
24+
### Per-call suppression
25+
26+
Use `#pragma warning disable` around specific call sites:
27+
28+
```csharp
29+
#pragma warning disable MCPEXP001
30+
tool.Execution = new ToolExecution { ... };
31+
#pragma warning restore MCPEXP001
32+
```
33+
34+
For a full list of experimental diagnostic IDs and their descriptions, see the [list of diagnostics](list-of-diagnostics.md#experimental-apis).
35+
36+
## Serialization behavior
37+
38+
Experimental properties on protocol types are fully serialized and deserialized when using the SDK's built-in serialization via <xref:ModelContextProtocol.McpJsonUtilities.DefaultOptions>. This means experimental data is transmitted on the wire even if your application code doesn't directly interact with it, preserving protocol compatibility.
39+
40+
### Custom `JsonSerializerContext`
41+
42+
If you define your own `JsonSerializerContext` that includes MCP protocol types, experimental properties will not be included in your context's serialization contract. This is by design, as it protects your compiled code against binary breaking changes to experimental APIs.
43+
44+
To ensure consistent serialization behavior that always includes experimental properties, configure a `TypeInfoResolverChain` so the SDK's resolver handles MCP types:
45+
46+
```csharp
47+
using ModelContextProtocol;
48+
49+
JsonSerializerOptions options = new()
50+
{
51+
TypeInfoResolverChain =
52+
{
53+
McpJsonUtilities.DefaultOptions.TypeInfoResolver!,
54+
MyCustomContext.Default,
55+
}
56+
};
57+
```
58+
59+
By placing the SDK's resolver first, MCP types are serialized using the SDK's contract (which includes experimental properties), while your custom context handles your own types. This is recommended even if you aren't currently using experimental APIs, since it ensures your serialization configuration remains correct as new experimental properties are introduced or as you adopt experimental features in the future.
60+
61+
## See also
62+
63+
- [Versioning](versioning.md)
64+
- [List of diagnostics](list-of-diagnostics.md#experimental-apis)
65+
- [Tasks](concepts/tasks/tasks.md) (an experimental feature)

docs/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,7 @@ items:
55
href: api/ModelContextProtocol.yml
66
- name: Versioning
77
href: versioning.md
8+
- name: Experimental APIs
9+
href: experimental.md
810
- name: GitHub
911
href: https://github.com/ModelContextProtocol/csharp-sdk

0 commit comments

Comments
 (0)