mcpField
C
csharp-mcp-server-generator

csharp-mcp-server-generator

github.com/githubDevelopment40.5k8.4k installsUpdated today
Repository

About csharp-mcp-server-generator

A skill for developers generating C# MCP servers with .NET 8.0 or later. It specifies the Host and dependency injection setup, stdio transport, tool attributes, error handling, and run instructions.

Key features

  1. 01Create a C# console project structure
  2. 02Configure Host and dependency injection
  3. 03Set up stdio transport and logging
  4. 04Generate described and validated tools
  5. 05Provide run, test, and troubleshooting guidance

Use cases

  1. 01Build a C# MCP server from scratch
  2. 02Add custom tools to a server
  3. 03Generate a server template with error handling and documentation

MCP support

The skill generates an MCP server that MCP clients can connect to over stdio. The generated server registers tools for clients to call.

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/github/awesome-copilot --skill csharp-mcp-server-generator

After installing, type/csharp-mcp-server-generatorin Claude Code to confirm it loaded.

Details

From the project README

Generate C# MCP Server

Create a complete Model Context Protocol (MCP) server in C# with the following specifications:

Requirements

  1. Project Structure: Create a new C# console application with proper directory structure
  2. NuGet Packages: Include ModelContextProtocol (prerelease) and Microsoft.Extensions.Hosting
  3. Logging Configuration: Configure all logs to stderr to avoid interfering with stdio transport
  4. Server Setup: Use the Host builder pattern with proper DI configuration
  5. Tools: Create at least one useful tool with proper attributes and descriptions
  6. Error Handling: Include proper error handling and validation

Implementation Details

Basic Project Setup
  • Use .NET 8.0 or later
  • Create a console application
  • Add necessary NuGet packages with --prerelease flag
  • Configure logging to stderr
Server Configuration
  • Use Host.CreateApplicationBuilder for DI and lifecycle management
  • Configure AddMcpServer() with stdio transport
  • Use WithToolsFromAssembly() for automatic tool discovery
  • Ensure the server runs with RunAsync()
Tool Implementation
  • Use [McpServerToolType] attribute on tool classes
  • Use [McpServerTool] attribute on tool methods
  • Add [Description] attributes to tools and parameters
  • Support async operations where appropriate
  • Include proper parameter validation
Code Quality
  • Follow C# naming conventions
  • Include XML documentation comments
  • Use nullable reference types
  • Implement proper error handling with McpProtocolException
  • Use structured logging for debugging

Example Tool Types to Consider

  • File operations (read, write, search)
  • Data processing (transform, validate, analyze)
  • External API integrations (HTTP requests)
  • System operations (execute commands, check status)
  • Database operations (query, update)

Testing Guidance

  • Explain how to run the server
  • Provide example commands to test with MCP clients
  • Include troubleshooting tips

Generate a complete, production-ready MCP server with comprehensive documentation and error handling.

Comments

Markdown supported