MCP ExplorerExplorer

Mcpservertoolgenerator

@dotnetsparkon 21 days ago
1 MIT
FreeCommunity
AI Systems
#csharp#mcpserver#sourcegenerator
McpServerToolsGenerator is a Roslyn incremental source generator for C# that automatically generates static tool classes for server-side tools in the ModelContextProtocol (MCP) ecosystem.

Overview

What is Mcpservertoolgenerator

McpServerToolGenerator is a Roslyn incremental source generator for C# that automatically generates static tool classes for server-side tools in the ModelContextProtocol (MCP) ecosystem.

Use cases

Use cases include simplifying the development of server-side tools, enhancing code maintainability, and providing a clear API for server functionalities in applications leveraging the MCP framework.

How to use

To use McpServerToolGenerator, annotate your server tool classes with specific attributes like [McpServerToolName] and [McpServerToolTypeDescription], then build your project. The generator will create static wrapper classes and methods for the annotated functionality.

Key features

Key features include automatic generation of static tool classes, wrapping of methods with descriptions, Roslyn symbol comparison for attribute detection, support for multi-targeting (.NET 9.0 and .NET Standard 2.0), and reduction of boilerplate code.

Where to use

McpServerToolGenerator is used in C# projects that implement server-side tools within the ModelContextProtocol (MCP) ecosystem, particularly in applications requiring consistent and discoverable server-side functionality.

Content

McpServerToolsGenerator

Visitors

Build & Pack
PR Validation
Publish NuGet

Overview

McpServerToolsGenerator is a Roslyn incremental source generator for C# that automatically generates static tool classes for server-side tools in the ModelContextProtocol (MCP) ecosystem.

It scans your code for classes and methods annotated with specific attributes and generates static wrapper classes and methods, making it easier to expose server-side functionality in a consistent and discoverable way.

Core Libraries

Package Version Description
McpServerToolGenerator.FastTrack.Common Nuget Shared attributes for MCP server tool generators
McpServerToolGenerator.FastTrack Nuget Roslyn source generator for MCP server tool wrappers

How It Works

Note: If the Mermaid diagram below does not render, view this README on GitHub web with Mermaid enabled or use a Markdown viewer/editor that supports Mermaid.

flowchart TD
    A["Your Annotated Class<br/>with McpServerToolGenerator.FastTrack.Common Attributes"] --> B["Roslyn Source Generator"]
    B --> C["Auto-generated Static Tool Class"]
    C --> D["Use Generated Static Methods"]

Features

  • Generates static tool classes for each class annotated with [McpServerToolNameAttribute].
  • Wraps methods annotated with [McpServerToolTypeDescriptionAttribute] into static methods, including descriptions.
  • Uses Roslyn symbol comparison for attribute detection (no hardcoded attribute names).
  • Supports netstandard2.0 for broad compatibility.
  • Ensures generated code is consistent and reduces boilerplate.

Usage

Using McpServerToolGenerator.FastTrack and FastTrack.Common NuGet packages

  1. Install the NuGet packages:

    Add both the FastTrack source generator and the FastTrack.Common attribute library to your project using the .NET CLI:

    dotnet add package McpServerToolGenerator.FastTrack.Common
    dotnet add package McpServerToolGenerator.FastTrack
    

    Or via the NuGet Package Manager in Visual Studio, VS Code (with the C# Dev Kit or NuGet Package Manager extension), or JetBrains Rider (right-click the project, choose “Add” → “Add NuGet Packages…”).

  2. Annotate your MCP server tool classes:

    using McpServerToolGenerator.FastTrack.Common;
    
    [McpServerToolName("MyClass")]
    public class MyClass
    {
        [McpServerToolTypeDescription("Does something")]
        public int DoWork(int x) => x + 1;
    }
    
  3. Build your project.
    The generator will automatically produce McpServerTool classes (e.g., MyClassTools) with static methods wrapping your annotated methods.

  4. Use the generated McpServerTool generated in your codebase as needed.

    
    

Requirements

  • .NET Standard 2.0
  • Microsoft.CodeAnalysis.CSharp (Roslyn) package
  • McpServerToolGenerator.FastTrack.Common for attribute definitions
  • McpServerToolGenerator.FastTrack for McpServerTool source generation

Project Structure

  • FastTrackGenerator.cs — The main source generator implementation.
  • FastTrack.Common project — Contains attributes such as McpServerToolNameAttribute and McpServerToolTypeDescriptionAttribute.

Contributing

Contributions and issues are welcome! Please open a pull request or issue on GitHub.

License

MIT License

Tools

No tools

Comments