Expose existing C# services as MCP tools
When to use: You have a working business library in C# and need to make it agent-accessible.
Prerequisites
- .NET 8+ SDK — https://dotnet.microsoft.com/download
- MCPSharp package — dotnet add package MCPSharp
Flow
-
Decorate methodsAdd [McpTool] to the public methods I want exposed in my OrdersService. Keep signatures; let MCPSharp validate.✓ Copied→ Attributes applied, XML docs used as descriptions
-
Start the serverAdd a Program.cs entry point that calls MCPServer.StartAsync("orders", "1.0.0").✓ Copied→ Runs via dotnet run; MCP clients can discover tools
-
Wire into Claude DesktopEmit a claude_desktop_config.json snippet that launches my dotnet binary.✓ Copied→ Config block with command=dotnet args=[run --project, path]
Outcome: An MCP server your C# services power, with little new code.
Pitfalls
- Returning large objects without shaping them — Return DTOs — don't serialize EF entities with nav properties, you'll blow up responses