Model Context Protocol .NET Template

Model Context Protocol .NET Template

This repository contains a template for creating a Model Context Protocol (MCP) applications in .NET.

NikiforovAll

开发者工具
访问服务器

README

Model Context Protocol .NET Template

<p align="center"> <img src="assets/light.png" alt="MCP Logo" /> </p>

<p align="center"> <strong>A protocol for seamless integration between LLM applications and external data sources</strong> </p>

<p align="center"> <a href="https://modelcontextprotocol.io">Documentation</a> | <a href="https://spec.modelcontextprotocol.io">Specification</a> | <a href="https://github.com/orgs/modelcontextprotocol/discussions">Discussions</a> </p>

This repository contains a template for creating a Model Context Protocol (MCP) application in .NET. It provides a basic structure and example code to help you get started with building your own MCP-enabled applications.

Package Version Description
Nall.ModelContextProtocol.Template Nuget Templates
Nall.ModelContextProtocol.Inspector.Aspire.Hosting Nuget Aspire Hosting Integration

Getting Started

Install:

dotnet new install Nall.ModelContextProtocol.Template

Verify installation:

dotnet new list mcp
# These templates matched your input: 'mcp'

# Template Name      Short Name         Language  Tags
# -----------------  -----------------  --------  -------------
# MCP Server         mcp-server         [C#]      dotnet/ai/mcp
# MCP Server SSE     mcp-server-sse     [C#]      dotnet/ai/mcp
# MCP Server Hybrid  mcp-server-hybrid  [C#]      dotnet/ai/mcp

[!TIP] It is convenient to switch between modes, so I recommend using the mcp-server-hybrid template. It allows you to run the server in both Stdio and SSE modes.

Verify output:

dotnet new mcp-server -o MyAwesomeMCPServer -n MyAwesomeMCPServer --dry-run
# File actions would have been taken:
#   Create: MyAwesomeMCPServer\.vscode\launch.json
#   Create: MyAwesomeMCPServer\MyAwesomeMCPServer.csproj
#   Create: MyAwesomeMCPServer\Program.cs
#   Create: MyAwesomeMCPServer\Properties\launchSettings.json
#   Create: MyAwesomeMCPServer\README.md
#   Create: MyAwesomeMCPServer\appsettings.Development.json
#   Create: MyAwesomeMCPServer\appsettings.json

Create from template:

dotnet new mcp-server -o MyAwesomeMCPServer -n MyAwesomeMCPServer

Here is a content of Program.cs:

using Microsoft.Extensions.Hosting;

var builder = Host.CreateApplicationBuilder(args);
builder.Services
    .AddMcpServer()
    .WithStdioServerTransport()
    .WithToolsFromAssembly();

await builder.Build().RunAsync();

[McpServerToolType]
public static class EchoTool
{
    [McpServerTool, Description("Echoes the message back to the client.")]
    public static string Echo(string message) => $"hello {message}";
}

It is a simple echo server that listens for incoming messages and responds with a greeting. You can add more tools by creating additional methods with the [McpServerTool] attribute. The WithToolsFromAssembly() method automatically registers all tools in the assembly.

Run Locally

Build from the project directory:

dotnet build -o Artefacts -c Release

Run the inspector:

npx @modelcontextprotocol/inspector -e DOTNET_ENVIRONMENT=Production dotnet "$(PWD)/Artefacts/MyAwesomeMCPServer.dll"

Open inspector in your browser and test the server:

<p align="center"> <img src="assets/inspector-demo.png" alt="Inspector Demo" /> </p>

Distribute as .NET Tool

Pack from the project directory:

dotnet pack -o Artefacts -c Release

Install the tool globally:

dotnet tool install --global --add-source ./Artefacts MyAwesomeMCPServer

Now, after you installed this tool globally, you can run it from anywhere on your system. The tool will be available as MyAwesomeMCPServer (or myawesomemcpserver) in your terminal.

💡 You can also create local tool manifest and install MCPs as tools locally.

Run the inspector:

npx @modelcontextprotocol/inspector -e DOTNET_ENVIRONMENT=Production myawesomemcpserver

Run with Aspire

In Stdio mode

In AppHost/Program.cs:

var builder = DistributedApplication.CreateBuilder(args);

builder.AddMCPInspector().WithStdio<Projects.MCPServer>();

builder.Build().Run();

In SSE mode

In AppHost/Program.cs:

var builder = DistributedApplication.CreateBuilder(args);

var mcp = builder.AddProject<Projects.MCPServerSSE>("server");
builder.AddMCPInspector().WithSSE(mcp);

builder.Build().Run();

Reference

推荐服务器

Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
MCP Package Docs Server

MCP Package Docs Server

促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。

精选
本地
TypeScript
Claude Code MCP

Claude Code MCP

一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。

精选
本地
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。

精选
本地
JavaScript
mermaid-mcp-server

mermaid-mcp-server

一个模型上下文协议 (MCP) 服务器,用于将 Mermaid 图表转换为 PNG 图像。

精选
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP 服务器向 AI 编码助手(如 Cursor)提供 Jira 工单信息。

精选
TypeScript
Linear MCP Server

Linear MCP Server

一个模型上下文协议(Model Context Protocol)服务器,它与 Linear 的问题跟踪系统集成,允许大型语言模型(LLM)通过自然语言交互来创建、更新、搜索和评论 Linear 问题。

精选
JavaScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

这个服务器通过将复杂问题分解为顺序步骤来促进结构化的问题解决,支持修订,并通过完整的 MCP 集成来实现多条解决方案路径。

精选
Python
Curri MCP Server

Curri MCP Server

通过管理文本笔记、提供笔记创建工具以及使用结构化提示生成摘要,从而实现与 Curri API 的交互。

官方
本地
JavaScript