Skip to content
gentic.news — AI News Intelligence Platform
Connecting to the Living Graph…

Listen to today's AI briefing

Daily podcast — 5 min, AI-narrated summary of top stories

Developer typing C# code on a laptop with a ModelContextProtocol SDK window and a terminal showing build output, in…
Open SourceScore: 80

Build an MCP Server in C#: Write Tools Once

The official ModelContextProtocol C# SDK (1.0.0) lets you write tools once and use them in Claude Code via stdio or HTTP — no more copy-pasting tool code between apps.

·8h ago·3 min read··6 views·AI-Generated·Report error
Share:
Source: dev.tovia devto_mcpCorroborated
How do I build an MCP server in C# so Claude Code can use my tools?

Use the ModelContextProtocol C# SDK (1.0.0). Create a console app, add the ModelContextProtocol and Microsoft.Extensions.Hosting packages, mark tool methods with [McpServerTool] and [Description], then register the server in Program.cs. Claude Code connects via `claude mcp add`.

TL;DR

Stop copy-pasting tools between apps. Build a .NET MCP server with the official C# SDK and expose tools to Claude Code, Desktop, and beyond via stdio or HTTP.

What Changed — The specific update, with version/date if available

The official ModelContextProtocol C# SDK hit 1.0.0 (maintained with Microsoft). This is no longer a preview or an experimental wrapper. It's a stable, production-ready way to build MCP servers in .NET.

If you've been writing Claude Code tools as inline functions or copy-pasting them between projects, this changes the game. You write a tool once as a standalone server, and any MCP client — Claude Code, Claude Desktop, your own agent — connects and gets your tools for free.

What It Means For You

Your tools become process-independent. The client (Claude Code) launches your server as a child process (stdio) or connects over the network (HTTP). The tool lives on the other side of a process boundary, reusable by any client instead of hardwired into one app.

Here's the core pattern:

[McpServerToolType]
public sealed class CoffeeTools(CoffeeShopData data)
{
    [McpServerTool, Description("Consulta el estado y la fecha estimada de entrega de un pedido por su id.")]
    public string GetOrderStatus(
        [Description("Id del pedido, p. ej. A-1001")] string orderId) =>
        data.Orders.TryGetValue(orderId, out var order)
            ? $"Pedido {order.Id}: {order.Status}, ETA {order.Eta}."
            : "No hay ningún pedido con ese id.";
}

The SDK reads your method signature and generates the JSON Schema automatically. No more hand-writing schemas or maintaining a switch statement.

Try It Now

1. Create a console app and add the packages:

Cover image for Crea un servidor MCP en C#: escribe tus herramientas una vez y úsalas en cualquier Claude

dotnet new console -o AuroraCoffee.Mcp
cd AuroraCoffee.Mcp
dotnet add package ModelContextProtocol
dotnet add package Microsoft.Extensions.Hosting

2. Define your data as an injectable service (a singleton, like a real repository).

3. Mark your tool methods with [McpServerTool] and [Description] on both the method and each parameter.

4. Wire it up in Program.cs using the generic host — the same DI and configuration story you'd use in any .NET service.

5. Connect Claude Code to your server:

claude mcp add aurora-coffee -- dotnet run --project AuroraCoffee.Mcp

Or use the HTTP transport if you want to share the server across a team:

claude mcp add --transport http aurora-coffee https://your-server.example.com/mcp

The Big Picture

MCP servers expose three things:

  • tools — actions the model can call (this article's focus)
  • resources — readable data (files, rows)
  • prompts — reusable prompt templates

If you have a tool that multiple apps need — order lookup, stock check, database queries, internal APIs — build it once as an MCP server. Then every Claude client gets it. That's the coupling MCP exists to break.


Source: dev.to

Source: gentic.news · · author= · citation.json

AI-assisted reporting. Generated by gentic.news from multiple verified sources, fact-checked against the Living Graph of 4,300+ entities. Edited by Ala SMITH.

Following this story?

Get a weekly digest with AI predictions, trends, and analysis — free.

AI Analysis

**What should Claude Code users do differently?** First, stop embedding every tool inside your CLAUDE.md prompts or inline scripts. If a tool is useful beyond a single session, it deserves to be an MCP server. The C# SDK makes this trivial — the attributes replace hand-written JSON schemas, and DI gives you clean separation between data access and tool logic. Second, think about transport. For local development, stdio is perfect — Claude Code launches your server as a child process. But if you have a team, or tools that need shared state, deploy your server over HTTP. Then anyone on your team can add it with `claude mcp add --transport http <name> <url>` and get your tools immediately. Third, leverage DI. The example uses constructor injection for data, exactly like a real repository. This means your MCP tools can talk to real databases, internal APIs, or any .NET service — not just in-memory dictionaries. The pattern scales from demo to production without restructuring. Finally, if you're already using the older `ModelContextProtocol` preview packages, upgrade to 1.0.0. The API is stable now, and the Microsoft collaboration means it's the path forward for .NET MCP development.
Compare side-by-side
Claude Code vs Claude Desktop
Enjoyed this article?
Share:

AI Toolslive

Five one-click lenses on this article. Cached for 24h.

Pick a tool above to generate an instant lens on this article.

Related Articles

From the lab

The framework underneath this story

Every article on this site sits on top of one engine and one framework — both built by the lab.

More in Open Source

View all