mcp-server-dotnet

Stig-Johnny/mcp-server-dotnet

3.2

If you are the rightful owner of mcp-server-dotnet and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A .NET 8 implementation of the Model Context Protocol (MCP) server using Clean Architecture, Domain-Driven Design (DDD), and .NET Aspire for orchestration.

Tools
3
Resources
0
Prompts
0

MCP Server .NET

A .NET 8 implementation of the Model Context Protocol (MCP) server using Clean Architecture, Domain-Driven Design (DDD), and .NET Aspire for orchestration.

Architecture

This solution follows Clean Architecture principles with clear separation of concerns:

ā”œā”€ā”€ src/
│   ā”œā”€ā”€ Domain/                 # Core business logic and entities
│   ā”œā”€ā”€ Application/            # Use cases and application services
│   ā”œā”€ā”€ Infrastructure/         # External concerns and implementations
│   ā”œā”€ā”€ Presentation/           # Web API controllers and presentation logic
│   └── Host/                   # Aspire orchestration host

Features

  • Clean Architecture: Clear separation between layers with dependency inversion
  • Domain-Driven Design: Rich domain model with proper encapsulation
  • MCP Protocol Support: Model Context Protocol implementation with tools and resources
  • ASP.NET Core Web API: RESTful API for MCP operations
  • .NET Aspire: Modern orchestration and observability
  • Docker Support: Container-ready with optimized Dockerfile
  • Swagger/OpenAPI: API documentation and testing interface

Quick Start

Prerequisites

Getting Started

1. Clone the Repository

git clone https://github.com/Stig-Johnny/mcp-server-dotnet.git
cd mcp-server-dotnet

2. Restore Dependencies

dotnet restore

3. Build the Solution

dotnet build

4. Run the Application

Option A: Run with Aspire Host (Recommended for Development)
dotnet run --project src/Host/McpServer.Host
Option B: Run Individual Services
# Run the API
dotnet run --project src/Presentation/McpServer.Api

# Run the BFF (in another terminal)
dotnet run --project src/Presentation/McpServer.Bff
Option C: Deploy to Kubernetes (Production)
# Quick deployment with ArgoCD
kubectl apply -f argocd/application.yaml

# Or manual deployment with Helm
helm install mcp-server ./helm/mcp-server-dotnet \
  --namespace mcp-server \
  --create-namespace

5. Access the Application

  • API Base URL: https://localhost:7001 or http://localhost:5001
  • BFF Base URL: https://localhost:7245 or http://localhost:5245
  • Swagger UI: https://localhost:7001/swagger
  • Health Check: https://localhost:7001/health
  • Aspire Dashboard: https://localhost:15888 (when running with Aspire Host)

API Endpoints

MCP Tools

  • GET /api/mcp/tools - Get all available MCP tools
  • POST /api/mcp/tools/{toolName}/execute - Execute a specific tool

Example tools:

  • echo - Echoes back a message
  • time - Returns current time information
  • calculate - Performs basic arithmetic calculations

MCP Resources

  • GET /api/mcp/resources - Get all available MCP resources
  • GET /api/mcp/resources/content?uri={uri} - Get content of a specific resource

Usage Examples

Execute Echo Tool

curl -X POST "https://localhost:7001/api/mcp/tools/echo/execute" \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello, MCP!"}'

Get Current Time

curl -X POST "https://localhost:7001/api/mcp/tools/time/execute" \
  -H "Content-Type: application/json" \
  -d '{}'

Perform Calculation

curl -X POST "https://localhost:7001/api/mcp/tools/calculate/execute" \
  -H "Content-Type: application/json" \
  -d '{"expression": "2+2"}'

Docker Support

Build Docker Image

docker build -f src/Presentation/McpServer.Api/Dockerfile -t mcp-server-dotnet .

Run Container

docker run -p 8080:80 mcp-server-dotnet

Access the API at http://localhost:8080

Development

Project Structure

  • McpServer.Domain: Contains core entities, value objects, and domain interfaces
  • McpServer.Application: Contains application services and use cases
  • McpServer.Infrastructure: Contains concrete implementations of domain interfaces
  • McpServer.Api: Contains Web API controllers and presentation logic
  • McpServer.Host: Contains Aspire host for orchestration

Core Principles

This project follows key software development principles:

  • KISS (Keep It Simple, Stupid): Favor simplicity and clarity in design
  • DRY (Don't Repeat Yourself): Avoid code duplication through abstraction
  • YAGNI (You Aren't Gonna Need It): Implement only what's necessary

Adding New MCP Tools

  1. Add tool definition in BasicMcpToolExecutor.InitializeTools()
  2. Implement execution logic in BasicMcpToolExecutor.ExecuteAsync()
  3. Update API documentation if needed

Adding New MCP Resources

  1. Add resource definition in BasicMcpResourceProvider.InitializeResources()
  2. Implement content retrieval in BasicMcpResourceProvider.GetResourceContentAsync()

Testing

# Run all tests
dotnet test

# Run with coverage
dotnet test --collect:"XPlat Code Coverage"

Configuration

The application uses standard .NET configuration. Key settings can be configured via:

  • appsettings.json
  • Environment variables
  • Command line arguments
  • Azure Key Vault (in production)

Deployment

Local Development

Use the Aspire Host for the best development experience:

dotnet run --project src/Host/McpServer.Host

Production

Kubernetes with ArgoCD (Recommended)

Deploy to Kubernetes using ArgoCD and Helm:

# Apply ArgoCD application
kubectl apply -f argocd/application.yaml

# Or deploy manually with Helm
helm install mcp-server ./helm/mcp-server-dotnet \
  --namespace mcp-server \
  --create-namespace \
  --set global.tag=main

For detailed Kubernetes deployment instructions, see .

Docker Container

Deploy as a Docker container or directly to Azure App Service, AWS, or any .NET-compatible hosting platform.

# Build and run API
docker build -f src/Presentation/McpServer.Api/Dockerfile -t mcp-server-api .
docker run -p 8080:80 mcp-server-api

# Build and run BFF
docker build -f src/Presentation/McpServer.Bff/Dockerfile -t mcp-server-bff .
docker run -p 8081:80 mcp-server-bff

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the file for details.

Resources

Support

For questions and support, please open an issue in the GitHub repository.