npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

api2ai

v1.0.6

Published

Generate MCP servers from OpenAPI specs using the mcp-use framework

Downloads

25

Readme

API2AI: OpenAPI to MCP-Use Server

Generate production-ready MCP servers from any OpenAPI specification using the mcp-use framework.

Features

  • 🚀 Modern Framework - Uses mcp-use for clean, maintainable code
  • 🔍 Built-in Inspector - Test tools immediately at /inspector
  • 📡 Multiple Transports - HTTP, SSE, and Streamable HTTP support
  • 🎨 UI Widgets - Compatible with ChatGPT Apps SDK and MCP-UI
  • 🔐 Auth Support - Bearer tokens, API keys, custom headers
  • Zod Schemas - Type-safe parameter validation
  • 🐳 Production Ready - Docker, PM2, and Kubernetes ready

Quick Start

# Generate a server from the Petstore API
node generate-mcp-use-server.js \
  https://petstore3.swagger.io/api/v3/openapi.json \
  ./petstore-mcp \
  --name petstore-api

# Install and run
cd petstore-mcp
npm install
npm start

Open http://localhost:3000/inspector to test your tools!

Usage

CLI

node generate-mcp-use-server.js <openapi-spec> [output-folder] [options]

Options:
  --name <name>      Server name (default: api-mcp-server)
  --base-url <url>   Override API base URL
  --port <port>      Server port (default: 3000)
  --help             Show help

Examples

# From remote URL
node generate-mcp-use-server.js \
  https://api.example.com/openapi.json \
  ./my-server \
  --name my-api

# From local file
node generate-mcp-use-server.js \
  ./specs/my-api.yaml \
  ./my-mcp-server \
  --port 8080

# With custom base URL
node generate-mcp-use-server.js \
  ./petstore.json \
  ./petstore \
  --base-url https://petstore.example.com/v3

Programmatic Usage

import { generateMcpServer, extractTools, loadOpenApiSpec } from './generate-mcp-use-server.js';

// Generate complete server
const result = await generateMcpServer(
  'https://api.example.com/openapi.json',
  './output-folder',
  {
    serverName: 'my-api',
    baseUrl: 'https://api.example.com/v1',
    port: 3000,
  }
);

console.log(`Generated ${result.toolCount} tools`);

// Or just extract tools for custom processing
const spec = await loadOpenApiSpec('./my-spec.json');
const tools = extractTools(spec, {
  filterFn: (tool) => tool.method === 'get',  // Only GET endpoints
  excludeOperationIds: ['deleteUser'],        // Exclude specific operations
});

Generated Output

my-mcp-server/
├── .env              # Environment config (gitignored)
├── .env.example      # Example environment file
├── .gitignore
├── package.json
├── README.md         # Generated documentation
└── src/
    ├── index.js        # Main server with MCP tool registrations
    ├── http-client.js  # HTTP utilities for API calls
    └── tools-config.js # Tool configurations from OpenAPI spec

Tool Registration Format

Each API endpoint is converted into a proper MCP tool:

// Example generated tool
server.tool(
  {
    name: 'getPetById',
    description: 'Find pet by ID',
    schema: z.object({
      petId: z.number().int().describe('ID of pet to return'),
    }),
  },
  async (params) => {
    const toolConfig = toolConfigMap.get('getPetById');
    const result = await executeRequest(toolConfig, params, apiConfig);

    if (!result.ok) {
      return text(\`Error: \${result.status} \${result.statusText}\`);
    }

    // Returns MCP content types (text or object)
    return typeof result.data === 'object'
      ? object(result.data)
      : text(result.data);
  }
);

Generated Server Features

Built-in Endpoints

| Endpoint | Description | |----------|-------------| | GET /inspector | Interactive tool testing UI | | POST /mcp | MCP protocol endpoint | | GET /sse | Server-Sent Events endpoint | | GET /health | Health check |

Environment Variables

| Variable | Description | |----------|-------------| | PORT | Server port | | NODE_ENV | development/production | | API_BASE_URL | Base URL for API calls | | API_KEY | Bearer token auth | | API_AUTH_HEADER | Custom header (Name:value) | | MCP_URL | Public URL for widgets | | ALLOWED_ORIGINS | CORS origins (production) |

Connect to ChatGPT

The generated server supports the OpenAI Apps SDK out of the box.

Advanced Options

Filter Tools by Method

const result = await generateMcpServer(specUrl, outputDir, {
  filterFn: (tool) => ['get', 'post'].includes(tool.method),
});

Exclude Dangerous Operations

const result = await generateMcpServer(specUrl, outputDir, {
  excludeOperationIds: [
    'deleteUser',
    'deleteAllData', 
    'adminReset',
  ],
});

Filter by Path Pattern

const result = await generateMcpServer(specUrl, outputDir, {
  filterFn: (tool) => tool.pathTemplate.startsWith('/api/v2/'),
});

Combine Filters

const result = await generateMcpServer(specUrl, outputDir, {
  excludeOperationIds: ['deleteUser'],
  filterFn: (tool) => 
    tool.method === 'get' && 
    tool.pathTemplate.includes('/public/'),
});

Comparison with Raw MCP SDK

| Feature | This Generator | Raw SDK | |---------|---------------|---------| | Code needed | ~50 lines | ~200+ lines | | Inspector | ✅ Built-in | ❌ Manual | | UI Widgets | ✅ Supported | ❌ Manual | | Zod validation | ✅ Generated | ❌ Manual | | Authentication | ✅ Configured | ❌ Manual | | Production ready | ✅ Yes | ⚠️ Requires work |