Manifold: Generate MCP Servers from .NET Code with Zero Boilerplate
Open SourceScore: 80

Manifold: Generate MCP Servers from .NET Code with Zero Boilerplate

Manifold lets .NET developers create CLI tools and MCP servers from the same codebase using source generators, eliminating duplicate definitions.

GAla Smith & AI Research Desk·12h ago·3 min read·4 views·AI-Generated
Share:
Source: github.comvia hn_claude_cli, gn_mcp_protocolCorroborated
Manifold: Generate MCP Servers from .NET Code with Zero Boilerplate

What It Does — One Definition, Two Surfaces

Manifold is a .NET foundation that solves a specific problem: when you build a tool that needs both a CLI interface and an MCP server, you typically write the same logic twice—once for command-line parsing, once for MCP tool definitions. With Manifold, you define an operation once using C# attributes, and the source generator emits both CLI bindings and MCP tool metadata.

This means your Add operation that takes two integers can be exposed as both claude code MCP tool and a standalone dotnet run -- math add 5 3 command from the same source code.

Setup — Add Three NuGet Packages

Start with the core packages in your .csproj:

<ItemGroup>
  <PackageReference Include="Manifold" Version="1.0.0" />
  <PackageReference Include="Manifold.Generators" Version="1.0.0" PrivateAssets="all" />
  <PackageReference Include="Manifold.Mcp" Version="1.0.0" />
</ItemGroup>

For CLI-only tools, use Manifold.Cli instead of Manifold.Mcp. For both surfaces, include both packages.

How To Apply It — Define Once, Generate Everywhere

Here's the simplest approach using static methods:

using Manifold;

public static class MathOperations
{
    [Operation("math.add", Summary = "Adds two integers.")]
    [CliCommand("math", "add")]
    [McpTool("math_add")]
    public static int Add(
        [Argument(0, Name = "x")] int x,
        [Argument(1, Name = "y")] int y)
    {
        return x + y;
    }
}

The source generator creates:

  • GeneratedMcpCatalog with MCP tool definitions
  • GeneratedMcpInvoker to handle MCP requests
  • GeneratedCliInvoker for CLI parsing
  • GeneratedOperationRegistry as the central dispatch

For more complex operations with dependency injection, use class-based operations:

[Operation("math.add", Summary = "Adds two integers.")]
[CliCommand("math", "add")]
[McpTool("math_add")]
public sealed class AddOperation : IOperation<AddOperation.Request, int>
{
    public ValueTask<int> ExecuteAsync(Request request, OperationContext context)
        => ValueTask.FromResult(request.X + request.Y);

    public sealed class Request
    {
        [Argument(0, Name = "x")]
        [McpName("x")]
        public int X { get; init; }

        [Argument(1, Name = "y")]
        [McpName("y")]
        public int Y { get; init; }
    }
}

Register class-based operations in your DI container:

services.AddTransient<AddOperation>();

When To Use It — .NET Teams Building Internal Tools

Manifold shines when:

  1. You're building internal developer tools in .NET that should be accessible both via CLI and through Claude Code
  2. You want to avoid maintaining separate argument parsing logic for CLI vs MCP
  3. Your team already uses .NET and wants to contribute to the MCP ecosystem without learning new toolchains

The repository includes sample hosts for both stdio and HTTP MCP servers, making it easy to integrate with Claude Code's MCP configuration.

Limitations To Know

Manifold doesn't handle transport or hosting—you still need to wire up the MCP server yourself using the generated artifacts. It's a foundation, not a full-stack solution. The current release (v1.0.0) is new, so expect some rough edges in complex scenarios.

For .NET shops, this dramatically lowers the barrier to creating MCP servers. Instead of manually writing JSON schemas and tool definitions, you get them generated from your existing C# code.

AI Analysis

Claude Code users who work with .NET should immediately evaluate Manifold for any internal tooling projects. Here's what to do differently: 1. **Stop writing separate MCP definitions** for .NET tools. Define operations once with `[Operation]`, `[CliCommand]`, and `[McpTool]` attributes, then let the source generator create both surfaces. This ensures your CLI and MCP interfaces never drift apart. 2. **Use the static method approach** for simple operations that don't need DI. For more complex tools requiring services, use class-based operations with `IOperation<TRequest, TResult>`. Register them in your DI container before using the generated invokers. 3. **Start with the MCP samples** in the repository to understand the wiring. The hardest part isn't the operation definition—it's connecting the generated artifacts to an actual MCP host. The samples show both stdio and HTTP approaches. This follows the trend of MCP tooling becoming more accessible to mainstream development stacks. As MCP adoption grows (mentioned in 67 prior articles), tools like Manifold that lower the integration barrier will become increasingly valuable.
Enjoyed this article?
Share:

Related Articles

More in Open Source

View all