MCP Proxy

April 17, 2025 ยท View on GitHub

A Go service that connects to MCP (Model Context Protocol) servers and exposes their tools via a RESTful HTTP API and OpenAPI specification.

Overview

This application:

  1. Reads a configuration file that specifies MCP servers
  2. Launches each MCP server as a child process
  3. Connects to each server using the mcp-go client library
  4. Exposes the tools provided by each server via a RESTful HTTP API
  5. Generates OpenAPI specifications for the API

Configuration

Create a config.json file in the same directory as the application with the following structure:

{
  "mcpServers": {
    "postgres": {
      "command": "npx",
      "args": [
        "-y",
        "@modelcontextprotocol/server-postgres",
        "postgresql://localhost/mydb"
      ]
    }
  }
}

Each entry in the mcpServers object defines an MCP server:

  • The key is the name of the server (used in the API endpoints)
  • command is the command to run
  • args is an array of arguments to pass to the command

API Endpoints

The application exposes the following endpoints:

  • GET /swagger/*any - Swagger UI for the API
  • GET /api/v1/servers - List all available servers
  • GET /api/v1/openapi.json - Get the combined OpenAPI specification
  • GET /api/v1/servers/:server - Get information about a specific server
  • GET /api/v1/servers/:server/tools - List all tools provided by a server
  • GET /api/v1/servers/:server/openapi.json - Get the OpenAPI specification for a server
  • POST /api/v1/servers/:server/tools/:tool - Call a tool on a server

Usage

  1. Create a config.json file with your MCP server configurations
  2. Run the application: go run main.go
  3. Visit http://localhost:8080/swagger/index.html to explore the API

Requirements

  • Go 1.23 or later
  • The commands specified in the configuration file must be available on the system path

Dependencies

This project uses: