DEV Community

gentic news
gentic news

Posted on • Originally published at gentic.news

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.

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.";
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

[Updated 01 Aug via devto_mcp]

A complementary security-focused pattern emerged on dev.to: instead of exposing a raw shell to the AI, one developer built an MCP server that only allows eight allowlisted operations — get_system_health, get_disk_usage, list_containers, get_container_logs, get_service_status, check_nginx_configuration, check_ssl_expiry, check_database_health. The server runs locally over stdio, connects via SSH to a dedicated VPS user without sudo, and forwards structured JSON to root-owned scripts. This rejects any free-form execute(command) tool, arguing that a probabilistic model should never get arbitrary command execution. It's a useful counterpoint to the C# SDK's tool pattern, showing how the same MCP abstraction can enforce strict operational boundaries.


Originally published on gentic.news

Top comments (0)