csharp-mcp-server-generator
npx machina-cli add skill github/awesome-copilot/csharp-mcp-server-generator --openclawGenerate C# MCP Server
Create a complete Model Context Protocol (MCP) server in C# with the following specifications:
Requirements
- Project Structure: Create a new C# console application with proper directory structure
- NuGet Packages: Include ModelContextProtocol (prerelease) and Microsoft.Extensions.Hosting
- Logging Configuration: Configure all logs to stderr to avoid interfering with stdio transport
- Server Setup: Use the Host builder pattern with proper DI configuration
- Tools: Create at least one useful tool with proper attributes and descriptions
- 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.CreateApplicationBuilderfor 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.
Source
git clone https://github.com/github/awesome-copilot/blob/main/plugins/csharp-mcp-development/skills/csharp-mcp-server-generator/SKILL.mdView on GitHub Overview
Generates a production-ready MCP server in C# using .NET 8+, featuring a console app scaffold, DI via Host.CreateApplicationBuilder, and a real stdio transport. It includes prerelease tooling discovery via WithToolsFromAssembly, robust error handling with McpProtocolException, and thorough documentation.
How This Skill Works
The generator scaffolds a C# console app, adds the MCP prerelease package and hosting libraries, and configures logging to stderr. It wires an MCP server using AddMcpServer with stdio transport, enables automatic tool discovery via WithToolsFromAssembly, and runs the server with RunAsync inside a well-structured DI container.
When to Use It
- You need a production-ready MCP server in C# with stdio transport.
- You want automatic tool discovery from an assembly via WithToolsFromAssembly.
- You require structured logging, XML docs, nullable references, and robust parameter validation.
- You plan to implement custom MCP server tools such as file, data, HTTP, system, or database operations.
- You want a complete scaffolded project including tooling, error handling, and developer documentation.
Quick Start
- Step 1: Create a new C# console app targeting .NET 8+ (dotnet new console -n McpServerApp).
- Step 2: Add ModelContextProtocol --prerelease and Microsoft.Extensions.Hosting, then configure logging to stderr.
- Step 3: Implement Host.CreateApplicationBuilder, AddMcpServer, WithToolsFromAssembly, and RunAsync, including a sample tool.
Best Practices
- Follow C# naming conventions and provide XML documentation comments for all public members.
- Enable nullable reference types and use proper error handling with McpProtocolException.
- Configure logs to stderr to avoid interfering with stdio transport.
- Leverage WithToolsFromAssembly for automatic tool discovery and decorate tools with McpServerToolType, McpServerTool, and Description attributes.
- Validate tool parameters, prefer async methods where appropriate, and thoroughly test with MCP clients.
Example Use Cases
- Scaffold a new .NET 8 console app and create the MCP server skeleton.
- Add ModelContextProtocol prerelease and Microsoft.Extensions.Hosting to the project.
- Implement a sample tool with McpServerToolType and McpServerTool attributes and a Description.
- Configure Host.CreateApplicationBuilder, AddMcpServer with stdio transport, and RunAsync.
- Run the server and connect with an MCP client using the stdio channel for testing.