csharp-mcp-server-blazor
C# MCP Server & Blazor WebAssembly Inspector
Ein begleitendes Code-Repository zum Blogbeitrag: Building a C# MCP Server with Blazor Frontend.
Dieses Repository bietet eine produktionsreife Implementierung des Model Context Protocol (MCP) in C# auf .NET 9, kombiniert mit einem interaktiven Blazor WebAssembly Tool Inspector & Protocol Monitor.
🚀 Architektur-Highlights
Standard-MCP-Protokoll-Engine: Implementiert das offizielle Model Context Protocol über Server-Sent Events (
GET /sse) und JSON-RPC 2.0 (POST /messages) und unterstützt externe KI-Clients wie Claude Desktop, Cursor, VS Code und die Anthropic MCP Inspector CLI.Native C#-Tool-Reflection: Macht stark typisierte C#-Methoden als auffindbare MCP-Tools verfügbar, unter Verwendung von
Microsoft.Extensions.AI(AIFunctionFactory) und automatischer Schemagenerierung mitSystem.Text.Json.Interaktiver Blazor-WASM-Inspektor: Eine Entwickler-GUI zum Überprüfen generierter JSON-Schemas, zum Testen der Tool-Ausführung mit benutzerdefinierten Parameterformularen und zum Überwachen von JSON-RPC-Wire-Logs in Echtzeit.
Zero-Config-Lokalentwicklung vs. abgesicherte Produktion: Die lokale Entwicklung läuft reibungslos ohne Secrets; Nicht-Development-Umgebungen erzwingen JWT-Bearer-Authentifizierung, Rate-Limiting und Request-Timeouts.
Related MCP server: Your Own MCP Server
📁 Projektstruktur
McpServerApp/McpServerApp: Der ASP.NET-Core-Server, der die Endpunkte/sse,/messagesund/api/mcpbereitstellt.McpServerApp/McpServerApp.Client: Der Blazor-WebAssembly-Client, der die interaktive Inspector-Benutzeroberfläche bereitstellt.McpServerApp/McpServerApp.Tests: Vollständige automatisierte Testsuite (Unit-Tests, Integrationstests überWebApplicationFactoryund bUnit-UI-Komponententests).e2e/: Playwright-Browsertest, der Tool-Erkennung, Tool-Ausführung und Screenshot-Erfassung validiert.
🛠️ Erste Schritte
Voraussetzungen
.NET 9.0 SDK (oder .NET-10-Preview)
Node.js 20+ (für Playwright-Browsertests)
Lokale Ausführung
Klonen Sie das Repository:
git clone https://github.com/cmalpass/csharp-mcp-server-blazor.git cd csharp-mcp-server-blazor/McpServerAppStarten Sie die Anwendung:
dotnet run --project McpServerAppÖffnen Sie Ihren Browser und navigieren Sie zu
https://localhost:7150(oder dem in Ihrem Terminal angezeigten Port), um den MCP Inspector zu erkunden.
🔌 Externe KI-Clients verbinden
1. Claude Desktop
Fügen Sie diesen Eintrag zu Ihrer claude_desktop_config.json hinzu:
{
"mcpServers": {
"csharp-blazor-server": {
"url": "http://localhost:5000/sse"
}
}
}2. Cursor
Gehen Sie zu Settings > Features > MCP, klicken Sie auf + Add New MCP Server, wählen Sie SSE und geben Sie http://localhost:5000/sse an.
3. Anthropic CLI Inspector
npx @modelcontextprotocol/inspector http://localhost:5000/sse🧪 Testen
Deterministische Testsuite (.NET)
Führen Sie die Unit-, Integrations- und bUnit-Komponententests aus:
dotnet test McpServerApp/McpServerApp.sln --configuration ReleaseBrowser-E2E-Test (Playwright)
npm ci
npm run test:e2eDies führt den vollständigen Browserablauf aus und erzeugt Screenshot-Nachweise unter docs/evidence/mcp-inspector-execution.png.
📜 Lizenz
Dieses Projekt ist unter der MIT-Lizenz lizenziert.
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