csharp -sample
csharp-mcp-server-sample
claude mcp add --transport stdio bluetsys-csharp-mcp-server-sample dotnet run --project ./SampleMcpServer/SampleMcpServer.csproj \ --env DOTNET_ENVIRONMENT="Development" \ --env ASPNETCORE_ENVIRONMENT="Development"
How to use
This MCP server sample provides a C#/.NET 6+ utility that calls JsonPlaceholder API endpoints to fetch data. It can be integrated into a console application or an ASP.NET Core project as part of an MCP server, exposing tools that query endpoints such as posts, comments, albums, photos, todos, and users. The sample demonstrates how to wire an MCP server with HttpClient management, single-item and list retrieval methods, and how to expose those operations as MCP tools that can be invoked by the MCP runtime.
To use it, build the project and run the MCP server. The server exposes tools for interacting with the JsonPlaceholder API via the MCP framework. You can extend SampleTools to add additional endpoints or custom logic, and then invoke these tools through the MCP proxy or controller in your environment.
How to install
Prerequisites:
- .NET 6.0+ SDK installed on your machine
- A suitable IDE (e.g., Visual Studio, VS Code) for .NET development
- Access to the project repository containing the SampleMcpServer.csproj file
Installation steps:
- Clone the repository containing the C# MCP server sample.
- Navigate to the project directory that contains SampleMcpServer.csproj.
- Restore dependencies and build the project:
dotnet restore
dotnet build
- Run the MCP server:
dotnet run --project ./SampleMcpServer/SampleMcpServer.csproj
- The MCP server will start and listen for MCP tool invocations based on the SampleTools configuration.
Additional notes
Notes and tips:
- Ensure you have the correct .NET 6+ SDK installed; the sample targets .NET 6 or higher as indicated in the README.
- The sample uses HttpClient to access the JsonPlaceholder API endpoints (/posts, /comments, /albums, /photos, /todos, /users). You can extend or modify the endpoints as needed.
- If you change tooling or endpoints, update the MCP tools declaration in SampleTools accordingly.
- Environment variables such as ASPNETCORE_ENVIRONMENT or DOTNET_ENVIRONMENT can be used to toggle development vs. production behavior.
- If you run into port or binding issues, verify any URL binding settings in the hosting configuration and ensure no other process is occupying the required port.
Related MCP Servers
mssql
MSSQL Server MCP implementation written in C#
McpDotNet.Extensions.SemanticKernel
Microsoft SemanticKernel integration for the Model Context Protocol (MCP). Enables seamless use of MCP tools as AI functions.
DatabaseMcpServer
MCP server from ttcc666/DatabaseMcpServer
mcp-dataverse
MCP Server for querying Dataverse using SQL
xperience-community
ASP.NET Core MCP server for Xperience by Kentico projects
console-to-http
Example of converting a stdio MCP server to HTTP using ModelContextProtocol.AspNetCore