# Openapi To Mcp Converter (`theguide/openapi-to-mcp-converter`) Actor

Convert any OpenAPI specification into a Model Context Protocol (MCP) server that AI assistants can use to interact with REST APIs.

- **URL**: https://apify.com/theguide/openapi-to-mcp-converter.md
- **Developed by:** [TheGuide](https://apify.com/theguide) (community)
- **Categories:** MCP servers, AI, Developer tools
- **Stats:** 4 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$500.00 / 1,000 openapi url processeds

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## OpenAPI to MCP Converter

Convert any OpenAPI specification into a Model Context Protocol (MCP) server that AI assistants can use to interact with REST APIs.

### Features

- **Universal OpenAPI Support**: Works with OpenAPI v3.0 and v3.1 specifications
- **Flexible Input**: Accept OpenAPI specs from URLs or raw JSON/YAML strings
- **Smart Filtering**: Include/exclude endpoints using regex patterns
- **Authentication Support**: Bearer tokens, API keys, and basic auth
- **Multiple Output Formats**: Generate MCP server packages, JSON manifests, or both
- **Production Ready**: Includes error handling, validation, and structured logging

### How It Works

1. **Input**: Provide an OpenAPI specification URL or raw spec
2. **Parse**: Extract endpoints, parameters, request/response schemas
3. **Transform**: Convert each endpoint into an MCP tool with proper schemas
4. **Generate**: Create a ready-to-use MCP server package or JSON manifest
5. **Deploy**: Use the generated MCP server with any AI assistant

### Input Parameters

#### Required

- **openapiSource** (string): URL or raw JSON/YAML of the OpenAPI specification

#### Optional

- **serverName** (string): Unique identifier for the MCP server (default: `openapi-mcp-server`)
- **serverDescription** (string): Human-readable description
- **includeEndpoints** (array): Regex patterns to include specific endpoints
- **excludeEndpoints** (array): Regex patterns to exclude endpoints
- **authentication** (object): Auth configuration
  - `type`: `none`, `bearer`, `apiKey`, or `basic`
  - `token`: Bearer token or API key value
  - `apiKeyHeader`: Header name for API key (e.g., `X-API-Key`)
  - `username`: For basic auth
  - `password`: For basic auth
- **baseUrl** (string): Override the base URL from the spec
- **outputFormat** (string): `mcp-package`, `json-manifest`, or `both` (default: `both`)
- **includeExamples** (boolean): Include examples in tool descriptions (default: `true`)
- **maxEndpoints** (integer): Maximum endpoints to process (default: `100`, max: `500`)

### Output

#### Dataset

Each run produces a dataset with:

1. **Summary record**: Overview of processed endpoints
2. **Endpoint records**: Detailed info for each API endpoint including MCP tool name

#### Key-Value Store

- **manifest.json**: Complete MCP manifest with all tools and metadata
- **mcp-server.zip**: Ready-to-deploy MCP server package (includes `package.json`, `index.js`, `README.md`)

### Usage Examples

#### Basic Usage

```json
{
    "openapiSource": "https://petstore3.swagger.io/api/v3/openapi.json",
    "serverName": "petstore-mcp",
    "serverDescription": "MCP server for Petstore API"
}
```

#### With Authentication

```json
{
    "openapiSource": "https://api.example.com/openapi.json",
    "serverName": "example-api-mcp",
    "authentication": {
        "type": "bearer",
        "token": "your-api-token-here"
    }
}
```

#### With Endpoint Filtering

```json
{
    "openapiSource": "https://api.example.com/openapi.json",
    "includeEndpoints": ["GET /users.*", "POST /users"],
    "excludeEndpoints": ["DELETE .*"]
}
```

#### From Raw YAML

```json
{
    "openapiSource": "openapi: 3.0.0\ninfo:\n  title: My API\n  version: 1.0.0\npaths:\n  /hello:\n    get:\n      summary: Say hello\n      responses:\n        '200':\n          description: Success"
}
```

### Deploying the MCP Server

After the actor completes:

1. Download `mcp-server.zip` from the key-value store
2. Extract the archive
3. Install dependencies: `npm install`
4. Run the server: `node index.js`
5. Connect it to your AI assistant (Claude Desktop, etc.)

#### Example MCP Configuration (Claude Desktop)

```json
{
    "mcpServers": {
        "petstore-mcp": {
            "command": "node",
            "args": ["/path/to/extracted/mcp-server/index.js"]
        }
    }
}
```

### API Integration

Use the Apify API to automate OpenAPI to MCP conversion:

```javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: 'YOUR_API_TOKEN' });

const run = await client.actor('YOUR_USERNAME/openapi-to-mcp-converter').call({
    openapiSource: 'https://api.example.com/openapi.json',
    serverName: 'my-api-mcp',
    authentication: {
        type: 'bearer',
        token: process.env.API_TOKEN,
    },
});

const { defaultKeyValueStoreId } = run;
const kvStore = client.keyValueStore(defaultKeyValueStoreId);

// Download the MCP server package
const mcpPackage = await kvStore.getValue('mcp-server.zip');
```

### Use Cases

- **API Integration**: Make any REST API accessible to AI assistants
- **Legacy API Modernization**: Bridge old APIs with modern AI tooling
- **Rapid Prototyping**: Quickly test AI interactions with APIs
- **Multi-API Orchestration**: Create multiple MCP servers for different services
- **Developer Tools**: Generate MCP servers for internal APIs

### Limitations

- Only supports OpenAPI v3.0 and v3.1
- Complex authentication flows (OAuth2, etc.) require manual customization
- Generated MCP server code is a starting point and may need refinement for production
- Maximum 500 endpoints per run

### Technical Details

- **Runtime**: Node.js 18+
- **Dependencies**: `apify`, `openapi-types`, `yaml`, `zod`, `archiver`, `fs-extra`
- **Output**: MCP SDK v1.0+ compatible servers

### Troubleshooting

#### "Failed to fetch OpenAPI spec"

- Verify the URL is accessible
- Check if authentication is required for the spec endpoint
- Ensure the URL returns valid JSON or YAML

#### "No endpoints found"

- Check your include/exclude patterns
- Verify the OpenAPI spec has valid paths
- Increase `maxEndpoints` if needed

#### "Invalid OpenAPI specification"

- Ensure the spec is valid OpenAPI v3.0 or v3.1
- Use an OpenAPI validator to check the spec first
- Try converting v2.0 (Swagger) specs to v3.0 first

### Support

For issues, feature requests, or questions, please open an issue on the actor's repository.

# Actor input Schema

## `openapiSource` (type: `string`):

URL or raw JSON/YAML string of the OpenAPI specification (v3.0 or v3.1).

## `serverName` (type: `string`):

Unique identifier for the generated MCP server.

## `serverDescription` (type: `string`):

Human-readable description of what this API does.

## `includeEndpoints` (type: `array`):

List of regex patterns to include specific endpoints. Leave empty to include all.

## `excludeEndpoints` (type: `array`):

List of regex patterns to exclude specific endpoints.

## `authentication` (type: `object`):

Optional authentication details for API calls.

## `baseUrl` (type: `string`):

Override the base URL from the OpenAPI spec (optional).

## `outputFormat` (type: `string`):

Generate MCP server package, JSON manifest, or both.

## `includeExamples` (type: `boolean`):

Include example requests/responses in the MCP tool descriptions.

## `maxEndpoints` (type: `integer`):

Maximum number of endpoints to process.

## Actor input object example

```json
{
  "openapiSource": "https://petstore3.swagger.io/api/v3/openapi.json",
  "serverName": "openapi-mcp-server",
  "includeEndpoints": [],
  "excludeEndpoints": [],
  "outputFormat": "both",
  "includeExamples": true,
  "maxEndpoints": 100
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "openapiSource": "https://petstore3.swagger.io/api/v3/openapi.json",
    "includeEndpoints": [],
    "excludeEndpoints": []
};

// Run the Actor and wait for it to finish
const run = await client.actor("theguide/openapi-to-mcp-converter").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "openapiSource": "https://petstore3.swagger.io/api/v3/openapi.json",
    "includeEndpoints": [],
    "excludeEndpoints": [],
}

# Run the Actor and wait for it to finish
run = client.actor("theguide/openapi-to-mcp-converter").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "openapiSource": "https://petstore3.swagger.io/api/v3/openapi.json",
  "includeEndpoints": [],
  "excludeEndpoints": []
}' |
apify call theguide/openapi-to-mcp-converter --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,theguide/openapi-to-mcp-converter"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/kHQOKhiCyxhnhIp6k/builds/RtP39DoPkMCnEbUUY/openapi.json
