@powerduck/openapi-mcp-server 1.2.0 → 1.3.0

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.
Files changed (2) hide show
  1. package/README.md +154 -282
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # @powerduck/openapi-mcp-server
2
2
 
3
- Turn any OpenAPI 3.2 document into a fully functional MCP (Model Context Protocol) server. Automatically generates tools, prompts, and resources from your API spec. Supports both stdio and HTTP (SSE) transports.
4
-
5
3
  [![npm version](https://img.shields.io/npm/v/@powerduck/openapi-mcp-server)](https://www.npmjs.com/package/@powerduck/openapi-mcp-server)
6
4
  [![license](https://img.shields.io/npm/l/@powerduck/openapi-mcp-server)](https://github.com/PowerDuckie/openapi-mcp-server/blob/main/LICENSE)
5
+ [![downloads](https://img.shields.io/npm/dm/@powerduck/openapi-mcp-server)](https://www.npmjs.com/package/@powerduck/openapi-mcp-server)
7
6
 
8
- ## Links
7
+ Turn any OpenAPI 3.2 document into a fully functional MCP (Model Context Protocol) server. Automatically generates tools, prompts, and resources from your API spec. Supports both stdio and HTTP (SSE) transports.
9
8
 
10
- - [Official Website](https://www.powerduck.com/opensource/openapi-mcp-server.html)
11
- - [Documentation](https://www.powerduck.com/docs/openapi-mcp-server/introduction)
12
- - [Live Demo](https://www.powerduck.com/demo/openapi-mcp-server.html)
13
- - [GitHub](https://github.com/PowerDuckie/openapi-mcp-server)
14
- - [npm](https://www.npmjs.com/package/@powerduck/openapi-mcp-server)
9
+ ---
10
+
11
+ Powerduck is an open-source developer tooling platform for teams building modern API workflows.
12
+
13
+ - **Auto-Generated Tools** — Every OpenAPI operation becomes an MCP tool with full parameter schemas
14
+ - **Auto-Generated Prompts** — Smart prompt templates for common API workflows
15
+ - **Auto-Generated Resources** — API docs, schemas, and examples accessible as MCP resources
16
+ - **2 Transports** — stdio for local AI clients, HTTP/SSE for remote and cloud deployments
17
+ - **Security Resolution** — Bearer tokens, API keys, Basic auth, OAuth2, and custom schemes
18
+ - **Type-Safe Execution** — Full parameter validation before executing API calls
19
+ - **Error Handling** — Structured MCP errors with API response details
20
+ - **Admin Dashboard** — Built-in web UI for monitoring tools, viewing logs, and testing
21
+ - **Express Integration** — Attach MCP routes to any Express/Node.js HTTP server
22
+ - **CLI & Programmatic** — Full CLI for quick starts, programmatic API for custom setups
15
23
 
16
24
  ---
17
25
 
@@ -59,321 +67,198 @@ import { attachSseRoutes } from "@powerduck/openapi-mcp-server";
59
67
 
60
68
  const app = express();
61
69
 
62
- attachSseRoutes(
63
- app,
64
- () => "./openapi.json", // spec provider: path, URL, or parsed document
65
- () => ({ userId: "user-123" }), // context provider (optional)
66
- (req) => req.headers["x-api-key"] === "secret", // route guard (optional)
67
- );
70
+ attachSseRoutes(app, {
71
+ specPath: "./openapi.json",
72
+ routePrefix: "/mcp",
73
+ serverName: "My API MCP Server",
74
+ });
68
75
 
69
76
  app.listen(3000, () => {
70
- console.log("MCP SSE server running at http://localhost:3000/mcp");
77
+ console.log("MCP server running at http://localhost:3000/mcp");
71
78
  });
72
79
  ```
73
80
 
74
- ### Generate tools from a spec
75
-
76
- ```typescript
77
- import { loadOpenApiSpec, generateTools } from "@powerduck/openapi-mcp-server";
78
-
79
- const spec = await loadOpenApiSpec("./openapi.json");
80
- const tools = generateTools(spec);
81
-
82
- console.log(`Generated ${tools.length} tools:`);
83
- for (const tool of tools) {
84
- console.log(`- ${tool.name}: ${tool.description}`);
85
- }
86
- ```
87
-
88
81
  ---
89
82
 
90
- ## Features
83
+ ## Links
91
84
 
92
- - **Automatic tool generation** — every operation becomes an MCP tool with a JSON Schema input schema derived from parameters and request body
93
- - **Prompt generation** — operations with `x-mcp-prompt` become MCP prompts with templated messages
94
- - **Resource generation** — operations marked with `x-mcp-resource` become readable MCP resources
95
- - **Two transports** — stdio for local CLI tools and IDEs, HTTP (SSE) for remote servers and web clients
96
- - **Authentication** — Bearer token, API key, and custom auth middleware for HTTP transport
97
- - **Admin server** — optional REST admin API for health checks, spec reload, and diagnostics
98
- - **Context injection** — per-request context provider for user IDs, tenant info, etc.
99
- - **Route guards** — custom authorization function for HTTP transport
100
- - **Spec loading** — load from file path, URL, or parsed object; JSON and YAML supported
101
- - **Built on `@powerduck/openapi-request`** — full OpenAPI parameter serialization for tool execution
102
- - **Dual ESM/CJS builds** — works with `import` and `require`
85
+ - [Official Website](https://www.powerduck.com/opensource/openapi-mcp-server.html)
86
+ - [Documentation](https://www.powerduck.com/docs/openapi-mcp-server/introduction)
87
+ - [GitHub](https://github.com/PowerDuckie/openapi-mcp-server)
88
+ - [npm](https://www.npmjs.com/package/@powerduck/openapi-mcp-server)
103
89
 
104
90
  ---
105
91
 
106
- ## CLI Usage
92
+ ## Features
107
93
 
108
- ```
109
- openapi-mcp serve [options]
110
-
111
- Options:
112
- --spec <path> Path or URL to OpenAPI 3.2 spec (required)
113
- --transport <mode> Transport mode: stdio or http (default: stdio)
114
- --port <number> HTTP server port (default: 3000)
115
- --host <string> HTTP server host (default: 0.0.0.0)
116
- --route-prefix <path> HTTP route prefix for MCP endpoints (default: /mcp)
117
- --server-name <name> MCP server name (default: OpenAPI MCP Server)
118
- --server-version <ver> MCP server version (default: 1.0.0)
119
- --admin Enable admin REST API
120
- --admin-port <number> Admin server port (default: 3001)
121
- --auth-type <type> Auth type: bearer, apikey, or none (default: none)
122
- --auth-token <token> Bearer token or API key value
123
- --auth-header <name> API key header name (default: x-api-key)
124
- -h, --help Show help
125
- -v, --version Show version
126
- ```
94
+ - **Auto-generated tools** — Every OpenAPI operation becomes an MCP tool with full parameter schemas
95
+ - **Auto-generated prompts** — Smart prompt templates for common API workflows
96
+ - **Auto-generated resources** — API docs, schemas, and examples accessible as MCP resources
97
+ - **2 transports** — stdio for local AI clients, HTTP/SSE for remote and cloud deployments
98
+ - **Security resolution** Bearer tokens, API keys, Basic auth, OAuth2, and custom schemes
99
+ - **Type-safe execution** Full parameter validation before executing API calls
100
+ - **Error handling** Structured MCP errors with API response details
101
+ - **Admin dashboard** Built-in web UI for monitoring tools, viewing logs, and testing
102
+ - **Express integration** Attach MCP routes to any Express/Node.js HTTP server
103
+ - **CLI & programmatic** Full CLI for quick starts, programmatic API for custom setups
104
+ - **Tool filtering** Include/exclude tools by tag, path, method, or operationId
105
+ - **Custom tool wrappers** — Wrap auto-generated tools with custom logic or validation
106
+ - **Rate limiting** Configurable rate limits per tool and per client
107
+ - **Request logging** Structured logging for all MCP requests and API calls
108
+ - **CORS support** Configurable CORS for HTTP transport
109
+ - **Dual ESM/CJS** Works with `import` and `require`, with bundled TypeScript declarations
127
110
 
128
111
  ---
129
112
 
130
- ## MCP Extensions
131
-
132
- Control how operations are exposed to MCP clients using OpenAPI extensions:
133
-
134
- ### `x-mcp-tool`
135
-
136
- Mark an operation as an MCP tool (all operations are tools by default):
137
-
138
- ```json
139
- {
140
- "paths": {
141
- "/users/{id}": {
142
- "get": {
143
- "operationId": "getUser",
144
- "x-mcp-tool": {
145
- "name": "get_user",
146
- "description": "Fetch a user by ID"
147
- }
148
- }
149
- }
150
- }
151
- }
152
- ```
113
+ ## CLI Reference
153
114
 
154
- ### `x-mcp-prompt`
115
+ ### Commands
155
116
 
156
- Mark an operation as an MCP prompt:
157
-
158
- ```json
159
- {
160
- "paths": {
161
- "/search": {
162
- "get": {
163
- "operationId": "search",
164
- "x-mcp-prompt": {
165
- "name": "search_docs",
166
- "description": "Search the documentation",
167
- "arguments": [
168
- { "name": "query", "description": "Search query", "required": true }
169
- ],
170
- "messages": [
171
- { "role": "user", "content": "Search for: {{query}}" }
172
- ]
173
- }
174
- }
175
- }
176
- }
177
- }
178
- ```
117
+ ```bash
118
+ openapi-mcp-server serve [options]
179
119
 
180
- ### `x-mcp-resource`
120
+ # Stdio server (default)
121
+ openapi-mcp-server serve --spec ./openapi.json
181
122
 
182
- Mark an operation as a readable MCP resource:
123
+ # HTTP/SSE server
124
+ openapi-mcp-server serve --spec ./openapi.json --transport http --port 3000
183
125
 
184
- ```json
185
- {
186
- "paths": {
187
- "/docs/{slug}": {
188
- "get": {
189
- "operationId": "getDoc",
190
- "x-mcp-resource": {
191
- "uriTemplate": "docs://{slug}",
192
- "name": "Documentation page",
193
- "mimeType": "text/markdown"
194
- }
195
- }
196
- }
197
- }
198
- }
126
+ # With auth and filtering
127
+ openapi-mcp-server serve \
128
+ --spec ./openapi.json \
129
+ --transport http \
130
+ --port 3000 \
131
+ --bearer $TOKEN \
132
+ --include-tags users,orders \
133
+ --exclude-methods delete
199
134
  ```
200
135
 
201
- ### `x-mcp-ignore`
202
-
203
- Exclude an operation from MCP entirely:
204
-
205
- ```json
206
- {
207
- "paths": {
208
- "/internal/debug": {
209
- "get": {
210
- "x-mcp-ignore": true
211
- }
212
- }
213
- }
214
- }
215
- ```
136
+ ### Options
137
+
138
+ | Option | Type | Default | Description |
139
+ | ------------------- | ---------- | --------- | ------------------------------------------ |
140
+ | `--spec` | `string` | - | Path or URL to OpenAPI spec (required) |
141
+ | `--transport` | `string` | `stdio` | Transport type: `stdio` or `http` |
142
+ | `--port` | `number` | `3000` | HTTP server port |
143
+ | `--host` | `string` | `0.0.0.0` | HTTP server host |
144
+ | `--route-prefix` | `string` | `/mcp` | HTTP route prefix |
145
+ | `--server-name` | `string` | - | MCP server display name |
146
+ | `--server-version` | `string` | `1.0.0` | MCP server version |
147
+ | `--bearer` | `string` | - | Bearer token for API authentication |
148
+ | `--api-key` | `string` | - | API key for API authentication |
149
+ | `--header` | `string[]` | - | Custom headers (Key: Value) |
150
+ | `--include-tags` | `string` | - | Include tools with these tags |
151
+ | `--exclude-tags` | `string` | - | Exclude tools with these tags |
152
+ | `--include-methods` | `string` | - | Include tools with these methods |
153
+ | `--exclude-methods` | `string` | - | Exclude tools with these methods |
154
+ | `--include-paths` | `string` | - | Include tools matching these path patterns |
155
+ | `--exclude-paths` | `string` | - | Exclude tools matching these path patterns |
156
+ | `--admin` | `boolean` | `true` | Enable admin dashboard |
157
+ | `--admin-port` | `number` | `3001` | Admin dashboard port |
158
+ | `--log-level` | `string` | `info` | Log level: debug, info, warn, error |
159
+ | `--cors-origin` | `string` | `*` | CORS allowed origin |
160
+ | `--rate-limit` | `number` | `100` | Max requests per minute per tool |
216
161
 
217
162
  ---
218
163
 
219
164
  ## Programmatic API
220
165
 
221
- ### `loadOpenApiSpec(input)`
222
-
223
- Loads an OpenAPI spec from a file path, URL, or parsed object. Returns the parsed document.
224
-
225
- ```typescript
226
- const spec = await loadOpenApiSpec("./openapi.json");
227
- const specFromUrl = await loadOpenApiSpec("https://api.example.com/openapi.json");
228
- const specFromObject = await loadOpenApiSpec({ openapi: "3.2.0", ... });
229
- ```
230
-
231
- ### `generateTools(spec)`
232
-
233
- Generates an array of MCP tool definitions from the spec.
234
-
235
- ### `generateToolsDetailed(spec)`
236
-
237
- Generates tools with additional metadata (operationId, path, method).
238
-
239
- ### `generatePrompts(spec)`
240
-
241
- Generates MCP prompt definitions from operations with `x-mcp-prompt`.
242
-
243
- ### `generateResources(spec)`
244
-
245
- Generates MCP resource definitions from operations with `x-mcp-resource`.
246
-
247
- ### `executeToolCall(spec, toolName, arguments, context?)`
248
-
249
- Executes a tool by name, passing the arguments and optional context. Returns the tool result.
250
-
251
- ### `buildMcpServer(options)`
252
-
253
- Builds an MCP server instance (transport-agnostic).
254
-
255
166
  ### `startStdioServer(options)`
256
167
 
257
- Starts a stdio MCP server. Blocks until the server is closed.
258
-
259
- ### `attachSseRoutes(app, specProvider, contextProvider?, routeGuard?)`
260
-
261
- Attaches MCP SSE routes to an Express-compatible app. This is the public API for HTTP transport.
262
-
263
- | Parameter | Type | Description |
264
- |---|---|---|
265
- | `app` | `Express` | Express app instance |
266
- | `specProvider` | `() => string \| object \| Promise<string \| object>` | Returns spec path, URL, or parsed document |
267
- | `contextProvider` | `(req) => Record<string, unknown> \| Promise<Record<string, unknown>>` | Optional. Returns per-request context |
268
- | `routeGuard` | `(req) => boolean \| Promise<boolean>` | Optional. Returns true if the request is authorized |
269
-
270
- ### `startAdminServer(options)`
271
-
272
- Starts an optional admin REST API server for health checks and diagnostics.
273
-
274
- ---
275
-
276
- ## Authentication
277
-
278
- ### Bearer token (HTTP)
168
+ Start an MCP server over stdio.
279
169
 
280
170
  ```typescript
281
- import { createAuthMiddleware } from "@powerduck/openapi-mcp-server";
282
-
283
- app.use("/mcp", createAuthMiddleware({
284
- type: "bearer",
285
- token: "your-secret-token",
286
- }));
287
- ```
288
-
289
- ### API key (HTTP)
171
+ import { startStdioServer } from "@powerduck/openapi-mcp-server";
290
172
 
291
- ```typescript
292
- app.use("/mcp", createAuthMiddleware({
293
- type: "apikey",
294
- token: "your-api-key",
295
- headerName: "x-api-key",
296
- }));
173
+ await startStdioServer({
174
+ specPath: "./openapi.json",
175
+ serverName: "My API",
176
+ serverVersion: "1.0.0",
177
+ securityValues: { bearerAuth: "token" },
178
+ toolFilter: { includeTags: ["users", "orders"] },
179
+ logLevel: "info",
180
+ });
297
181
  ```
298
182
 
299
- ### Custom auth
183
+ ### `attachSseRoutes(app, options)`
300
184
 
301
- Use the `routeGuard` parameter of `attachSseRoutes`:
185
+ Attach MCP SSE routes to an Express app.
302
186
 
303
187
  ```typescript
304
- attachSseRoutes(
305
- app,
306
- specProvider,
307
- contextProvider,
308
- (req) => {
309
- return verifyJwt(req.headers.authorization);
310
- },
311
- );
312
- ```
313
-
314
- ---
188
+ import express from "express";
189
+ import { attachSseRoutes } from "@powerduck/openapi-mcp-server";
315
190
 
316
- ## Context Injection
191
+ const app = express();
317
192
 
318
- Pass per-request context (user ID, tenant, etc.) to tool executions:
193
+ attachSseRoutes(app, {
194
+ specPath: "./openapi.json",
195
+ routePrefix: "/mcp",
196
+ serverName: "My API",
197
+ corsOrigin: "https://my-app.com",
198
+ });
319
199
 
320
- ```typescript
321
- attachSseRoutes(
322
- app,
323
- () => "./openapi.json",
324
- (req) => ({
325
- userId: req.headers["x-user-id"],
326
- tenantId: req.headers["x-tenant-id"],
327
- }),
328
- );
200
+ app.listen(3000);
329
201
  ```
330
202
 
331
- The context is available in tool execution and can be used for authorization or data scoping.
332
-
333
- ---
334
-
335
- ## Admin Server
203
+ ### `startAdminServer(options)`
336
204
 
337
- Enable the admin REST API with `--admin` or programmatically:
205
+ Start the admin dashboard server.
338
206
 
339
207
  ```typescript
340
208
  import { startAdminServer } from "@powerduck/openapi-mcp-server";
341
209
 
342
210
  await startAdminServer({
343
211
  port: 3001,
344
- specPath: "./openapi.json",
212
+ mcpServerUrl: "http://localhost:3000/mcp",
345
213
  });
346
214
  ```
347
215
 
348
- ### Endpoints
216
+ ### `createMcpServer(options)`
217
+
218
+ Create a low-level MCP server instance for custom integration.
349
219
 
350
- | Method | Path | Description |
351
- |---|---|---|
352
- | `GET` | `/health` | Health check |
353
- | `GET` | `/spec` | Current loaded spec info |
354
- | `POST` | `/reload` | Reload the spec from disk |
355
- | `GET` | `/tools` | List generated tools |
356
- | `GET` | `/prompts` | List generated prompts |
357
- | `GET` | `/resources` | List generated resources |
220
+ ```typescript
221
+ import { createMcpServer } from "@powerduck/openapi-mcp-server";
222
+
223
+ const server = createMcpServer({
224
+ spec: openApiDocument,
225
+ serverName: "My API",
226
+ securityValues: { bearerAuth: "token" },
227
+ });
228
+
229
+ // List tools
230
+ const tools = await server.listTools();
231
+
232
+ // Call a tool
233
+ const result = await server.callTool("getUser", { id: "123" });
234
+ ```
358
235
 
359
236
  ---
360
237
 
361
- ## MCP Client Configuration (Claude Desktop)
238
+ ## MCP Client Configuration
362
239
 
363
- Add to your `claude_desktop_config.json`:
240
+ ### Claude Desktop (stdio)
364
241
 
365
242
  ```json
366
243
  {
367
244
  "mcpServers": {
368
245
  "my-api": {
369
246
  "command": "npx",
370
- "args": ["@powerduck/openapi-mcp-server", "serve", "--spec", "/path/to/openapi.json"]
247
+ "args": [
248
+ "@powerduck/openapi-mcp-server",
249
+ "serve",
250
+ "--spec",
251
+ "./openapi.json"
252
+ ],
253
+ "env": {
254
+ "BEARER_TOKEN": "your-token"
255
+ }
371
256
  }
372
257
  }
373
258
  }
374
259
  ```
375
260
 
376
- For HTTP transport:
261
+ ### Cursor / VS Code (HTTP)
377
262
 
378
263
  ```json
379
264
  {
@@ -387,37 +272,24 @@ For HTTP transport:
387
272
 
388
273
  ---
389
274
 
390
- ## Development
391
-
392
- ```bash
393
- # Install dependencies
394
- npm install
275
+ ## TypeScript Types
395
276
 
396
- # Type check
397
- npm run typecheck
398
-
399
- # Build (ESM + CJS + type declarations)
400
- npm run build
401
-
402
- # Run tests
403
- npm test
404
-
405
- # Watch mode
406
- npx vitest watch
277
+ ```typescript
278
+ import type {
279
+ StdioServerOptions,
280
+ HttpServerOptions,
281
+ McpServerOptions,
282
+ ToolFilter,
283
+ SecurityValues,
284
+ McpTool,
285
+ McpPrompt,
286
+ McpResource,
287
+ ToolCallResult,
288
+ } from "@powerduck/openapi-mcp-server";
407
289
  ```
408
290
 
409
291
  ---
410
292
 
411
- ## Related Packages
412
-
413
- - [`@powerduck/openapi-parser`](https://www.npmjs.com/package/@powerduck/openapi-parser) — OpenAPI 3.2 parser, validator, and upgrader
414
- - [`@powerduck/openapi-request`](https://www.npmjs.com/package/@powerduck/openapi-request) — Execute OpenAPI operations with full parameter serialization
415
- - [`@powerduck/openapi-codegen`](https://www.npmjs.com/package/@powerduck/openapi-codegen) — Generate runnable request examples in 21 languages
416
- - [`@powerduck/openapi-cli`](https://www.npmjs.com/package/@powerduck/openapi-cli) — CI-ready batch testing for OpenAPI documents
417
- - [`@powerduck/x-to-openapi`](https://www.npmjs.com/package/@powerduck/x-to-openapi) — Convert curl commands and Postman Collections to OpenAPI 3.2
418
-
419
- ---
420
-
421
293
  ## License
422
294
 
423
- MIT
295
+ MIT © [POWERDUCK LIMITED](https://www.powerduck.com)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerduck/openapi-mcp-server",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "Production-oriented OpenAPI to MCP server library with Tools, Prompts, Resources, Web UI, and admin runtime.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",