Skip to content

MCP

NSmithy.Server.Mcp exposes generated services through the Model Context Protocol. It currently maps unary operations to MCP tools. Support for prompts modeled with smithy.ai#prompts is planned next.

MCP capabilityNSmithy support
ToolsGenerated from unary operations
PromptsPlanned from smithy.ai#prompts
ResourcesNot currently generated

The package integrates with the official MCP C# SDK. It does not select a transport: the application can use stdio, HTTP, or another transport provided by that SDK.

<PackageReference Include="NSmithy.Server.Mcp" Version="0.9.0" />

The package brings in the MCP server hosting APIs and the NSmithy JSON and server runtimes.

The tools adapter uses generated JSON Schema 2020-12 documents, JSON codecs, constraint validation, and typed handlers shared with the other NSmithy server surfaces.

Register the generated handler as usual, then give its generated operation catalog to WithSmithyTools:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NSmithy.Server.Mcp;
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddWeatherServiceHandler<WeatherHandler>();
builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithSmithyTools<IWeatherServiceHandler>(handler =>
handler.CreateWeatherServiceOperationCatalog()
);
await builder.Build().RunAsync();

The dependency-injection overload resolves the generated aggregate handler when the MCP server is configured. An existing catalog can also be registered directly:

builder.Services
.AddMcpServer()
.WithStdioServerTransport()
.WithSmithyTools(handler.CreateWeatherServiceOperationCatalog());

Each supported operation becomes one MCP tool:

SmithyMCP
Operation shape nameTool name
@documentation on the operationTool description
Input structure and member constraintsJSON Schema 2020-12 input schema
Output shapeJSON Schema 2020-12 output schema and structured content
@readonlyreadOnlyHint and a non-destructive hint
@idempotentidempotentHint
@jsonNameJSON property name

Arguments are deserialized by NSmithy’s strict JSON codec and validated before the handler runs. Missing required members, constraint violations, and modeled errors are returned as MCP tool errors. Successful values are returned both as structured content and as JSON text for clients that only consume text content.

JSON Schema generation is part of the C# code generator, not the MCP adapter. Each generated unary server operation binding carries its input and output documents in JsonSchemas. The shared OperationSchema and client-only output do not carry this tool metadata. The schemas describe NSmithy’s canonical JSON document representation; they do not replace protocol-specific descriptions such as OpenAPI.

Streaming operations are omitted because an MCP tool call has one JSON argument object and one result.

The restJson1 Weather example runs the same generated service and handler as either an ASP.NET Core server or an MCP stdio server.

Smithy resource shapes model API lifecycle and identifiers; they are not the same concept as MCP resources. NSmithy does not currently infer MCP resources from them, and the Smithy AI traits do not define an MCP-resource mapping.