@powerduck/openapi-mcp-server 1.0.1 → 1.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Powerduck limited
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,37 +1,31 @@
1
- A production-oriented TypeScript library and runtime that converts OpenAPI documents into MCP services.
1
+ # @powerduck/openapi-mcp-server
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.
2
4
 
3
5
  ## Features
4
6
 
5
- - Tools generated from OpenAPI operations
6
- - Prompts generated from API metadata and operations
7
- - Resources generated from the OpenAPI catalog
8
- - HTTP and STDIO MCP transports
9
- - Admin Web UI
10
- - Persistent runtime state
11
- - Stronger validation and safer request execution
12
- - Production-oriented structure for future SaaS evolution
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
13
17
 
14
18
  ## Install
15
19
 
16
20
  ```bash
17
- npm i @powerduck/openapi-mcp-server
18
- ```
19
-
20
- ## Start web runtime
21
-
22
- ```bash
23
- npm run start -- serve --port 3000 --host 127.0.0.1
21
+ npm install @powerduck/openapi-mcp-server
24
22
  ```
25
23
 
26
- ## Start STDIO runtime
27
-
28
- ```bash
29
- node dist/cli.js serve --transport stdio --spec ./openapi.yaml
30
- ```
24
+ ## Quick Start
31
25
 
32
- ## CLI usage
26
+ ### CLI Usage
33
27
 
34
- ### Web mode
28
+ #### Web Mode (with Admin UI)
35
29
 
36
30
  ```bash
37
31
  openapi-mcp serve \
@@ -41,7 +35,7 @@ openapi-mcp serve \
41
35
  --api-key your-admin-key
42
36
  ```
43
37
 
44
- ### STDIO mode
38
+ #### STDIO Mode
45
39
 
46
40
  ```bash
47
41
  openapi-mcp serve \
@@ -50,43 +44,235 @@ openapi-mcp serve \
50
44
  --base-url https://api.example.com
51
45
  ```
52
46
 
53
- ## Production notes
47
+ ### Programmatic API
48
+
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
+ );
62
+ ```
63
+
64
+ #### Generate MCP Tools
65
+
66
+ ```typescript
67
+ import { generateTools, buildBindingIndex } from "@powerduck/openapi-mcp-server";
68
+
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
74
+ ```
75
+
76
+ #### Generate Prompts and Resources
77
+
78
+ ```typescript
79
+ import { generatePrompts, generateResources } from "@powerduck/openapi-mcp-server";
80
+
81
+ const prompts = generatePrompts(spec);
82
+ const resources = generateResources(spec);
83
+ ```
84
+
85
+ #### Build an MCP Server
86
+
87
+ ```typescript
88
+ import { buildMcpServer, startStdioServer, attachSseRoutes } from "@powerduck/openapi-mcp-server";
89
+ import express from "express";
90
+
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" }),
95
+ });
96
+
97
+ // STDIO transport
98
+ await startStdioServer(server);
99
+
100
+ // HTTP/SSE transport
101
+ const app = express();
102
+ attachSseRoutes(app, server, { path: "/mcp" });
103
+ app.listen(3000);
104
+ ```
105
+
106
+ #### Execute Tool Calls
107
+
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
+ ```
119
+
120
+ #### Spec Utility Functions
121
+
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";
135
+
136
+ // Iterate all operations
137
+ for (const op of iterateOperations(spec)) {
138
+ console.log(op.method, op.path, op.operation?.operationId);
139
+ }
140
+
141
+ // Find operation by ID
142
+ const operation = findOperationById(spec, "getUser");
143
+
144
+ // Check for duplicate operation IDs
145
+ const duplicates = findDuplicateOperationIds(spec);
146
+
147
+ // Extract path variables
148
+ const vars = extractPathTemplateVariables("/users/{userId}/posts/{postId}");
149
+ // => ["userId", "postId"]
150
+ ```
151
+
152
+ #### Build HTTP Requests
54
153
 
55
- This version is production-oriented, but you should still add the following for SaaS deployment:
154
+ ```typescript
155
+ import { buildRequest } from "@powerduck/openapi-mcp-server";
56
156
 
57
- - tenant isolation
58
- - database-backed project registry
59
- - rate limits
60
- - audit logs
61
- - RBAC
62
- - secure secret storage
63
- - upstream host allowlists
64
- - comprehensive test suites
65
- - full OpenAPI parameter serialization coverage
66
- - full requestBody content negotiation support
157
+ const request = buildRequest({
158
+ operation,
159
+ pathItem,
160
+ arguments: { id: "123", include: ["profile", "posts"] },
161
+ baseUrl: "https://api.example.com",
162
+ });
67
163
 
68
- ## Project structure
164
+ // request contains: method, url, headers, body
165
+ ```
166
+
167
+ #### Admin Server and Auth
168
+
169
+ ```typescript
170
+ import { startAdminServer, createAuthMiddleware } from "@powerduck/openapi-mcp-server";
171
+
172
+ const app = await startAdminServer({
173
+ port: 3000,
174
+ host: "127.0.0.1",
175
+ apiKey: "your-admin-key",
176
+ });
69
177
 
70
- - `src/core`: spec parsing, operation traversal, tool generation, request building, execution
71
- - `src/mcp`: MCP server creation and transports
72
- - `src/registry`: prompts and resources registries
73
- - `src/runtime`: runtime service registry
74
- - `src/server`: admin HTTP server
75
- - `src/webui`: browser UI
76
- - `src/config`: persistence helpers
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" }));
182
+ ```
183
+
184
+ ## Project Structure
185
+
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
+ ```
77
215
 
78
216
  ## Web UI
79
217
 
80
- The UI supports:
218
+ The admin UI supports:
81
219
 
82
- - upload and paste OpenAPI documents
83
- - view tools, prompts, and resources
84
- - inspect runtime services
85
- - stop services
86
- - basic MCP debugging hints
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
87
225
  - SSE endpoint discovery
88
- - STDIO tooltip guidance
226
+ - STDIO configuration guidance
227
+
228
+ ## Testing
229
+
230
+ ```bash
231
+ # Run all tests
232
+ npm test
233
+
234
+ # Run tests in watch mode
235
+ npm run test:watch
236
+
237
+ # Run tests with coverage
238
+ npm run test:coverage
239
+ ```
240
+
241
+ Test coverage includes:
242
+
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
247
+
248
+ ## Production Notes
249
+
250
+ This version is production-oriented. For full SaaS deployment, consider adding:
251
+
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
259
+
260
+ ## Dependencies
261
+
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
271
+
272
+ ## License
273
+
274
+ MIT © Powerduck limited
89
275
 
90
- ## Important implementation policy
276
+ ## Important Implementation Policy
91
277
 
92
- All source comments are written in American English.
278
+ All source comments are written in American English. No Chinese characters are permitted in the codebase.
@@ -1,6 +1,6 @@
1
1
  import { Express } from 'express';
2
2
  import { Server } from 'node:http';
3
- import { Document } from '@scalar/openapi-types/3.2';
3
+ import { Oas32Document } from '@powerduck/openapi-parser';
4
4
  import { Prompt, PromptArgument, Resource, Tool } from '@modelcontextprotocol/sdk/types.js';
5
5
 
6
6
  /** How the MCP server is exposed to a client. */
@@ -96,7 +96,7 @@ interface SecurityContext {
96
96
  }
97
97
  /** Mutable runtime state of the loaded specification. */
98
98
  interface AppState {
99
- spec: Document | null;
99
+ spec: Oas32Document | null;
100
100
  baseUrlOverride?: string | undefined;
101
101
  specSource?: SpecSource | undefined;
102
102
  }
@@ -1,6 +1,6 @@
1
1
  import { Express } from 'express';
2
2
  import { Server } from 'node:http';
3
- import { Document } from '@scalar/openapi-types/3.2';
3
+ import { Oas32Document } from '@powerduck/openapi-parser';
4
4
  import { Prompt, PromptArgument, Resource, Tool } from '@modelcontextprotocol/sdk/types.js';
5
5
 
6
6
  /** How the MCP server is exposed to a client. */
@@ -96,7 +96,7 @@ interface SecurityContext {
96
96
  }
97
97
  /** Mutable runtime state of the loaded specification. */
98
98
  interface AppState {
99
- spec: Document | null;
99
+ spec: Oas32Document | null;
100
100
  baseUrlOverride?: string | undefined;
101
101
  specSource?: SpecSource | undefined;
102
102
  }