csharp-mcp-server-blazor
C# MCP Server & Blazor WebAssembly Inspector
这是博客文章 使用 Blazor 前端构建 C# MCP 服务器 的配套代码仓库。
本仓库在 .NET 9 上提供了 Model Context Protocol(MCP) 的生产级 C# 实现,并配备了一个交互式 Blazor WebAssembly 工具检查器与协议监视器。
🚀 架构亮点
标准 MCP 协议引擎:通过 Server-Sent Events(
GET /sse)和 JSON-RPC 2.0(POST /messages)实现官方的 Model Context Protocol,支持 Claude Desktop、Cursor、VS Code 以及 Anthropic MCP Inspector CLI 等外部 AI 客户端。原生 C# 工具反射:借助
Microsoft.Extensions.AI(AIFunctionFactory)与System.Text.Json自动生成 JSON 架构,将强类型的 C# 方法公开为可发现的 MCP 工具。交互式 Blazor WASM 检查器:一个面向开发者的 GUI,可检查生成的 JSON 架构、通过自定义参数表单测试工具执行,并实时监视 JSON-RPC 通信日志。
零配置本地开发与受防护的生产环境:本地开发无需任何密钥即可顺畅运行;非 Development 环境强制实施 JWT Bearer 身份验证、速率限制和请求超时。
Related MCP server: Your Own MCP Server
📁 解决方案结构
McpServerApp/McpServerApp:承载/sse、/messages和/api/mcp端点的 ASP.NET Core 服务器。McpServerApp/McpServerApp.Client:提供交互式 Inspector UI 的 Blazor WebAssembly 客户端。McpServerApp/McpServerApp.Tests:完整的自动化测试套件(单元测试、通过WebApplicationFactory的集成测试,以及 bUnit UI 组件测试)。e2e/:Playwright 浏览器测试,用于验证工具发现、执行与截图捕获。
🛠️ 快速开始
先决条件
.NET 9.0 SDK(或 .NET 10 预览版)
Node.js 20+(用于 Playwright 浏览器测试)
本地运行
克隆仓库:
git clone https://github.com/cmalpass/csharp-mcp-server-blazor.git cd csharp-mcp-server-blazor/McpServerApp运行应用程序:
dotnet run --project McpServerApp打开浏览器并访问
https://localhost:7150(或终端中显示的端口),探索 MCP Inspector。
🔌 连接外部 AI 客户端
1. Claude Desktop
将以下条目添加到你的 claude_desktop_config.json:
{
"mcpServers": {
"csharp-blazor-server": {
"url": "http://localhost:5000/sse"
}
}
}2. Cursor
转到 设置 > 功能 > MCP,点击 + 添加新 MCP 服务器,选择 SSE,并提供 http://localhost:5000/sse。
3. Anthropic CLI Inspector
npx @modelcontextprotocol/inspector http://localhost:5000/sse🧪 测试
确定性测试套件(.NET)
运行单元测试、集成测试和 bUnit 组件测试:
dotnet test McpServerApp/McpServerApp.sln --configuration Release浏览器 E2E 测试(Playwright)
npm ci
npm run test:e2e这将运行完整的浏览器流程,并将截图证据输出到 docs/evidence/mcp-inspector-execution.png。
📜 许可证
本项目采用 MIT 许可证 授权。
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Zero-setup MCP gateway securely connecting AI to your tools with authentication and workflows
AI Reasoning Cache & Consensus Layer with 11 MCP tools via Streamable HTTP.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceGive your AI assistant superpowers for .NET development! This MCP server connects GitHub Copilot, Claude, and other AI assistants directly to the .NET SDK, enabling them to create projects, manage packages, run builds, and more—all through natural language.37MIT
- FlicenseNot gradedqualityCmaintenanceEnables AI assistants and MCP-enabled clients to discover and call application capabilities exposed as structured, schema-defined tools, with input validation, error handling, and API/database integration. It also ships a sample client that demonstrates secure tool execution and seamless AI-agent interoperability.-
- AlicenseNot gradedqualityAmaintenanceEnables AI assistants like Claude, Cursor, VS Code, and Windsurf to manage workspaces, projects, tasks, and AI agents through natural language, with a hosted OAuth server or a local stdio package. Also supports generating MCP tools from any OpenAPI spec.2,807 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables AI clients such as Claude, Cursor, VS Code, and Windsurf to list and manage workspaces, projects, tasks, AI agents, and automations through a hosted OAuth-secured endpoint or a local stdio package. Also generates MCP tools from any OpenAPI spec.2,807 npmMIT