api2ai 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,189 @@
1
+ # API2AI: OpenAPI to MCP-Use Server
2
+
3
+ Generate production-ready MCP servers from any OpenAPI specification using the [mcp-use](https://mcp-use.com) framework.
4
+
5
+ ## Features
6
+
7
+ - 🚀 **Modern Framework** - Uses mcp-use for clean, maintainable code
8
+ - 🔍 **Built-in Inspector** - Test tools immediately at `/inspector`
9
+ - 📡 **Multiple Transports** - HTTP, SSE, and Streamable HTTP support
10
+ - 🎨 **UI Widgets** - Compatible with ChatGPT Apps SDK and MCP-UI
11
+ - 🔐 **Auth Support** - Bearer tokens, API keys, custom headers
12
+ - ✨ **Zod Schemas** - Type-safe parameter validation
13
+ - 🐳 **Production Ready** - Docker, PM2, and Kubernetes ready
14
+
15
+ ## Quick Start
16
+
17
+ ```bash
18
+ # Generate a server from the Petstore API
19
+ node generate-mcp-use-server.js \
20
+ https://petstore3.swagger.io/api/v3/openapi.json \
21
+ ./petstore-mcp \
22
+ --name petstore-api
23
+
24
+ # Install and run
25
+ cd petstore-mcp
26
+ npm install
27
+ npm start
28
+ ```
29
+
30
+ Open http://localhost:3000/inspector to test your tools!
31
+
32
+ ## Usage
33
+
34
+ ### CLI
35
+
36
+ ```bash
37
+ node generate-mcp-use-server.js <openapi-spec> [output-folder] [options]
38
+
39
+ Options:
40
+ --name <name> Server name (default: api-mcp-server)
41
+ --base-url <url> Override API base URL
42
+ --port <port> Server port (default: 3000)
43
+ --help Show help
44
+ ```
45
+
46
+ ### Examples
47
+
48
+ ```bash
49
+ # From remote URL
50
+ node generate-mcp-use-server.js \
51
+ https://api.example.com/openapi.json \
52
+ ./my-server \
53
+ --name my-api
54
+
55
+ # From local file
56
+ node generate-mcp-use-server.js \
57
+ ./specs/my-api.yaml \
58
+ ./my-mcp-server \
59
+ --port 8080
60
+
61
+ # With custom base URL
62
+ node generate-mcp-use-server.js \
63
+ ./petstore.json \
64
+ ./petstore \
65
+ --base-url https://petstore.example.com/v3
66
+ ```
67
+
68
+ ### Programmatic Usage
69
+
70
+ ```javascript
71
+ import { generateMcpServer, extractTools, loadOpenApiSpec } from './generate-mcp-use-server.js';
72
+
73
+ // Generate complete server
74
+ const result = await generateMcpServer(
75
+ 'https://api.example.com/openapi.json',
76
+ './output-folder',
77
+ {
78
+ serverName: 'my-api',
79
+ baseUrl: 'https://api.example.com/v1',
80
+ port: 3000,
81
+ }
82
+ );
83
+
84
+ console.log(`Generated ${result.toolCount} tools`);
85
+
86
+ // Or just extract tools for custom processing
87
+ const spec = await loadOpenApiSpec('./my-spec.json');
88
+ const tools = extractTools(spec, {
89
+ filterFn: (tool) => tool.method === 'get', // Only GET endpoints
90
+ excludeOperationIds: ['deleteUser'], // Exclude specific operations
91
+ });
92
+ ```
93
+
94
+ ## Generated Output
95
+
96
+ ```
97
+ my-mcp-server/
98
+ ├── .env # Environment config (gitignored)
99
+ ├── .env.example # Example environment file
100
+ ├── .gitignore
101
+ ├── package.json
102
+ ├── README.md # Generated documentation
103
+ └── src/
104
+ ├── index.js # Main server with tool registrations
105
+ ├── http-client.js # HTTP utilities
106
+ └── tools-config.js # Tool configurations
107
+ ```
108
+
109
+ ## Generated Server Features
110
+
111
+ ### Built-in Endpoints
112
+
113
+ | Endpoint | Description |
114
+ |----------|-------------|
115
+ | `GET /inspector` | Interactive tool testing UI |
116
+ | `POST /mcp` | MCP protocol endpoint |
117
+ | `GET /sse` | Server-Sent Events endpoint |
118
+ | `GET /health` | Health check |
119
+
120
+ ### Environment Variables
121
+
122
+ | Variable | Description |
123
+ |----------|-------------|
124
+ | `PORT` | Server port |
125
+ | `NODE_ENV` | development/production |
126
+ | `API_BASE_URL` | Base URL for API calls |
127
+ | `API_KEY` | Bearer token auth |
128
+ | `API_AUTH_HEADER` | Custom header (`Name:value`) |
129
+ | `MCP_URL` | Public URL for widgets |
130
+ | `ALLOWED_ORIGINS` | CORS origins (production) |
131
+
132
+
133
+ ### Connect to ChatGPT
134
+
135
+ The generated server supports the OpenAI Apps SDK out of the box.
136
+
137
+ ## Advanced Options
138
+
139
+ ### Filter Tools by Method
140
+
141
+ ```javascript
142
+ const result = await generateMcpServer(specUrl, outputDir, {
143
+ filterFn: (tool) => ['get', 'post'].includes(tool.method),
144
+ });
145
+ ```
146
+
147
+ ### Exclude Dangerous Operations
148
+
149
+ ```javascript
150
+ const result = await generateMcpServer(specUrl, outputDir, {
151
+ excludeOperationIds: [
152
+ 'deleteUser',
153
+ 'deleteAllData',
154
+ 'adminReset',
155
+ ],
156
+ });
157
+ ```
158
+
159
+ ### Filter by Path Pattern
160
+
161
+ ```javascript
162
+ const result = await generateMcpServer(specUrl, outputDir, {
163
+ filterFn: (tool) => tool.pathTemplate.startsWith('/api/v2/'),
164
+ });
165
+ ```
166
+
167
+ ### Combine Filters
168
+
169
+ ```javascript
170
+ const result = await generateMcpServer(specUrl, outputDir, {
171
+ excludeOperationIds: ['deleteUser'],
172
+ filterFn: (tool) =>
173
+ tool.method === 'get' &&
174
+ tool.pathTemplate.includes('/public/'),
175
+ });
176
+ ```
177
+
178
+
179
+
180
+ ## Comparison with Raw MCP SDK
181
+
182
+ | Feature | This Generator | Raw SDK |
183
+ |---------|---------------|---------|
184
+ | Code needed | ~50 lines | ~200+ lines |
185
+ | Inspector | ✅ Built-in | ❌ Manual |
186
+ | UI Widgets | ✅ Supported | ❌ Manual |
187
+ | Zod validation | ✅ Generated | ❌ Manual |
188
+ | Authentication | ✅ Configured | ❌ Manual |
189
+ | Production ready | ✅ Yes | ⚠️ Requires work |
package/bun.lock ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "lockfileVersion": 1,
3
+ "configVersion": 1,
4
+ "workspaces": {
5
+ "": {
6
+ "name": "api2ai",
7
+ "devDependencies": {
8
+ "js-yaml": "^4.1.0",
9
+ },
10
+ },
11
+ },
12
+ "packages": {
13
+ "argparse": ["argparse@2.0.1", "", {}, "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q=="],
14
+
15
+ "js-yaml": ["js-yaml@4.1.1", "", { "dependencies": { "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" } }, "sha512-qQKT4zQxXl8lLwBtHMWwaTcGfFOZviOJet3Oy/xmGk2gZH677CJM9EvtfdSkgWcATZhj/55JZ0rmy3myCT5lsA=="],
16
+ }
17
+ }
@@ -0,0 +1,14 @@
1
+ # Server Configuration
2
+ PORT=3000
3
+ NODE_ENV=development
4
+
5
+ # API Configuration
6
+ API_BASE_URL=/api/v3
7
+
8
+ # Authentication
9
+ API_KEY=your-api-key-here
10
+ # API_AUTH_HEADER=Header-Name:header-value
11
+
12
+ # MCP Configuration
13
+ # MCP_URL=https://your-mcp-server.com
14
+ # ALLOWED_ORIGINS=https://allowed-origin.com
@@ -0,0 +1,145 @@
1
+ # petstore-api
2
+
3
+ MCP server auto-generated from OpenAPI specification using the [mcp-use](https://mcp-use.com) framework.
4
+
5
+ ## Features
6
+
7
+ - 🛠️ **19 API Tools** - All operations from the OpenAPI spec
8
+ - 🔍 **Built-in Inspector** - Test tools at `/inspector`
9
+ - 📡 **Streamable HTTP** - Modern MCP transport
10
+ - 🔐 **Authentication Support** - Bearer tokens & custom headers
11
+ - 🎨 **UI Widgets** - Compatible with ChatGPT and MCP-UI
12
+
13
+ ## Quick Start
14
+
15
+ ```bash
16
+ # Install dependencies
17
+ npm install
18
+
19
+ # Configure environment
20
+ cp .env.example .env
21
+ # Edit .env with your API credentials
22
+
23
+ # Start the server
24
+ npm start
25
+
26
+ # Or with hot reload
27
+ npm run dev
28
+ ```
29
+
30
+ Then open http://localhost:3000/inspector to test your tools!
31
+
32
+ ## Environment Variables
33
+
34
+ | Variable | Description | Default |
35
+ |----------|-------------|---------|
36
+ | `PORT` | Server port | 3000 |
37
+ | `NODE_ENV` | Environment (development/production) | development |
38
+ | `API_BASE_URL` | Base URL for API requests | /api/v3 |
39
+ | `API_KEY` | Bearer token for Authorization header | - |
40
+ | `API_AUTH_HEADER` | Custom auth header (format: `Header:value`) | - |
41
+ | `MCP_URL` | Public MCP server URL (for widgets) | http://localhost:3000 |
42
+ | `ALLOWED_ORIGINS` | Allowed origins in production (comma-separated) | - |
43
+
44
+ ## Connect to Claude Desktop
45
+
46
+ Add to your Claude Desktop configuration:
47
+
48
+ **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
49
+ **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
50
+
51
+ ```json
52
+ {
53
+ "mcpServers": {
54
+ "petstore-api": {
55
+ "url": "http://localhost:3000/mcp"
56
+ }
57
+ }
58
+ }
59
+ ```
60
+
61
+ ## Connect to ChatGPT
62
+
63
+ This server supports the OpenAI Apps SDK. Configure your ChatGPT integration to use:
64
+
65
+ ```
66
+ http://localhost:3000/mcp
67
+ ```
68
+
69
+ ## Available Tools
70
+
71
+ | Tool | Method | Path | Description |
72
+ |------|--------|------|-------------|
73
+ | `addPet` | POST | /pet | Add a new pet to the store. |
74
+ | `updatePet` | PUT | /pet | Update an existing pet. |
75
+ | `findPetsByStatus` | GET | /pet/findByStatus | Finds Pets by status. |
76
+ | `findPetsByTags` | GET | /pet/findByTags | Finds Pets by tags. |
77
+ | `getPetById` | GET | /pet/{petId} | Find pet by ID. |
78
+ | `updatePetWithForm` | POST | /pet/{petId} | Updates a pet in the store with form data. |
79
+ | `deletePet` | DELETE | /pet/{petId} | Deletes a pet. |
80
+ | `uploadFile` | POST | /pet/{petId}/uploadImage | Uploads an image. |
81
+ | `getInventory` | GET | /store/inventory | Returns pet inventories by status. |
82
+ | `placeOrder` | POST | /store/order | Place an order for a pet. |
83
+ | `getOrderById` | GET | /store/order/{orderId} | Find purchase order by ID. |
84
+ | `deleteOrder` | DELETE | /store/order/{orderId} | Delete purchase order by identifier. |
85
+ | `createUser` | POST | /user | Create user. |
86
+ | `createUsersWithListInput` | POST | /user/createWithList | Creates list of users with given input array. |
87
+ | `loginUser` | GET | /user/login | Logs user into the system. |
88
+ | `logoutUser` | GET | /user/logout | Logs out current logged in user session. |
89
+ | `getUserByName` | GET | /user/{username} | Get user by user name. |
90
+ | `updateUser` | PUT | /user/{username} | Update user resource. |
91
+ | `deleteUser` | DELETE | /user/{username} | Delete user resource. |
92
+
93
+ ## API Endpoints
94
+
95
+ | Endpoint | Description |
96
+ |----------|-------------|
97
+ | `GET /inspector` | Interactive tool testing UI |
98
+ | `POST /mcp` | MCP protocol endpoint |
99
+ | `GET /sse` | Server-Sent Events endpoint |
100
+ | `GET /health` | Health check endpoint |
101
+
102
+ ## Project Structure
103
+
104
+ ```
105
+ petstore-api/
106
+ ├── .env # Environment configuration
107
+ ├── .env.example # Example environment file
108
+ ├── package.json # Dependencies
109
+ ├── README.md # This file
110
+ └── src/
111
+ ├── index.js # Main server with tool registrations
112
+ ├── http-client.js # HTTP utilities for API calls
113
+ └── tools-config.js # Tool configurations from OpenAPI
114
+ ```
115
+
116
+ ## Production Deployment
117
+
118
+ ### Docker
119
+
120
+ ```dockerfile
121
+ FROM node:20-alpine
122
+ WORKDIR /app
123
+ COPY package*.json ./
124
+ RUN npm ci --only=production
125
+ COPY . .
126
+ ENV NODE_ENV=production
127
+ EXPOSE 3000
128
+ CMD ["npm", "start"]
129
+ ```
130
+
131
+ ### PM2
132
+
133
+ ```bash
134
+ pm2 start src/index.js --name petstore-api
135
+ ```
136
+
137
+ ## Source
138
+
139
+ - **OpenAPI Spec**: `https://petstore3.swagger.io/api/v3/openapi.json`
140
+ - **Generated**: 2025-12-30T23:36:57.107Z
141
+ - **Framework**: [mcp-use](https://mcp-use.com)
142
+
143
+ ## License
144
+
145
+ MIT