56 results available
Sign in
Skills directory

csharp-mcp-server-generator

github

·

Last changed
Hardened

This skill has been hardened by Chainguard

Last changed

This version passed the hardening gate. Hardening applied 14 targeted changes and preserved all other text. Classified findings before hardening: 0. Classified findings closed: 0. Classified findings remaining: 0. Unclassified scanner findings remaining: 0. Review findings closed: 15. Review findings remaining: 1.


Open before hardening

None

Open after hardening

None


Expand
File
Group
Subtype
Severity
Status

No findings available

0 findings


SKILL.md

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 in a new empty subdirectory that the user confirms first; ask the user before replacing any existing files or projects
  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; make the default example tool read only, clearly state in the Description attribute when a tool changes or deletes data so clients can ask the user for approval, and expose only the capabilities the use case needs
  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, pinned to one explicit prerelease version that is recorded and locked, with package sources limited to the official NuGet feed; review the chosen version before upgrading
  • 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
  • Include in the assembly only the tool classes that are intended and reviewed, and keep test or debug tools out of the build
  • If prompts are needed, define prompt classes and methods with the SDK prompt attributes and register them for discovery, confirming the exact names against the installed package
  • 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
  • Treat content returned by tools, such as file contents, database rows, and response bodies, as untrusted data; keep tool results size limited and return them as data only

Code Quality

  • Follow C# naming conventions
  • Include XML documentation comments
  • Use nullable reference types
  • Implement proper error handling with McpProtocolException (verify this and other type names against the installed, pinned ModelContextProtocol version before generating code)
  • Return generic, sanitized error messages to clients and keep detailed messages, free of secrets, in stderr logs only
  • Use structured logging for debugging; keep secrets, credentials, personal data, and full file or response contents out of logs, redact sensitive parameters, and default to Information level outside debugging
  • Load API keys and connection strings from environment variables or a secret store, keep them out of source control, and keep them out of logs, tool results, and errors

Example Tool Types to Consider

  • File operations (read and search by default, with opt in size limited write; restrict every path to a configured root directory, resolve full paths, reject paths outside the root including symbolic link escapes, and deny sensitive files such as keys and secret files)
  • Data processing (transform, validate, analyze)
  • External API integrations (HTTP requests to an allowlist of hosts over HTTPS only; block private, loopback, link local, and cloud metadata addresses; set timeouts and response size limits; treat responses as untrusted data)
  • System operations (read only status checks; any command execution uses a fixed allowlist of programs and arguments, runs each program directly rather than through a shell, passes arguments as a list, applies timeouts, and asks the user for confirmation first)
  • Database operations (parameterized queries only, with tool input passed as parameters rather than raw SQL; read only database account by default, with updates opt in and confirmed by the user)

Testing Guidance

  • Explain how to run the server
  • Provide example commands to test with MCP clients
  • Include troubleshooting tips
  • Include a security checklist to review before deployment, covering least privilege tools, input validation, path and host scoping, secret handling, and user confirmation for destructive actions

Generate a complete, well structured MCP server with comprehensive documentation and error handling, for human review and testing before deployment.

Install

Install with chainctl
chainctl skill install public/github/csharp-mcp-server-generator:latest
Get started with chainctl
View source

Harden your own skills

Bring Chainguard's hardening pipeline to your first-party skills — custom rulesets, automated remediation, full audit trail.

Provenance

Upstream sourcehttps://github.com/github/awesome-copilot
Upstream commitdf246af8efee2e4c4bf0c98bda9eb9f5a01734fd
OCI reference

skills.cgr.dev/public/github.com/github/skills/csharp-mcp-server-generator:latest

License

MIT

Files

HARDENING.md

LICENSE

SKILL.md


The trusted source for open source

Talk to an expert
PrivacyTerms

Product

Chainguard ContainersChainguard LibrariesChainguard VMsChainguard OS PackagesChainguard ActionsChainguard Agent SkillsIntegrationsPricing
© 2026 Chainguard, Inc. All Rights Reserved.
Chainguard® and the Chainguard logo are registered trademarks of Chainguard, Inc. in the United States and/or other countries.
The other respective trademarks mentioned on this page are owned by the respective companies and use of them does not imply any affiliation or endorsement.