Skip to main content
Glama
cmalpass

csharp-mcp-server-blazor

by cmalpass

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 DesktopCursorVS Code 以及 Anthropic MCP Inspector CLI 等外部 AI 客户端。

  • 原生 C# 工具反射:借助 Microsoft.Extensions.AIAIFunctionFactory)与 System.Text.Json 自动生成 JSON 架构,将强类型的 C# 方法公开为可发现的 MCP 工具。

  • 交互式 Blazor WASM 检查器:一个面向开发者的 GUI,可检查生成的 JSON 架构、通过自定义参数表单测试工具执行,并实时监视 JSON-RPC 通信日志。

  • 零配置本地开发与受防护的生产环境:本地开发无需任何密钥即可顺畅运行;非 Development 环境强制实施 JWT Bearer 身份验证、速率限制和请求超时。


Related MCP server: sharplens-mcp

📁 解决方案结构

  • McpServerApp/McpServerApp:承载 /sse/messages/api/mcp 端点的 ASP.NET Core 服务器。

  • McpServerApp/McpServerApp.Client:提供交互式 Inspector UI 的 Blazor WebAssembly 客户端。

  • McpServerApp/McpServerApp.Tests:完整的自动化测试套件(单元测试、通过 WebApplicationFactory 的集成测试,以及 bUnit UI 组件测试)。

  • e2e/:Playwright 浏览器测试,用于验证工具发现、执行与截图捕获。


🛠️ 快速开始

先决条件

本地运行

  1. 克隆仓库:

    git clone https://github.com/cmalpass/csharp-mcp-server-blazor.git
    cd csharp-mcp-server-blazor/McpServerApp
  2. 运行应用程序:

    dotnet run --project McpServerApp
  3. 打开浏览器并访问 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 许可证 授权。

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

0Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    A dual-transport MCP server that exposes your API as tools to LLM clients, supporting both stdio transport for local clients like Claude Desktop and HTTP/SSE transport for remote clients like OpenAI's Responses API.
  • A
    license
    A
    quality
    A
    maintenance
    A Model Context Protocol (MCP) server providing 62 AI-optimized tools for .NET/C# semantic code analysis, navigation, refactoring, and code generation using Microsoft Roslyn. Built for AI coding agents - provides compiler-accurate code understanding that AI cannot infer from reading source files alone.
    62
    31
    MIT
  • F
    license
    A
    quality
    D
    maintenance
    Minimal MCP server bridging a Roslyn C# language server to AI agents, exposing tools for diagnostics, call hierarchy, and type hierarchy.
    1
  • A
    license
    Not graded
    quality
    A
    maintenance
    Give 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.
    31
    MIT

View all related MCP servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/cmalpass/csharp-mcp-server-blazor'

If you have feedback or need assistance with the MCP directory API, please join our Discord server