|
| 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) |
0 commit comments