mcp-template-dotnet
This repository contains a template for creating a Model Context Protocol (MCP) applications in .NET.
claude mcp add --transport stdio nikiforovall-mcp-template-dotnet dotnet Artefacts/MyAwesomeMCPServer.dll \ --env DOTNET_ENVIRONMENT="Production"
How to use
This MCP server is a .NET-based implementation template for creating MCP-enabled applications. It provides a simple, echo-like example that exposes tools via the MCP protocol using the WithToolsFromAssembly approach, so you can add methods decorated with [McpServerTool] to extend behavior. The server can run in Stdio mode or be hosted with HTTP as part of a larger ASP.NET/Core setup, and you can inspect and test it using the MCP Inspector. To use it, build your project from the template, run the generated DLL with dotnet, and connect to it with an MCP inspector or client to invoke the registered tools. The included Echo tool demonstrates how to expose a function that receives an input and returns a transformed string, and you can add additional methods in the same assembly to grow capabilities. The inspector lets you test tool endpoints, see tool signatures, and verify protocol adherence in a browser UI.
How to install
Prerequisites:
- .NET SDK (6.x/7.x or newer)
- Basic familiarity with the .NET CLI
Step 1: Install the MCP template
dotnet new install Nall.ModelContextProtocol.Template
Step 2: Create a new MCP server from the template (hybrid template is recommended for both Stdio and HTTP modes)
dotnet new mcp-server-hybrid -o MyAwesomeMCPServer -n MyAwesomeMCPServer
Step 3: Build the project
dotnet build -o Artefacts -c Release
Step 4: Run the server (example path to the produced DLL may vary based on project name and output)
dotnet "Artefacts/MyAwesomeMCPServer.dll"
Step 5: (Optional) Run inspector to test locally
npx @modelcontextprotocol/inspector -e DOTNET_ENVIRONMENT=Production dotnet "Artefacts/MyAwesomeMCPServer.dll"
If you prefer to run via a global tool, pack the project and install the tool globally as described in the template’s README, then invoke the tool by its installed name and use the inspector to connect similarly.
Additional notes
Notes and tips:
- The template demonstrates adding tools by creating static methods with the [McpServerTool] attribute. Use WithToolsFromAssembly() to auto-register all tools from the assembly, but you can also selectively register specific types if needed.
- In Stdio mode, the MCP server communicates through standard input/output; in HTTP mode, it can be hosted behind a web server or included in a broader ASP.NET Core app. The hybrid template supports both modes.
- Ensure DOTNET_ENVIRONMENT is set appropriately when using the inspector to mimic production or development environments.
- If you see issues with tool discovery, double-check that your tool methods are public static and decorated with [McpServerTool] and that your assembly is loaded by the server at startup.
- For local testing, you can run the generated DLL directly with dotnet, or package as a local/global tool as shown in the template to simplify repeated invocations.
Related MCP Servers
mcpbi
PowerBI MCP server to give LLM clients (Claude, GH Copilot,etc) context from locally running PowerBI Desktop instances.
NugetMcpServer
.NET MCP server that gives LLMs real NuGet API metadata to reduce hallucinations
unity -template
Simple template project for controlling Unity via MCP
mcp -graph-api
Model-context-protocol (MCP) server for the Microsoft Graph API in C#
mcp-camunda
Tools to interact with the Camunda 7 Community Edition Engine using the Model Context Protocol (MCP). Whether you're automating workflows, querying process instances, or integrating with external systems, Camunda MCP Server is your agentic solution for seamless interaction with Camunda.
cf-worker -template
Một skeleton đầy đủ để bạn bắt đầu nhanh với Cloudflare Workers: routes, utils, services, bindings (KV/D1/R2), Durable Objects, cron.