dynamic-openapi-mcp 0.1.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 +324 -0
- package/dist/cli.js +1452 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +134 -0
- package/dist/index.js +1350 -0
- package/dist/index.js.map +1 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# dynamic-openapi-mcp
|
|
4
|
+
|
|
5
|
+
### Any OpenAPI spec. Instant AI tools.
|
|
6
|
+
|
|
7
|
+
Point it at a spec — your AI agent can call the API.
|
|
8
|
+
<br>
|
|
9
|
+
**OpenAPI v3** • **JSON & YAML** • **Auto-auth** • **Zero config**
|
|
10
|
+
<br>
|
|
11
|
+
Every endpoint becomes a tool. Every schema becomes a resource.
|
|
12
|
+
|
|
13
|
+
[](https://www.npmjs.com/package/dynamic-openapi-mcp)
|
|
14
|
+
[](https://www.npmjs.com/package/dynamic-openapi-mcp)
|
|
15
|
+
[](https://www.typescriptlang.org/)
|
|
16
|
+
[](https://nodejs.org/)
|
|
17
|
+
[](https://github.com/forattini-dev/dynamic-openapi-mcp/blob/main/LICENSE)
|
|
18
|
+
|
|
19
|
+
[Quick Start](#quick-start) · [Agent Setup](#setup-with-ai-agents) · [Auth](#authentication) · [Programmatic API](#programmatic-usage) · [CLI](#cli-reference)
|
|
20
|
+
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Quick Start
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx dynamic-openapi-mcp -s https://petstore3.swagger.io/api/v3/openapi.json
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
That's it. The MCP server starts, your AI agent discovers all the tools, and can call the Petstore API.
|
|
32
|
+
|
|
33
|
+
For Claude Code, add it in one command:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
claude mcp add petstore -- npx dynamic-openapi-mcp -s https://petstore3.swagger.io/api/v3/openapi.json
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Now ask Claude: *"list all available pets"* — it will call `listPets` and return real data.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## Table of Contents
|
|
44
|
+
|
|
45
|
+
- [Quick Start](#quick-start)
|
|
46
|
+
- [What's Inside](#whats-inside)
|
|
47
|
+
- [Setup with AI Agents](#setup-with-ai-agents)
|
|
48
|
+
- [Claude Code](#claude-code)
|
|
49
|
+
- [Cursor](#cursor)
|
|
50
|
+
- [Windsurf](#windsurf)
|
|
51
|
+
- [Claude Desktop](#claude-desktop)
|
|
52
|
+
- [Multiple APIs](#multiple-apis)
|
|
53
|
+
- [Authentication](#authentication)
|
|
54
|
+
- [Environment Variables](#via-environment-variables)
|
|
55
|
+
- [Supported Schemes](#supported-schemes)
|
|
56
|
+
- [Programmatic Usage](#programmatic-usage)
|
|
57
|
+
- [Custom Base URL](#custom-base-url)
|
|
58
|
+
- [Inline Spec](#from-an-inline-spec)
|
|
59
|
+
- [Inspecting the Spec](#inspecting-the-parsed-spec)
|
|
60
|
+
- [CLI Reference](#cli-reference)
|
|
61
|
+
- [How the Mapping Works](#how-the-mapping-works)
|
|
62
|
+
- [Operations → Tools](#operations--tools)
|
|
63
|
+
- [Schemas → Resources](#schemas--resources)
|
|
64
|
+
- [Prompts](#prompts)
|
|
65
|
+
- [License](#license)
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## What's Inside
|
|
70
|
+
|
|
71
|
+
| Category | What you get |
|
|
72
|
+
|:---------|:-------------|
|
|
73
|
+
| **Tools** | One per operation — `GET /pets` becomes `listPets`, with fully typed inputs |
|
|
74
|
+
| **Resources** | Full spec as `openapi://spec` + each schema as `openapi://schemas/{name}` |
|
|
75
|
+
| **Prompts** | `describe-api` for an overview, `explore-endpoint` for details on any operation |
|
|
76
|
+
| **Auth** | Bearer, API Key (header/query/cookie), Basic, OAuth2 client credentials |
|
|
77
|
+
| **Sources** | URL, local file (JSON/YAML), inline string, or JavaScript object |
|
|
78
|
+
|
|
79
|
+
The flow is simple: AI calls a tool → `dynamic-openapi-mcp` makes the real HTTP request → response comes back as MCP content.
|
|
80
|
+
|
|
81
|
+
## Setup with AI Agents
|
|
82
|
+
|
|
83
|
+
### Claude Code
|
|
84
|
+
|
|
85
|
+
Add to your project's `.mcp.json`:
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"mcpServers": {
|
|
90
|
+
"my-api": {
|
|
91
|
+
"command": "npx",
|
|
92
|
+
"args": ["dynamic-openapi-mcp", "-s", "https://api.example.com/openapi.json"],
|
|
93
|
+
"env": {
|
|
94
|
+
"OPENAPI_AUTH_TOKEN": "your-bearer-token"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Or add via CLI:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
claude mcp add my-api -- npx dynamic-openapi-mcp -s https://api.example.com/openapi.json
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Cursor
|
|
108
|
+
|
|
109
|
+
Go to **Settings → MCP** and add a new server, or add to `.cursor/mcp.json`:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{
|
|
113
|
+
"mcpServers": {
|
|
114
|
+
"my-api": {
|
|
115
|
+
"command": "npx",
|
|
116
|
+
"args": ["dynamic-openapi-mcp", "-s", "./specs/api.yaml"],
|
|
117
|
+
"env": {
|
|
118
|
+
"OPENAPI_API_KEY": "your-api-key"
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Windsurf
|
|
126
|
+
|
|
127
|
+
Add to `~/.codeium/windsurf/mcp_config.json`:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"mcpServers": {
|
|
132
|
+
"my-api": {
|
|
133
|
+
"command": "npx",
|
|
134
|
+
"args": ["dynamic-openapi-mcp", "-s", "https://api.example.com/openapi.json"],
|
|
135
|
+
"env": {
|
|
136
|
+
"OPENAPI_AUTH_TOKEN": "sk-..."
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Claude Desktop
|
|
144
|
+
|
|
145
|
+
Add to your config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
|
|
146
|
+
|
|
147
|
+
```json
|
|
148
|
+
{
|
|
149
|
+
"mcpServers": {
|
|
150
|
+
"my-api": {
|
|
151
|
+
"command": "npx",
|
|
152
|
+
"args": ["dynamic-openapi-mcp", "-s", "/absolute/path/to/spec.yaml"],
|
|
153
|
+
"env": {
|
|
154
|
+
"OPENAPI_AUTH_TOKEN": "your-token"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Multiple APIs
|
|
162
|
+
|
|
163
|
+
Connect several APIs at once — each runs as a separate MCP server, and the AI sees all their tools combined:
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"mcpServers": {
|
|
168
|
+
"github": {
|
|
169
|
+
"command": "npx",
|
|
170
|
+
"args": ["dynamic-openapi-mcp", "-s", "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json"],
|
|
171
|
+
"env": { "OPENAPI_AUTH_TOKEN": "ghp_..." }
|
|
172
|
+
},
|
|
173
|
+
"stripe": {
|
|
174
|
+
"command": "npx",
|
|
175
|
+
"args": ["dynamic-openapi-mcp", "-s", "./specs/stripe.yaml"],
|
|
176
|
+
"env": { "OPENAPI_AUTH_TOKEN": "sk_..." }
|
|
177
|
+
},
|
|
178
|
+
"internal-api": {
|
|
179
|
+
"command": "npx",
|
|
180
|
+
"args": ["dynamic-openapi-mcp", "-s", "https://internal.company.com/api/v1/openapi.json"],
|
|
181
|
+
"env": { "OPENAPI_API_KEY": "key-..." }
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
## Authentication
|
|
188
|
+
|
|
189
|
+
### Via environment variables
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
# Bearer token (most common)
|
|
193
|
+
OPENAPI_AUTH_TOKEN=sk-123 npx dynamic-openapi-mcp -s ./spec.yaml
|
|
194
|
+
|
|
195
|
+
# API key
|
|
196
|
+
OPENAPI_API_KEY=key-456 npx dynamic-openapi-mcp -s ./spec.yaml
|
|
197
|
+
|
|
198
|
+
# Per-scheme (matches securitySchemes names in your spec)
|
|
199
|
+
OPENAPI_AUTH_BEARERAUTH_TOKEN=sk-123 npx dynamic-openapi-mcp -s ./spec.yaml
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Or set them in the MCP config `env` block — same effect, cleaner setup.
|
|
203
|
+
|
|
204
|
+
### Supported schemes
|
|
205
|
+
|
|
206
|
+
| Scheme | Env var | Programmatic config |
|
|
207
|
+
|:-------|:--------|:--------------------|
|
|
208
|
+
| Bearer | `OPENAPI_AUTH_TOKEN` | `auth.bearerToken` |
|
|
209
|
+
| API Key (header/query/cookie) | `OPENAPI_API_KEY` | `auth.apiKey` |
|
|
210
|
+
| Basic | `OPENAPI_AUTH_TOKEN` (as `user:pass`) | `auth.basicAuth` |
|
|
211
|
+
| OAuth2 (client credentials) | — | `auth.oauth2` |
|
|
212
|
+
| Custom | — | `auth.custom` (function) |
|
|
213
|
+
|
|
214
|
+
Resolution order: programmatic config → per-scheme env var → global env var.
|
|
215
|
+
|
|
216
|
+
## Programmatic Usage
|
|
217
|
+
|
|
218
|
+
```bash
|
|
219
|
+
pnpm add dynamic-openapi-mcp
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
import { createOpenApiMcp } from 'dynamic-openapi-mcp'
|
|
224
|
+
|
|
225
|
+
const mcp = await createOpenApiMcp({
|
|
226
|
+
source: 'https://petstore3.swagger.io/api/v3/openapi.json',
|
|
227
|
+
auth: { bearerToken: 'my-token' },
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
// Start as MCP server over stdio
|
|
231
|
+
await mcp.serve()
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Custom base URL
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
const mcp = await createOpenApiMcp({
|
|
238
|
+
source: './spec.yaml',
|
|
239
|
+
baseUrl: 'http://localhost:3000',
|
|
240
|
+
headers: { 'X-Custom-Header': 'value' },
|
|
241
|
+
})
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### From an inline spec
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
const mcp = await createOpenApiMcp({
|
|
248
|
+
source: {
|
|
249
|
+
openapi: '3.0.3',
|
|
250
|
+
info: { title: 'My API', version: '1.0.0' },
|
|
251
|
+
servers: [{ url: 'https://api.example.com' }],
|
|
252
|
+
paths: {
|
|
253
|
+
'/hello': {
|
|
254
|
+
get: {
|
|
255
|
+
operationId: 'sayHello',
|
|
256
|
+
summary: 'Say hello',
|
|
257
|
+
responses: { '200': { description: 'OK' } },
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
},
|
|
261
|
+
},
|
|
262
|
+
})
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Inspecting the parsed spec
|
|
266
|
+
|
|
267
|
+
```typescript
|
|
268
|
+
const mcp = await createOpenApiMcp({ source: './spec.yaml' })
|
|
269
|
+
|
|
270
|
+
console.log(mcp.spec.title) // "My API"
|
|
271
|
+
console.log(mcp.spec.operations) // ParsedOperation[]
|
|
272
|
+
console.log(mcp.spec.schemas) // { Pet: {...}, User: {...} }
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
## CLI Reference
|
|
276
|
+
|
|
277
|
+
```
|
|
278
|
+
dynamic-openapi-mcp [options] [source]
|
|
279
|
+
|
|
280
|
+
Options:
|
|
281
|
+
-s, --source <url|file> OpenAPI spec URL or file path
|
|
282
|
+
-b, --base-url <url> Override the base URL from the spec
|
|
283
|
+
-h, --help Show help
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
| Environment Variable | Description |
|
|
287
|
+
|:---------------------|:------------|
|
|
288
|
+
| `OPENAPI_SOURCE` | Spec URL or file path (alternative to `-s`) |
|
|
289
|
+
| `OPENAPI_BASE_URL` | Override base URL |
|
|
290
|
+
| `OPENAPI_AUTH_TOKEN` | Bearer token for authentication |
|
|
291
|
+
| `OPENAPI_API_KEY` | API key for authentication |
|
|
292
|
+
|
|
293
|
+
## How the Mapping Works
|
|
294
|
+
|
|
295
|
+
### Operations → Tools
|
|
296
|
+
|
|
297
|
+
Each operation in the spec becomes one MCP tool:
|
|
298
|
+
|
|
299
|
+
| OpenAPI | MCP Tool |
|
|
300
|
+
|:--------|:---------|
|
|
301
|
+
| `operationId: listPets` | Tool name: `listPets` |
|
|
302
|
+
| `GET /pets/{petId}` (no operationId) | Tool name: `get_pets_by_petId` |
|
|
303
|
+
| `summary` or `description` | Tool description (truncated to 200 chars) |
|
|
304
|
+
| Path + query + header params | Top-level input properties |
|
|
305
|
+
| Request body | Input property under `body` key |
|
|
306
|
+
|
|
307
|
+
### Schemas → Resources
|
|
308
|
+
|
|
309
|
+
| OpenAPI | MCP Resource URI |
|
|
310
|
+
|:--------|:-----------------|
|
|
311
|
+
| Full dereferenced spec | `openapi://spec` |
|
|
312
|
+
| `components.schemas.Pet` | `openapi://schemas/Pet` |
|
|
313
|
+
| `components.schemas.User` | `openapi://schemas/User` |
|
|
314
|
+
|
|
315
|
+
### Prompts
|
|
316
|
+
|
|
317
|
+
| Prompt | Args | What it returns |
|
|
318
|
+
|:-------|:-----|:----------------|
|
|
319
|
+
| `describe-api` | — | Overview with title, version, all endpoints, auth schemes, schemas |
|
|
320
|
+
| `explore-endpoint` | `operationId` | Full details: parameters, request body schema, responses, security |
|
|
321
|
+
|
|
322
|
+
## License
|
|
323
|
+
|
|
324
|
+
MIT
|