Skip to main content
Glama
cmalpass

csharp-mcp-server-blazor

by cmalpass

C# MCP Server & Blazor WebAssembly Inspector

A companion repository for the blog post: Building a C# MCP Server with a Blazor WebAssembly Inspector.

This is a local, pedagogical MCP server built on .NET 10. It uses the official MCP C# SDK v2.2.0 and its stateless Streamable HTTP transport at POST /mcp, alongside a Blazor WebAssembly page for inspecting the sample tools. Customer and weather responses are simulated fixtures; the system-metrics tool intentionally reports live data from the local process. No tool queries an external system.

IMPORTANT

The Blazor page is a diagnostic UI, not an MCP client: its buttons use the application-specific/api/mcp/* API to inspect and invoke the sample tools. The actual MCP transport is POST /mcp.

Protocol and transport

The server uses the current 2026-07-28 MCP HTTP wire format through MCP C# SDK v2.2.0. It is stateless: each POST /mcp request is independent, and the server does not issue or retain an Mcp-Session-Id. The current revision uses server/discover for bootstrap rather than the historical initialize handshake, and HTTP requests carry the protocol version in the MCP-Protocol-Version header.

Streamable HTTP is the recommended HTTP transport for new MCP servers. See the official MCP C# SDK transport guidance and stateless HTTP guidance for the protocol behaviour and production deployment options.

Related MCP server: Your Own MCP Server

Solution structure

  • McpServerApp/McpServerApp: ASP.NET Core host for POST /mcp and the diagnostic inspector API.

  • McpServerApp/McpServerApp.Client: Blazor WebAssembly diagnostic inspector UI.

  • McpServerApp/McpServerApp.Tests: unit, integration, and bUnit component tests.

  • e2e/: Playwright browser test for local diagnostic inspection and invocation.

Run locally

Prerequisites: .NET 10 SDK. Install Node.js only when running the browser test.

git clone https://github.com/cmalpass/csharp-mcp-server-blazor.git
cd csharp-mcp-server-blazor
dotnet run --project McpServerApp/McpServerApp

Open the local address printed by ASP.NET Core (normally http://localhost:5000) to explore the sample tools and local diagnostic log. For a client integration, point a current MCP client at the local POST /mcp endpoint and follow that client’s official, up-to-date configuration documentation.

Production considerations

This repository teaches the protocol and tool-inspection flow; it is not a complete production deployment template. Before exposing an MCP server, design authentication and authorization for the tool surface, validate allowed origins and host names, apply request/concurrency/rate limits, avoid logging secrets or raw untrusted payloads, and run behind HTTPS and an appropriate reverse proxy. The official C# SDK documentation is the source of truth for current transport and deployment behaviour.

If a reverse proxy terminates TLS, configure it to overwrite the forwarded headers and set Mcp:TrustedProxyAddress to that proxy's exact IP address (for example, Mcp__TrustedProxyAddress=10.0.0.10 as an environment variable). The application ignores forwarded headers unless this exact proxy is configured; never enable trust for arbitrary client-supplied X-Forwarded-* headers.

Testing

Run the .NET test suite:

dotnet test --solution McpServerApp/McpServerApp.sln --configuration Release

Run the local browser test:

npm ci
npm run test:e2e

Playwright keeps screenshots, traces, and its HTML report in ignored test-output directories (test-results/ and playwright-report/). Running the test never updates tracked documentation images.

License

This project is licensed under the 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