DEV Community

Abdullah D.
Abdullah D. Subscriber

Posted on

The Missing Link: Exposing APIs to AI Agents Without Writing Code

If you’ve started building AI agents using the Model Context Protocol (MCP), you’ve likely hit a specific wall: The Boilerplate Wall.

You have a robust (.NET) back-end API with domain logic, validation, and database access all neatly organized. You even have an OpenAPI (Swagger) specification that describes exactly what the API does.

Yet, to make this accessible to an LLM (like Claude or a local Llama instance), developers often find themselves manually writing "Tool Definitions"—basically re-typing the API schema into a format the AI understands.

MCPify was created to tear down that wall.

The Problem: Two Sources of Truth

In the current ecosystem, allowing an AI to interact with a system usually requires:

  1. Defining a Tool (Name, Description, Input Schema).
  2. Mapping that tool to a C# method.
  3. Keeping that mapping updated every time the API changes.

If a query parameter is added to a controller but the MCP tool definition isn't updated, the AI starts hallucinating arguments or failing silently.

The Solution: Swagger Is The Tool Definition

Since the API already describes itself via OpenAPI/Swagger, that should be treated as the single source of truth.

MCPify is a library for .NET 8+ that acts as a dynamic bridge. It reads the OpenAPI specification (v2, v3, or v3.1) at runtime and projects it into the MCP Tool format automatically.

How It Works

Instead of hard-coding tools, MCPify injects itself into the Dependency Injection container. It parses the Swagger JSON, resolves the schemas, and automatically hosts the required MCP endpoints (SSE/Stdio).

Getting Started in 3 Steps

It is designed to be "install and forget."

1. Installation

Add the package to the ASP.NET Core project:

dotnet add package MCPify

Enter fullscreen mode Exit fullscreen mode

2. Configuration

In Program.cs, register the service. Provide the URL of the Swagger spec and the Base URL where the API requests should be sent.

using MCPify.Hosting;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMcpify(
    swaggerUrl: "https://localhost:5001/swagger/v1/swagger.json",
    apiBaseUrl: "https://localhost:5001",
    options => 
    {
        // Optional: Add a prefix to all tools to avoid naming collisions
        options.ToolPrefix = "myapi_";

        // Optional: Filter specific endpoints
        // options.Filter = op => op.Route.Contains("/products");
    }
);

Enter fullscreen mode Exit fullscreen mode

3. Usage

No custom MCP server implementation is required. Just map the endpoint, and MCPify handles the protocol communication (SSE/Post).

var app = builder.Build();

// Automatically creates the /sse and /messages endpoints
app.MapMcpifyEndpoint();

app.Run();

Enter fullscreen mode Exit fullscreen mode

Once running, connect the MCP client (like Claude Desktop) to:
http://localhost:<YOUR_PORT>/sse

> **Note:* Ensure you replace <YOUR_PORT> (e.g., 5000, 5005, 5132, ...) with the actual port number your application is listening on.*

Why This Matters

  • Rapid Prototyping: Spin up an agent that controls an entire backend in minutes, not days.
  • Maintenance Free: If a field is renamed in a DTO, the AI agent knows about the change as soon as the Swagger updates.
  • Ecosystem Compatibility: It handles the complex work of converting OpenAPI JSON schemas into the specific format MCP expects.

What's Next?

Future updates aim to add support for authentication bridging (passing user tokens through to the tools) and more granular control over operation filtering.

Developers building Agentic AI with .NET are encouraged to try it out.

Top comments (0)