Anthropic模型上下文协议(MCP)的全功能C#实现
概览
Mcp.Net - .NET 🚀 模型上下文协议 通过标准化的工具、资源和提示协议将您的应用连接到 AI 模型 Mcp.Net 是模型上下文协议(MCP)的 .NET 实现——这是一种标准化的方式,让应用能够与 AI 模型对话并执行工具。可以把它看作是“AI 工具使用的 HTTP”——一种干净、一致的方式,让你的应用赋予 AI 模型以下能力: - 🧰 使用搜索、天气查询、数据库访问等工具 - 🌐 访问网络资源和获取网页内容 - 📝 使用预定义提示和模板 这是 0.9.0 版本——核心稳定,但部分功能仍在开发中。详情请参见当前状态。 只需两步,即可体验 OpenAI 或 Anthropic 模型的 MCP(含网页搜索、抓取、Twilio 及各种演示工具): 更多细节请参见LLM演示文档。 i️ 第一个SSE GET按设计返回401未授权。
概述(AI 翻译)
Mcp.Net - .NET 🚀 模型上下文协议 将你的应用连接到带有标准化工具、资源和提示协议的AI模型
✨ Mcp.Net 是什么?
Mcp.Net 是模型上下文协议(MCP)的 .NET 实现——这是一种标准化的方式,让应用能够与 AI 模型对话并执行工具。可以把它看作是“AI 工具使用的 HTTP”——一种干净、一致的方式,让你的应用赋予 AI 模型以下能力:
- 🧰 使用搜索、天气查询、数据库访问等工具
- 🌐 访问网络资源并获取网页内容
- 📝 使用预定义的提示和模板
** ⚠️ 1.0 之前通知**
这是0.9.0版本——核心稳定,但部分功能仍在开发中。 详情请参见当前状态。
🏃 ♀️ 快速启动
试试互动式大语言模型演示
只需两步,即可体验 OpenAI 或 Anthropic 模型的 MCP(含网页搜索、抓取、Twilio 及各种演示工具):
更多细节请参见LLM演示文档。
安装包
运行带有 OAuth 2.1 的示例服务器 + 客户端
i️ 第一个SSE GET按设计返回
401 Unauthorized。客户端遵循
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
✨ What is Mcp.Net?
Mcp.Net is a .NET implementation of the Model Context Protocol (MCP) - a standardized way for apps to talk to AI models and execute tools. Think of it as the “HTTP of AI tool usage” - a clean, consistent way for your app to give AI models the ability to:
- 🧰 Use tools like search, weather lookup, database access
- 🌐 Access web resources and fetch web content
- 📝 Work with predefined prompts and templates
⚠️ Pre-1.0 Notice
This is version 0.9.0 - the core is stable but some features are still in development. See Current Status for details.
🏃♀️ Quick Start
Try the interactive LLM demo
Experience MCP (with web-search, scraping, twilio, various demo tools) with OpenAI or Anthropic models in just two steps:
# 1. Start the server with demo tools
dotnet run --project Mcp.Net.Examples.SimpleServer/Mcp.Net.Examples.SimpleServer.csproj
# 2. In a new terminal, run the LLM chat app (requires OpenAI or Anthropic API key)
dotnet run --project Mcp.Net.LLM/Mcp.Net.LLM.csproj
See the LLM demo documentation for more details.
Install the packages
# For building a server (the thing that provides tools)
dotnet add package Mcp.Net.Server
# For building a client (the thing that talks to AI models)
dotnet add package Mcp.Net.Client
Run the sample server + client with OAuth 2.1
# Terminal 1 — start the demo server (SSE on http://localhost:5000)
dotnet run --project Mcp.Net.Examples.SimpleServer/Mcp.Net.Examples.SimpleServer.csproj
# Terminal 2 — launch the client (performs dynamic registration + PKCE)
dotnet run --project Mcp.Net.Examples.SimpleClient -- --url http://localhost:5000 --auth-mode pkce
ℹ️ The first SSE GET returns
401 Unauthorizedby design. The client follows theWWW-Authenticatechallenge, registers itself at/oauth/register, completes the PKCE handshake, and reconnects with a bearer token. Watch the logs to see resources, prompts, and tools (including the new elicitation flow) being exercised end-to-end. When the Warhammer inquisitor tool runs you’ll be prompted to accept/decline/cancel and optionally override fields via the console handler in the sample client.
Enable elicitation in your own client
The client advertises the elicitation capability only after you register a handler. Call
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →