@powerduck/openapi-mcp-server 1.1.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 +221 -204
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,278 +1,295 @@
1
1
  # @powerduck/openapi-mcp-server
2
2
 
3
- A production-oriented TypeScript library and runtime that converts OpenAPI documents into MCP (Model Context Protocol) services. Built on top of `@powerduck/openapi-parser` for robust OpenAPI validation and dereferencing.
3
+ [![npm version](https://img.shields.io/npm/v/@powerduck/openapi-mcp-server)](https://www.npmjs.com/package/@powerduck/openapi-mcp-server)
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)
4
6
 
5
- ## Features
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.
6
8
 
7
- - **Tools** generated from OpenAPI operations with full parameter serialization
8
- - **Prompts** generated from API metadata and operations
9
- - **Resources** generated from the OpenAPI catalog
10
- - **HTTP (SSE)** and **STDIO** MCP transports
11
- - **Admin Web UI** for managing specs and services
12
- - **Persistent runtime state** with config storage
13
- - **Strong validation** and safer request execution
14
- - **Dual module support**: ESM and CommonJS
15
- - **TypeScript-first** with full type definitions
16
- - **91+ tests** covering core utilities, spec loading, and module exports
9
+ ---
17
10
 
18
- ## Install
11
+ Powerduck is an open-source developer tooling platform for teams building modern API workflows.
19
12
 
20
- ```bash
21
- npm install @powerduck/openapi-mcp-server
22
- ```
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
23
23
 
24
- ## Quick Start
24
+ ---
25
25
 
26
- ### CLI Usage
26
+ ## Quick Start
27
27
 
28
- #### Web Mode (with Admin UI)
28
+ ### Install
29
29
 
30
30
  ```bash
31
- openapi-mcp serve \
32
- --transport web \
33
- --port 3000 \
34
- --host 127.0.0.1 \
35
- --api-key your-admin-key
31
+ npm install @powerduck/openapi-mcp-server
36
32
  ```
37
33
 
38
- #### STDIO Mode
34
+ ### Run as a stdio server (CLI)
39
35
 
40
36
  ```bash
41
- openapi-mcp serve \
42
- --transport stdio \
43
- --spec ./openapi.yaml \
44
- --base-url https://api.example.com
37
+ npx @powerduck/openapi-mcp-server serve --spec ./openapi.json
45
38
  ```
46
39
 
47
- ### Programmatic API
40
+ ### Run as an HTTP server (CLI)
48
41
 
49
- #### Load and Validate an OpenAPI Document
50
-
51
- ```typescript
52
- import { loadOpenApiSpec, parseSpecContent } from "@powerduck/openapi-mcp-server";
53
-
54
- // Load from file (JSON or YAML)
55
- const spec = await loadOpenApiSpec("./openapi.yaml");
56
-
57
- // Parse from string content
58
- const specFromText = await parseSpecContent(
59
- '{"openapi": "3.1.0", "info": {...}, "paths": {...}}',
60
- false, // isYaml
61
- );
42
+ ```bash
43
+ npx @powerduck/openapi-mcp-server serve \
44
+ --spec ./openapi.json \
45
+ --transport http \
46
+ --port 3000 \
47
+ --route-prefix /mcp
62
48
  ```
63
49
 
64
- #### Generate MCP Tools
50
+ ### Programmatic stdio server
65
51
 
66
52
  ```typescript
67
- import { generateTools, buildBindingIndex } from "@powerduck/openapi-mcp-server";
53
+ import { startStdioServer } from "@powerduck/openapi-mcp-server";
68
54
 
69
- const tools = generateTools(spec);
70
- const bindingIndex = buildBindingIndex(spec);
71
-
72
- // tools is an array of MCP Tool definitions
73
- // bindingIndex maps operationIds to tool names
55
+ await startStdioServer({
56
+ specPath: "./openapi.json",
57
+ serverName: "My API MCP Server",
58
+ serverVersion: "1.0.0",
59
+ });
74
60
  ```
75
61
 
76
- #### Generate Prompts and Resources
62
+ ### Programmatic HTTP server (Express)
77
63
 
78
64
  ```typescript
79
- import { generatePrompts, generateResources } from "@powerduck/openapi-mcp-server";
80
-
81
- const prompts = generatePrompts(spec);
82
- const resources = generateResources(spec);
83
- ```
65
+ import express from "express";
66
+ import { attachSseRoutes } from "@powerduck/openapi-mcp-server";
84
67
 
85
- #### Build an MCP Server
68
+ const app = express();
86
69
 
87
- ```typescript
88
- import { buildMcpServer, startStdioServer, attachSseRoutes } from "@powerduck/openapi-mcp-server";
89
- import express from "express";
70
+ attachSseRoutes(app, {
71
+ specPath: "./openapi.json",
72
+ routePrefix: "/mcp",
73
+ serverName: "My API MCP Server",
74
+ });
90
75
 
91
- // Build a server with custom spec and context providers
92
- const server = buildMcpServer({
93
- specProvider: async () => spec,
94
- contextProvider: async () => ({ baseUrl: "https://api.example.com" }),
76
+ app.listen(3000, () => {
77
+ console.log("MCP server running at http://localhost:3000/mcp");
95
78
  });
79
+ ```
96
80
 
97
- // STDIO transport
98
- await startStdioServer(server);
81
+ ---
99
82
 
100
- // HTTP/SSE transport
101
- const app = express();
102
- attachSseRoutes(app, server, { path: "/mcp" });
103
- app.listen(3000);
104
- ```
83
+ ## Links
105
84
 
106
- #### Execute Tool Calls
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)
107
89
 
108
- ```typescript
109
- import { executeToolCall } from "@powerduck/openapi-mcp-server";
110
-
111
- const result = await executeToolCall({
112
- toolName: "get_user",
113
- arguments: { id: "123" },
114
- spec,
115
- baseUrl: "https://api.example.com",
116
- headers: { Authorization: "Bearer token" },
117
- });
118
- ```
90
+ ---
119
91
 
120
- #### Spec Utility Functions
92
+ ## Features
121
93
 
122
- ```typescript
123
- import {
124
- iterateOperations,
125
- findOperationById,
126
- findDuplicateOperationIds,
127
- assertUniqueOperationIds,
128
- extractPathTemplateVariables,
129
- synthesizeOperationId,
130
- ensureUniqueName,
131
- collectOperationParameters,
132
- effectiveStyle,
133
- effectiveExplode,
134
- } from "@powerduck/openapi-mcp-server";
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
110
+
111
+ ---
112
+
113
+ ## CLI Reference
114
+
115
+ ### Commands
135
116
 
136
- // Iterate all operations
137
- for (const op of iterateOperations(spec)) {
138
- console.log(op.method, op.path, op.operation?.operationId);
139
- }
117
+ ```bash
118
+ openapi-mcp-server serve [options]
140
119
 
141
- // Find operation by ID
142
- const operation = findOperationById(spec, "getUser");
120
+ # Stdio server (default)
121
+ openapi-mcp-server serve --spec ./openapi.json
143
122
 
144
- // Check for duplicate operation IDs
145
- const duplicates = findDuplicateOperationIds(spec);
123
+ # HTTP/SSE server
124
+ openapi-mcp-server serve --spec ./openapi.json --transport http --port 3000
146
125
 
147
- // Extract path variables
148
- const vars = extractPathTemplateVariables("/users/{userId}/posts/{postId}");
149
- // => ["userId", "postId"]
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
150
134
  ```
151
135
 
152
- #### Build HTTP Requests
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 |
161
+
162
+ ---
163
+
164
+ ## Programmatic API
165
+
166
+ ### `startStdioServer(options)`
167
+
168
+ Start an MCP server over stdio.
153
169
 
154
170
  ```typescript
155
- import { buildRequest } from "@powerduck/openapi-mcp-server";
156
-
157
- const request = buildRequest({
158
- operation,
159
- pathItem,
160
- arguments: { id: "123", include: ["profile", "posts"] },
161
- baseUrl: "https://api.example.com",
171
+ import { startStdioServer } from "@powerduck/openapi-mcp-server";
172
+
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",
162
180
  });
163
-
164
- // request contains: method, url, headers, body
165
181
  ```
166
182
 
167
- #### Admin Server and Auth
183
+ ### `attachSseRoutes(app, options)`
184
+
185
+ Attach MCP SSE routes to an Express app.
168
186
 
169
187
  ```typescript
170
- import { startAdminServer, createAuthMiddleware } from "@powerduck/openapi-mcp-server";
188
+ import express from "express";
189
+ import { attachSseRoutes } from "@powerduck/openapi-mcp-server";
190
+
191
+ const app = express();
171
192
 
172
- const app = await startAdminServer({
173
- port: 3000,
174
- host: "127.0.0.1",
175
- apiKey: "your-admin-key",
193
+ attachSseRoutes(app, {
194
+ specPath: "./openapi.json",
195
+ routePrefix: "/mcp",
196
+ serverName: "My API",
197
+ corsOrigin: "https://my-app.com",
176
198
  });
177
199
 
178
- // Or use auth middleware in your own Express app
179
- import express from "express";
180
- const myApp = express();
181
- myApp.use("/admin", createAuthMiddleware({ apiKey: "secret" }));
200
+ app.listen(3000);
182
201
  ```
183
202
 
184
- ## Project Structure
203
+ ### `startAdminServer(options)`
185
204
 
186
- ```
187
- src/
188
- ├── core/
189
- │ ├── openapi-loader.ts # Spec loading, validation, dereferencing
190
- │ ├── spec-utils.ts # Operation traversal, parameter normalization
191
- │ ├── tool-generator.ts # MCP tool generation from operations
192
- │ ├── request-builder.ts # HTTP request construction with serialization
193
- │ ├── http-executor.ts # Safe HTTP request execution
194
- │ └── global-utils.ts # Shared utilities (IDs, error detection)
195
- ├── mcp/
196
- │ ├── create-server.ts # MCP server construction
197
- │ ├── transport-stdio.ts # STDIO transport
198
- │ └── transport-http.ts # HTTP/SSE transport
199
- ├── registry/
200
- │ ├── prompt-registry.ts # Prompt generation and resolution
201
- │ └── resource-registry.ts # Resource generation and reading
202
- ├── runtime/
203
- │ └── service-registry.ts # Runtime service management
204
- ├── server/
205
- │ ├── admin-server.ts # Admin HTTP server with Web UI
206
- │ └── auth.ts # Authentication middleware
207
- ├── config/
208
- │ └── config-store.ts # Persistent configuration storage
209
- ├── webui/
210
- │ └── index.html # Admin Web UI
211
- ├── types.ts # Shared TypeScript types
212
- ├── cli.ts # CLI entry point
213
- └── index.ts # Library exports
214
- ```
205
+ Start the admin dashboard server.
215
206
 
216
- ## Web UI
207
+ ```typescript
208
+ import { startAdminServer } from "@powerduck/openapi-mcp-server";
217
209
 
218
- The admin UI supports:
210
+ await startAdminServer({
211
+ port: 3001,
212
+ mcpServerUrl: "http://localhost:3000/mcp",
213
+ });
214
+ ```
219
215
 
220
- - Upload and paste OpenAPI documents (JSON or YAML)
221
- - View generated tools, prompts, and resources
222
- - Inspect running runtime services
223
- - Stop services
224
- - Basic MCP debugging hints
225
- - SSE endpoint discovery
226
- - STDIO configuration guidance
216
+ ### `createMcpServer(options)`
227
217
 
228
- ## Testing
218
+ Create a low-level MCP server instance for custom integration.
229
219
 
230
- ```bash
231
- # Run all tests
232
- npm test
220
+ ```typescript
221
+ import { createMcpServer } from "@powerduck/openapi-mcp-server";
233
222
 
234
- # Run tests in watch mode
235
- npm run test:watch
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();
236
231
 
237
- # Run tests with coverage
238
- npm run test:coverage
232
+ // Call a tool
233
+ const result = await server.callTool("getUser", { id: "123" });
239
234
  ```
240
235
 
241
- Test coverage includes:
236
+ ---
237
+
238
+ ## MCP Client Configuration
239
+
240
+ ### Claude Desktop (stdio)
241
+
242
+ ```json
243
+ {
244
+ "mcpServers": {
245
+ "my-api": {
246
+ "command": "npx",
247
+ "args": [
248
+ "@powerduck/openapi-mcp-server",
249
+ "serve",
250
+ "--spec",
251
+ "./openapi.json"
252
+ ],
253
+ "env": {
254
+ "BEARER_TOKEN": "your-token"
255
+ }
256
+ }
257
+ }
258
+ }
259
+ ```
242
260
 
243
- - **Global utilities**: ID generation, abort error detection
244
- - **Spec utilities**: operation iteration, parameter normalization, name uniqueness
245
- - **OpenAPI loader**: JSON/YAML parsing, validation, dereferencing, error handling
246
- - **Module exports**: all public API surface verification
261
+ ### Cursor / VS Code (HTTP)
247
262
 
248
- ## Production Notes
263
+ ```json
264
+ {
265
+ "mcpServers": {
266
+ "my-api": {
267
+ "url": "http://localhost:3000/mcp"
268
+ }
269
+ }
270
+ }
271
+ ```
249
272
 
250
- This version is production-oriented. For full SaaS deployment, consider adding:
273
+ ---
251
274
 
252
- - Tenant isolation
253
- - Database-backed project registry
254
- - Rate limits
255
- - Audit logs
256
- - Role-based access control (RBAC)
257
- - Secure secret storage
258
- - Upstream host allowlists
275
+ ## TypeScript Types
259
276
 
260
- ## Dependencies
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";
289
+ ```
261
290
 
262
- - `@powerduck/openapi-parser` — OpenAPI validation, dereferencing, and upgrade (replaces `@scalar/openapi-parser`)
263
- - `@modelcontextprotocol/sdk` — MCP protocol implementation
264
- - `express` — HTTP server for admin UI and SSE transport
265
- - `axios` — HTTP client for tool execution
266
- - `commander` — CLI framework
267
- - `js-yaml` — YAML parsing
268
- - `multer` — File upload handling
269
- - `cors` — CORS middleware
270
- - `terser` — Minification for embedded assets
291
+ ---
271
292
 
272
293
  ## License
273
294
 
274
- MIT © Powerduck limited
275
-
276
- ## Important Implementation Policy
277
-
278
- All source comments are written in American English. No Chinese characters are permitted in the codebase.
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.1.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",