csharp-mcp-server-generator
Generate a complete MCP server project in C# with tools, prompts, and proper configuration
摘要
- 用途
- 建立以 C# 撰寫的 Model Context Protocol 伺服器專案,使用主機建置器管理相依性注入與 stdio 傳輸,並提供可自動探索的工具及實務操作說明。
- 使用時機
- 當你需要建立 .NET 8 以上的主控台伺服器,以提供自訂 MCP 工具,並包含設定、驗證與執行和測試指引時使用。
- 輸出結果
- 產出設定為 MCP stdio 傳輸與 stderr 記錄的主控台專案,內含至少一個具屬性標記且含驗證和錯誤處理的工具,以及執行與測試說明。
⚠ 已凍結/無上游
此技能沒有已驗證的上游來源。它凍結於 v1.0.0,不會再收到更新。
npx skills add "lettucebo/Skills#v2.2.0@csharp-mcp-server-generator" --full-depth ⚠ v2.2.0 發布後即可使用
Generate 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.