# Mcp Server Generator (`fiery_dream/mcp-server-generator`) Actor

- **URL**: https://apify.com/fiery\_dream/mcp-server-generator.md
- **Developed by:** [Cody Churchwell](https://apify.com/fiery_dream) (community)
- **Categories:** AI, Agents, MCP servers
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.01 / 1,000 results

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

## 🚀 MCP Server Generator from OpenAPI

**Automatically generate production-ready Model Context Protocol (MCP) servers from OpenAPI/Swagger specifications.**

Save hours of boilerplate coding. Just provide your API spec, and get a complete, type-safe MCP server ready to deploy.

### Features

- ✅ **OpenAPI 3.0 & Swagger 2.0** support
- ✅ **TypeScript or Python** output
- ✅ **Type-safe** tool definitions
- ✅ **Authentication** handling (API keys, OAuth, Bearer tokens)
- ✅ **Automatic** parameter validation
- ✅ **Error handling** built-in
- ✅ **Documentation** generated
- ✅ **Ready to deploy** - complete package with dependencies

### Use Cases

| Scenario | Benefit |
|----------|---------|
| **API Integration** | Turn any OpenAPI API into MCP tools in minutes |
| **LLM Agents** | Give AI agents access to your APIs instantly |
| **Rapid Prototyping** | Test MCP integrations without writing boilerplate |
| **Multi-API Orchestration** | Generate servers for multiple APIs and compose them |

### Quick Start

1. **Find your API's OpenAPI spec** (Swagger JSON/YAML URL)
2. **Run this Actor** with the spec URL
3. **Download generated code** from Key-Value Store
4. **Deploy** your MCP server

### Input

```json
{
  "openApiSource": "https://petstore.swagger.io/v2/swagger.json",
  "language": "typescript",
  "serverName": "petstore-mcp",
  "includeAllEndpoints": true,
  "includeAuth": true
}
```

### Output

Complete MCP server with:

- `server.ts` or `server.py` - Main MCP server implementation
- `package.json` or `requirements.txt` - Dependencies
- `README.md` - Usage documentation

All files saved to Key-Value Store and dataset.

### Example Generated Code

**TypeScript:**

```typescript
server.setRequestHandler('tools/call', async (request) => {
    if (request.params.name === 'get_pet_by_id') {
        const response = await axios.get(`${API_BASE_URL}/pet/${request.params.arguments.petId}`);
        return { content: [{ type: 'text', text: JSON.stringify(response.data) }] };
    }
});
```

**Python:**

```python
@server.call_tool()
async def get_pet_by_id(pet_id: int):
    async with httpx.AsyncClient() as client:
        response = await client.get(f"{API_BASE_URL}/pet/{pet_id}")
        return response.json()
```

### Why MCP?

Model Context Protocol (MCP) is the standard protocol for connecting AI assistants to external tools and data sources. Adopted by Anthropic, Google, and OpenAI.

Building MCP servers manually requires:

- Understanding MCP protocol specifications
- Writing request/response handlers
- Type definitions for all endpoints
- Error handling
- Authentication logic

**This Actor does all of that automatically.**

### Advanced Features

#### Tag Filtering

Only generate tools for specific API sections:

```json
{
  "includeAllEndpoints": false,
  "filterTags": ["pets", "store"]
}
```

#### Authentication

Automatically handles:

- API Key authentication (header, query param)
- Bearer token authentication
- OAuth 2.0 flows (code generated, you add tokens)

#### Test Generation

```json
{
  "generateTests": true
}
```

Includes unit test templates for all generated tools.

### Technical Details

**Parsing**: Uses `swagger-parser` for robust OpenAPI validation and dereferencing

**Code Generation**: Handlebars templates for clean, maintainable output

**Type Safety**: Full TypeScript type definitions or Python type hints

**Error Handling**: Try-catch blocks with meaningful error messages

**Standards Compliant**: Follows MCP 1.0 specification exactly

### Limitations

- Complex authentication flows may require manual enhancement
- Custom request/response transformations not supported
- Generated code is a starting point - customize for production

### Built for Apify $1M Challenge

This Actor solves a real problem in the exploding MCP ecosystem. Every API with an OpenAPI spec can now become MCP-enabled in seconds.

***

**Ready to generate your MCP server?** [Run now →](https://apify.com/actors)

# Actor input Schema

## `openApiSource` (type: `string`):

URL to OpenAPI/Swagger spec (JSON or YAML) or paste the spec directly

## `language` (type: `string`):

Programming language for generated MCP server

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

Name for your MCP server (will be used in package name and documentation)

## `includeAllEndpoints` (type: `boolean`):

Generate tools for all API endpoints. If false, you can filter by tags.

## `filterTags` (type: `array`):

Only generate tools for endpoints with these OpenAPI tags (only used if 'Include All Endpoints' is false)

## `includeAuth` (type: `boolean`):

Generate authentication handling code for API keys, OAuth, or Bearer tokens

## `generateTests` (type: `boolean`):

Include unit test templates for generated MCP tools

## Actor input object example

```json
{
  "openApiSource": "https://petstore.swagger.io/v2/swagger.json",
  "language": "typescript",
  "serverName": "my-mcp-server",
  "includeAllEndpoints": true,
  "filterTags": [],
  "includeAuth": true,
  "generateTests": false
}
```

# 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://petstore.swagger.io/v2/swagger.json",
    "language": "typescript",
    "serverName": "my-mcp-server",
    "includeAllEndpoints": true,
    "filterTags": [],
    "includeAuth": true,
    "generateTests": false
};

// Run the Actor and wait for it to finish
const run = await client.actor("fiery_dream/mcp-server-generator").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://petstore.swagger.io/v2/swagger.json",
    "language": "typescript",
    "serverName": "my-mcp-server",
    "includeAllEndpoints": True,
    "filterTags": [],
    "includeAuth": True,
    "generateTests": False,
}

# Run the Actor and wait for it to finish
run = client.actor("fiery_dream/mcp-server-generator").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://petstore.swagger.io/v2/swagger.json",
  "language": "typescript",
  "serverName": "my-mcp-server",
  "includeAllEndpoints": true,
  "filterTags": [],
  "includeAuth": true,
  "generateTests": false
}' |
apify call fiery_dream/mcp-server-generator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fiery_dream/mcp-server-generator"
        }
    }
}

```

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/mId2LNQow5nHNhEMh/builds/stnFf3p7Kwmesyexg/openapi.json
