Skip to main content
Glama
cmalpass

csharp-mcp-server-blazor

by cmalpass

C# MCP Server & Blazor WebAssembly Inspector

ブログ記事「BlazorフロントエンドでC# MCP Serverを構築する」の付属コードリポジトリです。

このリポジトリは、.NET 9上のC#で本番品質のModel Context Protocol (MCP)実装を提供し、インタラクティブなBlazor WebAssembly Tool Inspector & Protocol Monitorと組み合わせたものです。


🚀 アーキテクチャのハイライト

  • Standard MCP Protocol Engine: 公式のModel Context ProtocolをServer-Sent Events(GET /sse)とJSON-RPC 2.0(POST /messages)で実装し、Claude Desktop、Cursor、VS Code、Anthropic MCP Inspector CLIなどの外部AIクライアントをサポートします。

  • Native C# Tool Reflection: 型指定されたC#メソッドを、Microsoft.Extensions.AI(AIFunctionFactory)とSystem.Text.Jsonによる自動スキーマ生成を使用して、検出可能なMCPツールとして公開します。

  • Interactive Blazor WASM Inspector: 生成されたJSONスキーマを検査し、カスタムパラメータフォームでツール実行をテストし、リアルタイムのJSON-RPC通信ログを監視する開発者向けGUIです。

  • Zero-Config Local Dev vs Guarded Production: ローカル開発はシークレットなしで摩擦なく実行できます。非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ブラウザテスト。


🛠️ はじめに

前提条件

ローカルでの実行

  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

Settings > Features > MCPに移動し、+ Add New MCP Serverをクリックして、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 Licenseの下でライセンスされています。

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    B
    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.
    37
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables 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.
    -
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables 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 npm
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    Enables 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 npm
    MIT