A Model Context Protocol (MCP) server that exposes project documentation and resources through a standardized protocol. This server demonstrates how to create an MCP server using .NET 9 and C# that provides various types of resources including static content, dynamic file access, project statistics, and progress-reporting operations.
The Model Context Protocol (MCP) is an open protocol that standardizes how applications provide context to Large Language Models (LLMs). This project implements an MCP server that exposes project-related resources that can be consumed by MCP clients.
This MCP server exposes the following resources:
project://readme- Returns the project README contentproject://config- Returns project configuration as JSONproject://file/{path}- Returns the content of a file at the specified path (with security restrictions)project://logs/{date}- Returns application logs for a specific date (yyyy-MM-dd format)project://files/list- Returns a list of all files in the projectproject://stats- Returns project statistics (file counts, size, timestamp)project://analyze- Performs deep analysis of the project with progress reportingproject://diagram- Returns a project architecture diagram (PNG image)
- .NET 9.0 - Target framework
- C# 13.0 - Programming language
- ModelContextProtocol (v0.4.1-preview.1) - Core MCP protocol implementation
- ModelContextProtocol.AspNetCore (v0.4.1-preview.1) - ASP.NET Core integration
- Microsoft.Extensions.Hosting - Host builder and dependency injection
ProjectDocsServer/
├── Program.cs # Entry point and MCP server configuration
├── ProjectResource.cs # Resource implementations
├── ProjectDocsServer.csproj # Project file
└── README.md # This file
dotnet builddotnet runThe server runs using STDIO transport, which means it communicates through standard input/output. All logging is directed to stderr to avoid interfering with the MCP protocol communication.
The Model Context Inspector is a developer tool for testing and debugging MCP servers. Here's how to test this server:
Install the Model Context Inspector globally:
npm install -g @modelcontextprotocol/inspector- Start the Inspector:
npx @modelcontextprotocol/inspector dotnet run- Configure the Server Connection:
In the Inspector UI, add your server configuration:
{
"command": "dotnet",
"args": ["run", "--project", "path/to/ProjectDocsServer/ProjectDocsServer.csproj"]
}Or if you've already built the project:
{
"command": "dotnet",
"args": ["path/to/ProjectDocsServer/bin/Debug/net9.0/ProjectDocsServer.dll"]
}- Connect to the Server:
Click "Connect" in the Inspector interface. You should see the server initialize and the available resources listed.
Once connected, you can test each resource:
- README: Request
project://readmeto get the project documentation - Config: Request
project://configto get configuration JSON - Stats: Request
project://statsto get project statistics
- File Access: Request
project://file/Program.csto read the Program.cs file - Logs: Request
project://logs/2024-01-15to get logs for January 15, 2024 - File List: Request
project://files/listto see all project files