Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

14 Commits

Folders and files

Repository files navigation

MCP OpenAPI Proxy Go

A high-performance MCP (Model Context Protocol) server written in Go that dynamically generates tools from OpenAPI specifications. This server acts as a proxy between AI assistants and external APIs, automatically creating MCP tools based on OpenAPI definitions.

Features

  • Dynamic Tool Generation: Automatically creates MCP tools from OpenAPI specifications
  • Multiple Authentication Methods: Supports Bearer tokens, API keys, and custom headers
  • SSL Handling: Configurable SSL verification for development and production use
  • High Performance: Shared HTTP client with connection pooling; tools and spec parsed once at startup
  • Rust parity: Tool shorthand patterns, regex include/exclude filters, $ref parameter resolution, path params excluded from query strings
  • Flexible Configuration: Environment-based configuration system

Tool Naming Convention

The MCP proxy generates descriptive tool names that include HTTP method and path information, making tools easier to distinguish:

Naming Format

{prefix}_{method}_{path_segments}

Examples

OpenAPI Path HTTP Method Generated Tool Name
/users GET api_GET_users
/users/{id} GET api_GET_users_id
/admin/posts/{post_id} POST api_POST_admin_posts_post_id
/api/v1/user-profiles PUT api_PUT_api_v1_user_profiles
/ GET api_GET_root

Configuration

  • TOOL_NAME_PREFIX: Custom prefix for tool names (default: api)
  • TOOL_NAME_MAX_LENGTH: Maximum length for tool names

Benefits

  • Clear Identification: Easy to understand what each tool does
  • Better Organization: Tools are logically grouped by API structure
  • Consistent Format: Predictable naming pattern across all APIs
  • Path Parameter Handling: Path parameters are converted to descriptive names

OpenAPI Spec Generation

The proxy includes a powerful CLI feature to automatically generate OpenAPI specifications by crawling APIs:

# Generate OpenAPI spec in YAML format
./mcp-proxy-go --generate --url https://api.example.com --output ./specs/api-spec.yaml --type yaml

# Generate OpenAPI spec in JSON format
./mcp-proxy-go --generate --url https://api.example.com --output ./specs/api-spec.json --type json

# Generate spec with custom root paths for APIs without index pages
./mcp-proxy-go --generate --url https://my-blog-api.com --output ./specs/blog-api.yaml --type yaml --paths admin,posts,pages,settings

# Generate spec for e-commerce API with specific endpoints
./mcp-proxy-go --generate --url https://my-api.com --output ./specs/api.json --type json --paths users,products,orders,cart

CLI Options

Flag Description Required Example
--generate Enable spec generation mode Yes --generate
--url API URL to crawl Yes --url https://api.example.com
--output Output file path Yes --output ./specs/api.yaml
--type Output format (json/yaml) No --type yaml (default: yaml)
--paths Custom root paths to crawl No --paths admin,posts,users

How it works

  1. API Discovery: The generator crawls specified endpoints and HTTP methods
  2. Custom Path Support: Use --paths to specify exact endpoints when APIs don't have index pages
  3. Response Analysis: Analyzes HTTP responses to infer schemas and parameters
  4. Pattern Recognition: Discovers additional endpoints from response content
  5. Schema Inference: Automatically generates JSON schemas from response data
  6. OpenAPI Compliance: Outputs fully compliant OpenAPI 3.0.3 specifications

When to use custom paths

Use the --paths flag when:

  • Your API doesn't have a landing page that lists available endpoints
  • You know the specific endpoints you want to document
  • The API uses a different structure than the default discovery paths
  • You want to focus on specific API areas (e.g., admin functions only)

Example: For a blog API that has endpoints at /admin, /posts, /pages, /settings but no index page:

./mcp-proxy-go --generate --url https://my-blog-api.com --output ./specs/blog-api.yaml --paths admin,posts,pages,settings

Supported HTTP Methods

  • GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
  • Automatic path parameter detection (e.g., /users/{id})
  • Response status code analysis
  • Content-type detection and schema generation

Installation

Prerequisites

  • Go 1.23.5 or higher
  • Git

Build from Source

git clone https://github.com/romans127/mcp-openapi-proxy-go.git
cd mcp-openapi-proxy-go
make build

Using Makefile

# Build for current platform
make build

# Build for all platforms
make build-all

# Build with debug information
make build-debug

# Install for Cursor MCP
make install-cursor

# Show all available targets
make help

Configuration

Environment Variables

Variable Description Default
OPENAPI_SPEC_URL URL to OpenAPI specification Required (dynamic mode)
OPENAPI_SIMPLE_MODE Enable simple mode with basic tools false
OPENAPI_BASE_URL Base URL for API calls (used when SERVER_URL_OVERRIDE is not set) None
API_KEY API key for authentication (default when API_KEY_ENV is unset) None
API_KEY_ENV Name of the env var that holds the API key (e.g. SERVICE_API_KEY) None
API_AUTH_TYPE Authentication type (Bearer or APIKey) None
SERVER_URL_OVERRIDE Override server URL for API calls (takes precedence over OPENAPI_BASE_URL) None
EXTRA_HEADERS Additional HTTP headers (newline-separated) None
IGNORE_SSL_TOOLS Skip SSL certificate validation for API requests false
IGNORE_SSL_SPEC Skip SSL certificate validation when fetching the spec false
TOOL_NAME_PREFIX Prefix for generated tool names api
TOOL_NAME_MAX_LENGTH Max tool name length (default 40 for Cursor combined limit) 40
TOOL_INCLUDE_PATTERN Optional regex; only matching tool names are exposed None
TOOL_EXCLUDE_PATTERN Optional regex; matching tool names are excluded None

Modes

Dynamic Mode (Default)

Automatically fetches OpenAPI specifications and generates MCP tools for each endpoint:

About

No description, website, or topics provided.

Resources

Code of conduct

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages