mcp-openapi 0.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.
Files changed (114) hide show
  1. package/README.md +351 -0
  2. package/dist/bin/mcp-openapi.d.ts +3 -0
  3. package/dist/bin/mcp-openapi.d.ts.map +1 -0
  4. package/dist/bin/mcp-openapi.js +26 -0
  5. package/dist/bin/mcp-openapi.js.map +1 -0
  6. package/dist/src/auth/api-key.d.ts +10 -0
  7. package/dist/src/auth/api-key.d.ts.map +1 -0
  8. package/dist/src/auth/api-key.js +23 -0
  9. package/dist/src/auth/api-key.js.map +1 -0
  10. package/dist/src/auth/auth-manager.d.ts +4 -0
  11. package/dist/src/auth/auth-manager.d.ts.map +1 -0
  12. package/dist/src/auth/auth-manager.js +36 -0
  13. package/dist/src/auth/auth-manager.js.map +1 -0
  14. package/dist/src/auth/bearer.d.ts +8 -0
  15. package/dist/src/auth/bearer.d.ts.map +1 -0
  16. package/dist/src/auth/bearer.js +16 -0
  17. package/dist/src/auth/bearer.js.map +1 -0
  18. package/dist/src/auth/index.d.ts +3 -0
  19. package/dist/src/auth/index.d.ts.map +1 -0
  20. package/dist/src/auth/index.js +2 -0
  21. package/dist/src/auth/index.js.map +1 -0
  22. package/dist/src/auth/oauth2.d.ts +14 -0
  23. package/dist/src/auth/oauth2.d.ts.map +1 -0
  24. package/dist/src/auth/oauth2.js +59 -0
  25. package/dist/src/auth/oauth2.js.map +1 -0
  26. package/dist/src/auth/types.d.ts +5 -0
  27. package/dist/src/auth/types.d.ts.map +1 -0
  28. package/dist/src/auth/types.js +2 -0
  29. package/dist/src/auth/types.js.map +1 -0
  30. package/dist/src/config/cli-args.d.ts +5 -0
  31. package/dist/src/config/cli-args.d.ts.map +1 -0
  32. package/dist/src/config/cli-args.js +154 -0
  33. package/dist/src/config/cli-args.js.map +1 -0
  34. package/dist/src/config/index.d.ts +4 -0
  35. package/dist/src/config/index.d.ts.map +1 -0
  36. package/dist/src/config/index.js +3 -0
  37. package/dist/src/config/index.js.map +1 -0
  38. package/dist/src/config/types.d.ts +46 -0
  39. package/dist/src/config/types.d.ts.map +1 -0
  40. package/dist/src/config/types.js +7 -0
  41. package/dist/src/config/types.js.map +1 -0
  42. package/dist/src/executor/http-client.d.ts +14 -0
  43. package/dist/src/executor/http-client.d.ts.map +1 -0
  44. package/dist/src/executor/http-client.js +59 -0
  45. package/dist/src/executor/http-client.js.map +1 -0
  46. package/dist/src/executor/index.d.ts +7 -0
  47. package/dist/src/executor/index.d.ts.map +1 -0
  48. package/dist/src/executor/index.js +4 -0
  49. package/dist/src/executor/index.js.map +1 -0
  50. package/dist/src/executor/request-builder.d.ts +15 -0
  51. package/dist/src/executor/request-builder.d.ts.map +1 -0
  52. package/dist/src/executor/request-builder.js +60 -0
  53. package/dist/src/executor/request-builder.js.map +1 -0
  54. package/dist/src/executor/response-mapper.d.ts +10 -0
  55. package/dist/src/executor/response-mapper.d.ts.map +1 -0
  56. package/dist/src/executor/response-mapper.js +54 -0
  57. package/dist/src/executor/response-mapper.js.map +1 -0
  58. package/dist/src/executor/types.d.ts +8 -0
  59. package/dist/src/executor/types.d.ts.map +1 -0
  60. package/dist/src/executor/types.js +2 -0
  61. package/dist/src/executor/types.js.map +1 -0
  62. package/dist/src/generator/index.d.ts +6 -0
  63. package/dist/src/generator/index.d.ts.map +1 -0
  64. package/dist/src/generator/index.js +4 -0
  65. package/dist/src/generator/index.js.map +1 -0
  66. package/dist/src/generator/param-builder.d.ts +17 -0
  67. package/dist/src/generator/param-builder.d.ts.map +1 -0
  68. package/dist/src/generator/param-builder.js +110 -0
  69. package/dist/src/generator/param-builder.js.map +1 -0
  70. package/dist/src/generator/tool-generator.d.ts +22 -0
  71. package/dist/src/generator/tool-generator.d.ts.map +1 -0
  72. package/dist/src/generator/tool-generator.js +66 -0
  73. package/dist/src/generator/tool-generator.js.map +1 -0
  74. package/dist/src/generator/tool-namer.d.ts +10 -0
  75. package/dist/src/generator/tool-namer.d.ts.map +1 -0
  76. package/dist/src/generator/tool-namer.js +44 -0
  77. package/dist/src/generator/tool-namer.js.map +1 -0
  78. package/dist/src/index.d.ts +7 -0
  79. package/dist/src/index.d.ts.map +1 -0
  80. package/dist/src/index.js +4 -0
  81. package/dist/src/index.js.map +1 -0
  82. package/dist/src/parser/index.d.ts +5 -0
  83. package/dist/src/parser/index.d.ts.map +1 -0
  84. package/dist/src/parser/index.js +4 -0
  85. package/dist/src/parser/index.js.map +1 -0
  86. package/dist/src/parser/openapi-parser.d.ts +3 -0
  87. package/dist/src/parser/openapi-parser.d.ts.map +1 -0
  88. package/dist/src/parser/openapi-parser.js +287 -0
  89. package/dist/src/parser/openapi-parser.js.map +1 -0
  90. package/dist/src/parser/schema-converter.d.ts +7 -0
  91. package/dist/src/parser/schema-converter.d.ts.map +1 -0
  92. package/dist/src/parser/schema-converter.js +86 -0
  93. package/dist/src/parser/schema-converter.js.map +1 -0
  94. package/dist/src/parser/spec-loader.d.ts +6 -0
  95. package/dist/src/parser/spec-loader.d.ts.map +1 -0
  96. package/dist/src/parser/spec-loader.js +53 -0
  97. package/dist/src/parser/spec-loader.js.map +1 -0
  98. package/dist/src/parser/types.d.ts +72 -0
  99. package/dist/src/parser/types.d.ts.map +1 -0
  100. package/dist/src/parser/types.js +2 -0
  101. package/dist/src/parser/types.js.map +1 -0
  102. package/dist/src/server.d.ts +9 -0
  103. package/dist/src/server.d.ts.map +1 -0
  104. package/dist/src/server.js +61 -0
  105. package/dist/src/server.js.map +1 -0
  106. package/dist/src/utils/errors.d.ts +19 -0
  107. package/dist/src/utils/errors.d.ts.map +1 -0
  108. package/dist/src/utils/errors.js +37 -0
  109. package/dist/src/utils/errors.js.map +1 -0
  110. package/dist/src/utils/logger.d.ts +8 -0
  111. package/dist/src/utils/logger.d.ts.map +1 -0
  112. package/dist/src/utils/logger.js +12 -0
  113. package/dist/src/utils/logger.js.map +1 -0
  114. package/package.json +54 -0
package/README.md ADDED
@@ -0,0 +1,351 @@
1
+ # mcp-openapi
2
+
3
+ > Turn any OpenAPI/Swagger spec into MCP tools — so Claude and other AI assistants can call your REST APIs.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/mcp-openapi.svg)](https://www.npmjs.com/package/mcp-openapi)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
7
+ [![npm downloads](https://img.shields.io/npm/dm/mcp-openapi.svg)](https://www.npmjs.com/package/mcp-openapi)
8
+
9
+ Point `mcp-openapi` at any OpenAPI 3.x or Swagger 2.0 spec URL and it generates [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) tools automatically. No code generation, no config files, no boilerplate. Your AI assistant gets callable tools for every API endpoint in seconds.
10
+
11
+ ---
12
+
13
+ ## Quick Start
14
+
15
+ **1. Run it** (no install required):
16
+
17
+ ```bash
18
+ npx mcp-openapi --spec https://petstore3.swagger.io/api/v3/openapi.json
19
+ ```
20
+
21
+ **2. Add it to Claude Desktop** (`claude_desktop_config.json`):
22
+
23
+ ```json
24
+ {
25
+ "mcpServers": {
26
+ "petstore": {
27
+ "command": "npx",
28
+ "args": [
29
+ "mcp-openapi",
30
+ "--spec", "https://petstore3.swagger.io/api/v3/openapi.json"
31
+ ]
32
+ }
33
+ }
34
+ }
35
+ ```
36
+
37
+ **3. Ask Claude to use it:**
38
+
39
+ > "List all available pets in the store"
40
+
41
+ Claude sees MCP tools like `find_pets_by_status`, `get_pet_by_id`, `add_pet` and calls them directly.
42
+
43
+ ---
44
+
45
+ ## Why mcp-openapi?
46
+
47
+ Most MCP-to-API bridges require you to write tool definitions by hand or generate code from a spec. `mcp-openapi` skips all of that.
48
+
49
+ | Feature | mcp-openapi | Hand-written MCP servers | Generic HTTP tools |
50
+ |---------|:-----------:|:------------------------:|:------------------:|
51
+ | Zero config setup | Yes | No | Partial |
52
+ | OpenAPI 3.x + Swagger 2.0 | Yes | N/A | N/A |
53
+ | Flat parameter schemas (LLM-optimized) | Yes | Manual | No |
54
+ | Smart tool naming from operationId | Yes | Manual | No |
55
+ | Auth (API key, Bearer, OAuth2) | Built-in | DIY | DIY |
56
+ | Retry with exponential backoff | Built-in | DIY | DIY |
57
+ | Response truncation for LLM context | Built-in | DIY | No |
58
+
59
+ **Flat parameter schemas** are the key differentiator. Instead of passing nested JSON objects (which LLMs frequently get wrong), `mcp-openapi` flattens path, query, header, and body parameters into a single flat object. This dramatically improves tool-calling accuracy.
60
+
61
+ ---
62
+
63
+ ## How It Works
64
+
65
+ ```
66
+ OpenAPI/Swagger Spec mcp-openapi AI Assistant
67
+ (URL or file) (Claude, etc.)
68
+ | | |
69
+ | 1. Parse & validate | |
70
+ |------------------------>| |
71
+ | | |
72
+ | 2. Generate MCP tools | |
73
+ | (one per endpoint) | |
74
+ |------------------------>| |
75
+ | | |
76
+ | | 3. Register tools |
77
+ | | via stdio transport |
78
+ | |------------------------>|
79
+ | | |
80
+ | | 4. AI calls a tool |
81
+ | |<------------------------|
82
+ | | |
83
+ | 5. Build & execute | |
84
+ | HTTP request | |
85
+ |<------------------------| |
86
+ | | |
87
+ | 6. Return truncated | |
88
+ | response to AI | |
89
+ |------------------------>|------------------------>|
90
+ ```
91
+
92
+ Each API endpoint becomes one MCP tool:
93
+ - **Tool name** is derived from `operationId` (converted to `snake_case`) or from `method + path`
94
+ - **Parameters** are flattened into a single input schema (path, query, header, and body params merged)
95
+ - **Responses** are truncated to ~50KB to stay within LLM context limits
96
+ - **Errors** (429, 5xx) trigger automatic retries with exponential backoff (up to 3 retries)
97
+
98
+ ---
99
+
100
+ ## Claude Desktop Integration
101
+
102
+ Add any API to Claude Desktop by editing your config file:
103
+
104
+ **Location:**
105
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
106
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
107
+
108
+ ### Public API (no auth)
109
+
110
+ ```json
111
+ {
112
+ "mcpServers": {
113
+ "petstore": {
114
+ "command": "npx",
115
+ "args": [
116
+ "mcp-openapi",
117
+ "--spec", "https://petstore3.swagger.io/api/v3/openapi.json"
118
+ ]
119
+ }
120
+ }
121
+ }
122
+ ```
123
+
124
+ ### API with Bearer Token
125
+
126
+ ```json
127
+ {
128
+ "mcpServers": {
129
+ "github": {
130
+ "command": "npx",
131
+ "args": [
132
+ "mcp-openapi",
133
+ "--spec", "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json",
134
+ "--auth-type", "bearer",
135
+ "--auth-token", "$GITHUB_TOKEN",
136
+ "--prefix", "github",
137
+ "--include", "listReposForAuthenticatedUser,getRepo,listIssues,createIssue"
138
+ ],
139
+ "env": {
140
+ "GITHUB_TOKEN": "ghp_your_token_here"
141
+ }
142
+ }
143
+ }
144
+ }
145
+ ```
146
+
147
+ ### API with API Key
148
+
149
+ ```json
150
+ {
151
+ "mcpServers": {
152
+ "weather": {
153
+ "command": "npx",
154
+ "args": [
155
+ "mcp-openapi",
156
+ "--spec", "https://api.weather.example.com/openapi.json",
157
+ "--auth-type", "api-key",
158
+ "--auth-name", "X-API-Key",
159
+ "--auth-value", "$WEATHER_API_KEY",
160
+ "--auth-in", "header"
161
+ ],
162
+ "env": {
163
+ "WEATHER_API_KEY": "your_key_here"
164
+ }
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ ---
171
+
172
+ ## CLI Reference
173
+
174
+ ```bash
175
+ npx mcp-openapi --spec <url-or-path> [options]
176
+ ```
177
+
178
+ ### General Options
179
+
180
+ | Option | Short | Default | Description |
181
+ |--------|-------|---------|-------------|
182
+ | `--spec <url\|path>` | `-s` | *required* | OpenAPI spec URL or local file path |
183
+ | `--config <path>` | `-c` | | JSON config file path |
184
+ | `--base-url <url>` | | from spec | Override the API base URL |
185
+ | `--prefix <name>` | | | Prefix for all tool names (e.g. `github` -> `github_list_repos`) |
186
+ | `--include <patterns>` | | all | Comma-separated operationIds to include |
187
+ | `--exclude <patterns>` | | none | Comma-separated operationIds to exclude |
188
+ | `--timeout <ms>` | | `30000` | HTTP request timeout in milliseconds |
189
+ | `--max-retries <n>` | | `3` | Max retries on 429/5xx responses |
190
+ | `--header <name:value>` | `-H` | | Custom header (repeatable) |
191
+ | `--transport <type>` | | `stdio` | Transport type: `stdio` or `sse` |
192
+ | `--port <n>` | | `3000` | Port for SSE transport |
193
+ | `--help` | `-h` | | Show help |
194
+ | `--version` | `-v` | | Show version |
195
+
196
+ ### Auth Options
197
+
198
+ **Bearer token:**
199
+
200
+ | Option | Description |
201
+ |--------|-------------|
202
+ | `--auth-type bearer` | Use Bearer token authentication |
203
+ | `--auth-token <token>` | The token value (supports `$ENV_VAR` syntax) |
204
+
205
+ **API key:**
206
+
207
+ | Option | Description |
208
+ |--------|-------------|
209
+ | `--auth-type api-key` | Use API key authentication |
210
+ | `--auth-name <name>` | Header or query parameter name |
211
+ | `--auth-value <value>` | The API key value (supports `$ENV_VAR` syntax) |
212
+ | `--auth-in <header\|query>` | Where to send the key (default: `header`) |
213
+
214
+ **OAuth2 client credentials:**
215
+
216
+ | Option | Description |
217
+ |--------|-------------|
218
+ | `--auth-type oauth2` | Use OAuth2 client credentials flow |
219
+ | `--auth-client-id <id>` | OAuth2 client ID |
220
+ | `--auth-client-secret <secret>` | OAuth2 client secret |
221
+ | `--auth-token-url <url>` | Token endpoint URL |
222
+ | `--auth-scopes <scopes>` | Comma-separated scopes |
223
+
224
+ ---
225
+
226
+ ## CLI Examples
227
+
228
+ ```bash
229
+ # Basic usage with a remote spec
230
+ npx mcp-openapi --spec https://petstore3.swagger.io/api/v3/openapi.json
231
+
232
+ # Local YAML spec with Bearer auth
233
+ npx mcp-openapi --spec ./api.yaml --auth-type bearer --auth-token '$API_KEY'
234
+
235
+ # Filter to specific endpoints with a prefix
236
+ npx mcp-openapi --spec ./api.json --prefix myapi --include 'listUsers,getUser'
237
+
238
+ # Override base URL (useful for local dev)
239
+ npx mcp-openapi --spec https://api.example.com/openapi.json --base-url http://localhost:3000
240
+
241
+ # Add custom headers
242
+ npx mcp-openapi --spec ./api.json -H 'X-Custom: value' -H 'X-Another: value2'
243
+
244
+ # Use a JSON config file
245
+ npx mcp-openapi --config ./mcp-config.json
246
+ ```
247
+
248
+ ### Config File Format
249
+
250
+ Instead of CLI flags, you can use a JSON config file:
251
+
252
+ ```json
253
+ {
254
+ "spec": "https://api.example.com/openapi.json",
255
+ "prefix": "myapi",
256
+ "include": ["listUsers", "getUser", "createUser"],
257
+ "auth": {
258
+ "type": "bearer",
259
+ "token": "$API_TOKEN"
260
+ },
261
+ "timeout": 15000,
262
+ "maxRetries": 2,
263
+ "headers": {
264
+ "X-Custom-Header": "value"
265
+ }
266
+ }
267
+ ```
268
+
269
+ CLI arguments take precedence over config file values.
270
+
271
+ ---
272
+
273
+ ## Supported Specs
274
+
275
+ | Format | Versions | File types |
276
+ |--------|----------|------------|
277
+ | OpenAPI | 3.0.x, 3.1.x | `.json`, `.yaml`, `.yml` |
278
+ | Swagger | 2.0 | `.json`, `.yaml`, `.yml` |
279
+
280
+ Specs can be loaded from:
281
+ - Remote URLs (`https://...`)
282
+ - Local file paths (`./api.yaml`, `/absolute/path/spec.json`)
283
+
284
+ ---
285
+
286
+ ## Programmatic Usage
287
+
288
+ You can also use `mcp-openapi` as a library in your own MCP server:
289
+
290
+ ```typescript
291
+ import { createServer } from 'mcp-openapi';
292
+
293
+ const { server, tools, spec } = await createServer({
294
+ spec: 'https://petstore3.swagger.io/api/v3/openapi.json',
295
+ prefix: 'petstore',
296
+ auth: {
297
+ type: 'bearer',
298
+ token: process.env.API_TOKEN,
299
+ },
300
+ });
301
+
302
+ console.log(`Loaded ${tools.length} tools from ${spec.info.title}`);
303
+ ```
304
+
305
+ ---
306
+
307
+ ## Requirements
308
+
309
+ - Node.js 18 or later
310
+ - An OpenAPI 3.x or Swagger 2.0 spec (URL or local file)
311
+
312
+ ---
313
+
314
+ ## Contributing
315
+
316
+ Contributions are welcome. Here is how to get started:
317
+
318
+ ```bash
319
+ # Clone the repo
320
+ git clone https://github.com/Docat0209/auto-revenue.git
321
+ cd auto-revenue
322
+
323
+ # Install dependencies
324
+ pnpm install
325
+
326
+ # Navigate to the package
327
+ cd packages/mcp-servers/openapi
328
+
329
+ # Run tests
330
+ pnpm test
331
+
332
+ # Build
333
+ pnpm build
334
+ ```
335
+
336
+ Before submitting a PR:
337
+ 1. Add tests for new features
338
+ 2. Run `pnpm lint` and fix any issues
339
+ 3. Follow [Conventional Commits](https://www.conventionalcommits.org/) for commit messages
340
+
341
+ ---
342
+
343
+ ## License
344
+
345
+ MIT
346
+
347
+ ---
348
+
349
+ ## Keywords
350
+
351
+ mcp, model-context-protocol, openapi, swagger, claude, ai, llm, api, tools, rest-api, ai-tools, mcp-server
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=mcp-openapi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-openapi.d.ts","sourceRoot":"","sources":["../../bin/mcp-openapi.ts"],"names":[],"mappings":""}
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ import { parseCliArgs, loadConfigFile, mergeConfigs } from "../src/config/cli-args.js";
3
+ import { startServer } from "../src/server.js";
4
+ import { logger } from "../src/utils/logger.js";
5
+ async function main() {
6
+ try {
7
+ let config = parseCliArgs(process.argv);
8
+ // Load config file if specified
9
+ const configWithExtra = config;
10
+ if (configWithExtra.config) {
11
+ const fileConfig = await loadConfigFile(configWithExtra.config);
12
+ config = mergeConfigs(fileConfig, config);
13
+ }
14
+ if (!config.spec) {
15
+ logger.error("Missing required --spec argument. Use --help for usage.");
16
+ process.exit(1);
17
+ }
18
+ await startServer(config);
19
+ }
20
+ catch (error) {
21
+ logger.error(error instanceof Error ? error.message : String(error));
22
+ process.exit(1);
23
+ }
24
+ }
25
+ main();
26
+ //# sourceMappingURL=mcp-openapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-openapi.js","sourceRoot":"","sources":["../../bin/mcp-openapi.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEvF,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAEhD,KAAK,UAAU,IAAI;IAClB,IAAI,CAAC;QACJ,IAAI,MAAM,GAAG,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAExC,gCAAgC;QAChC,MAAM,eAAe,GAAG,MAAgD,CAAC;QACzE,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;YAC5B,MAAM,UAAU,GAAG,MAAM,cAAc,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAChE,MAAM,GAAG,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAC3C,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YAClB,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;YACxE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;QAED,MAAM,WAAW,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,CAAC,KAAK,CACX,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACtD,CAAC;QACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC;AACF,CAAC;AAED,IAAI,EAAE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { PreparedRequest } from "../executor/types.js";
2
+ import type { AuthProvider } from "./types.js";
3
+ export declare class ApiKeyAuth implements AuthProvider {
4
+ private readonly name;
5
+ private readonly value;
6
+ private readonly location;
7
+ constructor(name: string, value: string, location: "header" | "query");
8
+ apply(request: PreparedRequest): Promise<PreparedRequest>;
9
+ }
10
+ //# sourceMappingURL=api-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key.d.ts","sourceRoot":"","sources":["../../../src/auth/api-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,qBAAa,UAAW,YAAW,YAAY;IAE7C,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAFR,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,QAAQ,GAAG,OAAO;IAGxC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;CAY/D"}
@@ -0,0 +1,23 @@
1
+ export class ApiKeyAuth {
2
+ name;
3
+ value;
4
+ location;
5
+ constructor(name, value, location) {
6
+ this.name = name;
7
+ this.value = value;
8
+ this.location = location;
9
+ }
10
+ async apply(request) {
11
+ if (this.location === "header") {
12
+ return {
13
+ ...request,
14
+ headers: { ...request.headers, [this.name]: this.value },
15
+ };
16
+ }
17
+ return {
18
+ ...request,
19
+ query: { ...request.query, [this.name]: this.value },
20
+ };
21
+ }
22
+ }
23
+ //# sourceMappingURL=api-key.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-key.js","sourceRoot":"","sources":["../../../src/auth/api-key.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,UAAU;IAEJ;IACA;IACA;IAHlB,YACkB,IAAY,EACZ,KAAa,EACb,QAA4B;QAF5B,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;QACb,aAAQ,GAAR,QAAQ,CAAoB;IAC3C,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,OAAwB;QACnC,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO;gBACN,GAAG,OAAO;gBACV,OAAO,EAAE,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE;aACxD,CAAC;QACH,CAAC;QACD,OAAO;YACN,GAAG,OAAO;YACV,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,KAAK,EAAE;SACpD,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,4 @@
1
+ import type { AuthConfig } from "../config/types.js";
2
+ import type { AuthProvider } from "./types.js";
3
+ export declare function createAuthProvider(config?: AuthConfig): AuthProvider | null;
4
+ //# sourceMappingURL=auth-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-manager.d.ts","sourceRoot":"","sources":["../../../src/auth/auth-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAmB/C,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,YAAY,GAAG,IAAI,CAmB3E"}
@@ -0,0 +1,36 @@
1
+ import { logger } from "../utils/logger.js";
2
+ import { ApiKeyAuth } from "./api-key.js";
3
+ import { BearerAuth } from "./bearer.js";
4
+ import { OAuth2Auth } from "./oauth2.js";
5
+ /**
6
+ * Resolve environment variable references in auth values.
7
+ * Values starting with $ are treated as env var names.
8
+ */
9
+ function resolveEnvVar(value) {
10
+ if (value.startsWith("$")) {
11
+ const envName = value.slice(1);
12
+ const envValue = process.env[envName];
13
+ if (!envValue) {
14
+ logger.warn(`Environment variable ${envName} is not set`);
15
+ return "";
16
+ }
17
+ return envValue;
18
+ }
19
+ return value;
20
+ }
21
+ export function createAuthProvider(config) {
22
+ if (!config)
23
+ return null;
24
+ switch (config.type) {
25
+ case "api-key":
26
+ return new ApiKeyAuth(config.name, resolveEnvVar(config.value), config.in);
27
+ case "bearer":
28
+ return new BearerAuth(resolveEnvVar(config.token));
29
+ case "oauth2":
30
+ return new OAuth2Auth(resolveEnvVar(config.clientId), resolveEnvVar(config.clientSecret), config.tokenUrl, config.scopes);
31
+ default:
32
+ logger.warn("Unknown auth type, skipping auth");
33
+ return null;
34
+ }
35
+ }
36
+ //# sourceMappingURL=auth-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-manager.js","sourceRoot":"","sources":["../../../src/auth/auth-manager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC;;;GAGG;AACH,SAAS,aAAa,CAAC,KAAa;IACnC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC/B,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACtC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACf,MAAM,CAAC,IAAI,CAAC,wBAAwB,OAAO,aAAa,CAAC,CAAC;YAC1D,OAAO,EAAE,CAAC;QACX,CAAC;QACD,OAAO,QAAQ,CAAC;IACjB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,MAAmB;IACrD,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAEzB,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;QACrB,KAAK,SAAS;YACb,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC;QAC5E,KAAK,QAAQ;YACZ,OAAO,IAAI,UAAU,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACpD,KAAK,QAAQ;YACZ,OAAO,IAAI,UAAU,CACpB,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,EAC9B,aAAa,CAAC,MAAM,CAAC,YAAY,CAAC,EAClC,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,MAAM,CACb,CAAC;QACH;YACC,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;YAChD,OAAO,IAAI,CAAC;IACd,CAAC;AACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { PreparedRequest } from "../executor/types.js";
2
+ import type { AuthProvider } from "./types.js";
3
+ export declare class BearerAuth implements AuthProvider {
4
+ private readonly token;
5
+ constructor(token: string);
6
+ apply(request: PreparedRequest): Promise<PreparedRequest>;
7
+ }
8
+ //# sourceMappingURL=bearer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bearer.d.ts","sourceRoot":"","sources":["../../../src/auth/bearer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,qBAAa,UAAW,YAAW,YAAY;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK;gBAAL,KAAK,EAAE,MAAM;IAEpC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;CAS/D"}
@@ -0,0 +1,16 @@
1
+ export class BearerAuth {
2
+ token;
3
+ constructor(token) {
4
+ this.token = token;
5
+ }
6
+ async apply(request) {
7
+ return {
8
+ ...request,
9
+ headers: {
10
+ ...request.headers,
11
+ Authorization: `Bearer ${this.token}`,
12
+ },
13
+ };
14
+ }
15
+ }
16
+ //# sourceMappingURL=bearer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bearer.js","sourceRoot":"","sources":["../../../src/auth/bearer.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,UAAU;IACO;IAA7B,YAA6B,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAE9C,KAAK,CAAC,KAAK,CAAC,OAAwB;QACnC,OAAO;YACN,GAAG,OAAO;YACV,OAAO,EAAE;gBACR,GAAG,OAAO,CAAC,OAAO;gBAClB,aAAa,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE;aACrC;SACD,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,3 @@
1
+ export { createAuthProvider } from "./auth-manager.js";
2
+ export type { AuthProvider } from "./types.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createAuthProvider } from "./auth-manager.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/auth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { PreparedRequest } from "../executor/types.js";
2
+ import type { AuthProvider } from "./types.js";
3
+ export declare class OAuth2Auth implements AuthProvider {
4
+ private readonly clientId;
5
+ private readonly clientSecret;
6
+ private readonly tokenUrl;
7
+ private readonly scopes;
8
+ private accessToken;
9
+ private expiresAt;
10
+ constructor(clientId: string, clientSecret: string, tokenUrl: string, scopes?: string[]);
11
+ apply(request: PreparedRequest): Promise<PreparedRequest>;
12
+ private getToken;
13
+ }
14
+ //# sourceMappingURL=oauth2.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2.d.ts","sourceRoot":"","sources":["../../../src/auth/oauth2.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,qBAAa,UAAW,YAAW,YAAY;IAK7C,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAPxB,OAAO,CAAC,WAAW,CAAuB;IAC1C,OAAO,CAAC,SAAS,CAAK;gBAGJ,QAAQ,EAAE,MAAM,EAChB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,MAAM,GAAE,MAAM,EAAO;IAGjC,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;YAWjD,QAAQ;CA6CtB"}
@@ -0,0 +1,59 @@
1
+ import { AuthError } from "../utils/errors.js";
2
+ export class OAuth2Auth {
3
+ clientId;
4
+ clientSecret;
5
+ tokenUrl;
6
+ scopes;
7
+ accessToken = null;
8
+ expiresAt = 0;
9
+ constructor(clientId, clientSecret, tokenUrl, scopes = []) {
10
+ this.clientId = clientId;
11
+ this.clientSecret = clientSecret;
12
+ this.tokenUrl = tokenUrl;
13
+ this.scopes = scopes;
14
+ }
15
+ async apply(request) {
16
+ const token = await this.getToken();
17
+ return {
18
+ ...request,
19
+ headers: {
20
+ ...request.headers,
21
+ Authorization: `Bearer ${token}`,
22
+ },
23
+ };
24
+ }
25
+ async getToken() {
26
+ if (this.accessToken && Date.now() < this.expiresAt) {
27
+ return this.accessToken;
28
+ }
29
+ const params = new URLSearchParams({
30
+ grant_type: "client_credentials",
31
+ client_id: this.clientId,
32
+ client_secret: this.clientSecret,
33
+ });
34
+ if (this.scopes.length > 0) {
35
+ params.set("scope", this.scopes.join(" "));
36
+ }
37
+ try {
38
+ const response = await fetch(this.tokenUrl, {
39
+ method: "POST",
40
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
41
+ body: params,
42
+ signal: AbortSignal.timeout(10_000),
43
+ });
44
+ if (!response.ok) {
45
+ throw new AuthError(`OAuth2 token request failed: ${response.status} ${response.statusText}`);
46
+ }
47
+ const data = (await response.json());
48
+ this.accessToken = data.access_token;
49
+ this.expiresAt = Date.now() + (data.expires_in ?? 3600) * 1000 - 60_000; // refresh 1 min early
50
+ return this.accessToken;
51
+ }
52
+ catch (error) {
53
+ if (error instanceof AuthError)
54
+ throw error;
55
+ throw new AuthError(`OAuth2 token request failed: ${error instanceof Error ? error.message : String(error)}`);
56
+ }
57
+ }
58
+ }
59
+ //# sourceMappingURL=oauth2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth2.js","sourceRoot":"","sources":["../../../src/auth/oauth2.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAI/C,MAAM,OAAO,UAAU;IAKJ;IACA;IACA;IACA;IAPV,WAAW,GAAkB,IAAI,CAAC;IAClC,SAAS,GAAG,CAAC,CAAC;IAEtB,YACkB,QAAgB,EAChB,YAAoB,EACpB,QAAgB,EAChB,SAAmB,EAAE;QAHrB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,WAAM,GAAN,MAAM,CAAe;IACpC,CAAC;IAEJ,KAAK,CAAC,KAAK,CAAC,OAAwB;QACnC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;QACpC,OAAO;YACN,GAAG,OAAO;YACV,OAAO,EAAE;gBACR,GAAG,OAAO,CAAC,OAAO;gBAClB,aAAa,EAAE,UAAU,KAAK,EAAE;aAChC;SACD,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,QAAQ;QACrB,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;YACrD,OAAO,IAAI,CAAC,WAAW,CAAC;QACzB,CAAC;QAED,MAAM,MAAM,GAAG,IAAI,eAAe,CAAC;YAClC,UAAU,EAAE,oBAAoB;YAChC,SAAS,EAAE,IAAI,CAAC,QAAQ;YACxB,aAAa,EAAE,IAAI,CAAC,YAAY;SAChC,CAAC,CAAC;QAEH,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC5B,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,CAAC;YACJ,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAC3C,MAAM,EAAE,MAAM;gBACd,OAAO,EAAE,EAAE,cAAc,EAAE,mCAAmC,EAAE;gBAChE,IAAI,EAAE,MAAM;gBACZ,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC;aACnC,CAAC,CAAC;YAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;gBAClB,MAAM,IAAI,SAAS,CAClB,gCAAgC,QAAQ,CAAC,MAAM,IAAI,QAAQ,CAAC,UAAU,EAAE,CACxE,CAAC;YACH,CAAC;YAED,MAAM,IAAI,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAGlC,CAAC;YAEF,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,YAAY,CAAC;YACrC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,GAAG,IAAI,GAAG,MAAM,CAAC,CAAC,sBAAsB;YAE/F,OAAO,IAAI,CAAC,WAAW,CAAC;QACzB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAChB,IAAI,KAAK,YAAY,SAAS;gBAAE,MAAM,KAAK,CAAC;YAC5C,MAAM,IAAI,SAAS,CAClB,gCAAgC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACxF,CAAC;QACH,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,5 @@
1
+ import type { PreparedRequest } from "../executor/types.js";
2
+ export interface AuthProvider {
3
+ apply(request: PreparedRequest): Promise<PreparedRequest>;
4
+ }
5
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/auth/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,MAAM,WAAW,YAAY;IAC5B,KAAK,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC1D"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/auth/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import type { McpOpenApiConfig } from "./types.js";
2
+ export declare function parseCliArgs(argv: string[]): McpOpenApiConfig;
3
+ export declare function loadConfigFile(path: string): Promise<Partial<McpOpenApiConfig>>;
4
+ export declare function mergeConfigs(fileConfig: Partial<McpOpenApiConfig>, cliConfig: McpOpenApiConfig): McpOpenApiConfig;
5
+ //# sourceMappingURL=cli-args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli-args.d.ts","sourceRoot":"","sources":["../../../src/config/cli-args.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE/D,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAyE7D;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAGrF;AAED,wBAAgB,YAAY,CAC3B,UAAU,EAAE,OAAO,CAAC,gBAAgB,CAAC,EACrC,SAAS,EAAE,gBAAgB,GACzB,gBAAgB,CAQlB"}