@abhishekkumar00019/swagger-mcp 1.0.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 +20 -0
- package/README.md +314 -0
- package/dist/core/config.d.ts +21 -0
- package/dist/core/config.js +91 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/types.d.ts +58 -0
- package/dist/core/types.js +3 -0
- package/dist/core/types.js.map +1 -0
- package/dist/http/auth.d.ts +8 -0
- package/dist/http/auth.js +31 -0
- package/dist/http/auth.js.map +1 -0
- package/dist/http/request-handler.d.ts +12 -0
- package/dist/http/request-handler.js +167 -0
- package/dist/http/request-handler.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/swagger-parser.d.ts +20 -0
- package/dist/parser/swagger-parser.js +262 -0
- package/dist/parser/swagger-parser.js.map +1 -0
- package/dist/parser/tool-builder.d.ts +29 -0
- package/dist/parser/tool-builder.js +138 -0
- package/dist/parser/tool-builder.js.map +1 -0
- package/dist/server.d.ts +19 -0
- package/dist/server.js +175 -0
- package/dist/server.js.map +1 -0
- package/package.json +55 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abhishek Kumar
|
|
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 MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
# @abhishekkumar00019/swagger-mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@abhishekkumar00019/swagger-mcp)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://modelcontextprotocol.io)
|
|
6
|
+
|
|
7
|
+
> A dynamic [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server that converts any Swagger 2.0 or OpenAPI 3.x specification into callable MCP tools on the fly.
|
|
8
|
+
|
|
9
|
+
Point it at any OpenAPI/Swagger JSON or YAML spec URL, and every API endpoint automatically becomes an interactive tool for Claude, Copilot, ChatGPT, Cursor, Windsurf, and other MCP-enabled clients.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ✨ Features
|
|
14
|
+
|
|
15
|
+
- 🔄 **Dynamic Tool Generation** — Automatically parses Swagger 2.0 & OpenAPI 3.x specs at startup.
|
|
16
|
+
- 🛠️ **Zero Boilerplate** — Give it a spec URL and every endpoint is instantly exposed as an MCP tool.
|
|
17
|
+
- 🔐 **Flexible Auth Support** — Bearer Tokens, API Keys, and Basic Auth configured effortlessly via env vars or CLI flags.
|
|
18
|
+
- 🌐 **Smart Base URL Resolution** — Auto-derives base URL from config → spec server definition → spec origin URL.
|
|
19
|
+
- 🔁 **Hot Reloading** — Re-fetch and re-parse the spec live at runtime using the `_swagger_mcp_reload` tool.
|
|
20
|
+
- 📝 **Rich Schemas & Descriptions** — Translates OpenAPI parameters and request bodies into strict JSON schemas for precise LLM tool calling.
|
|
21
|
+
- ⏱️ **Configurable Timeouts & Custom Headers** — Easily set custom request headers and request timeout thresholds.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 🚀 Quick Start
|
|
26
|
+
|
|
27
|
+
### Option A: Direct via `npx` (No Installation Required)
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
SWAGGER_MCP_SPEC_URL=https://petstore.swagger.io/v2/swagger.json npx @abhishekkumar00019/swagger-mcp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Option B: Global NPM Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npm install -g @abhishekkumar00019/swagger-mcp
|
|
37
|
+
|
|
38
|
+
SWAGGER_MCP_SPEC_URL=https://petstore.swagger.io/v2/swagger.json swagger-mcp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Option C: Local Repository Setup
|
|
42
|
+
|
|
43
|
+
1. **Clone & Install Dependencies:**
|
|
44
|
+
```bash
|
|
45
|
+
git clone https://github.com/itachiuchihadev/swagger-mcp.git
|
|
46
|
+
cd swagger-mcp
|
|
47
|
+
npm install
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
2. **Build the Project:**
|
|
51
|
+
```bash
|
|
52
|
+
npm run build
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
3. **Run locally:**
|
|
56
|
+
```bash
|
|
57
|
+
SWAGGER_MCP_SPEC_URL=https://petstore.swagger.io/v2/swagger.json node dist/index.js
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## ⚙️ MCP Client Configurations
|
|
63
|
+
|
|
64
|
+
Below are sample configurations for popular MCP clients using `npx @abhishekkumar00019/swagger-mcp`.
|
|
65
|
+
|
|
66
|
+
### 1. Claude Desktop
|
|
67
|
+
|
|
68
|
+
Add to your `claude_desktop_config.json`:
|
|
69
|
+
- **macOS:** `~/Library/Application Support/Claude/claude_desktop_config.json`
|
|
70
|
+
- **Windows:** `%APPDATA%\Claude\claude_desktop_config.json`
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"mcpServers": {
|
|
75
|
+
"swagger-mcp": {
|
|
76
|
+
"command": "npx",
|
|
77
|
+
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
|
|
78
|
+
"env": {
|
|
79
|
+
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json",
|
|
80
|
+
"SWAGGER_MCP_BEARER_TOKEN": "your-api-token-here"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### 2. Claude Code (CLI)
|
|
90
|
+
|
|
91
|
+
Add directly via the Claude Code CLI:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
claude mcp add swagger-mcp -- npx -y @abhishekkumar00019/swagger-mcp --spec-url https://petstore.swagger.io/v2/swagger.json
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Or add to `.mcp.json` in your project root:
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"mcpServers": {
|
|
102
|
+
"swagger-mcp": {
|
|
103
|
+
"command": "npx",
|
|
104
|
+
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
|
|
105
|
+
"env": {
|
|
106
|
+
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
---
|
|
114
|
+
|
|
115
|
+
### 3. GitHub Copilot / VS Code
|
|
116
|
+
|
|
117
|
+
Add to `.vscode/mcp.json` in your workspace or global VS Code settings:
|
|
118
|
+
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"mcpServers": {
|
|
122
|
+
"swagger-mcp": {
|
|
123
|
+
"command": "npx",
|
|
124
|
+
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
|
|
125
|
+
"env": {
|
|
126
|
+
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json",
|
|
127
|
+
"SWAGGER_MCP_API_KEY": "your-api-key"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
### 4. Cursor
|
|
137
|
+
|
|
138
|
+
Add to `.cursor/mcp.json` or configure in **Cursor Settings → Features → MCP**:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"mcpServers": {
|
|
143
|
+
"swagger-mcp": {
|
|
144
|
+
"command": "npx",
|
|
145
|
+
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
|
|
146
|
+
"env": {
|
|
147
|
+
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
### 5. Windsurf
|
|
157
|
+
|
|
158
|
+
Add to `~/.codeium/windsurf/mcp_config.json`:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
{
|
|
162
|
+
"mcpServers": {
|
|
163
|
+
"swagger-mcp": {
|
|
164
|
+
"command": "npx",
|
|
165
|
+
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
|
|
166
|
+
"env": {
|
|
167
|
+
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
### 6. Roo Code / Cline (VS Code Extension)
|
|
177
|
+
|
|
178
|
+
Add to `cline_mcp_settings.json` (or `roo_code_mcp_settings.json`):
|
|
179
|
+
|
|
180
|
+
```json
|
|
181
|
+
{
|
|
182
|
+
"mcpServers": {
|
|
183
|
+
"swagger-mcp": {
|
|
184
|
+
"command": "npx",
|
|
185
|
+
"args": ["-y", "@abhishekkumar00019/swagger-mcp"],
|
|
186
|
+
"env": {
|
|
187
|
+
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
### 7. ChatGPT & OpenAI (Custom GPTs / Assistants / API)
|
|
197
|
+
|
|
198
|
+
**Direct OpenAPI Spec Import (Native Custom GPT Actions):**
|
|
199
|
+
ChatGPT Custom GPTs support OpenAPI specifications natively. You can directly import your Swagger/OpenAPI JSON/YAML spec URL in the **Actions** section of the Custom GPT Builder without needing an intermediate server.
|
|
200
|
+
|
|
201
|
+
**Via MCP HTTP/SSE Gateway:**
|
|
202
|
+
If connecting ChatGPT or OpenAI agents to this MCP server via an HTTP/SSE bridge (e.g., using `supergateway` or `mcp-remote`), start `swagger-mcp` with an SSE proxy:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
npx supergateway --stdio "npx -y @abhishekkumar00019/swagger-mcp --spec-url https://petstore.swagger.io/v2/swagger.json" --port 8000
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
### 8. Zed Editor
|
|
211
|
+
|
|
212
|
+
Add to `~/.config/zed/settings.json`:
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"context_servers": {
|
|
217
|
+
"swagger-mcp": {
|
|
218
|
+
"command": {
|
|
219
|
+
"path": "npx",
|
|
220
|
+
"args": ["-y", "@abhishekkumar00019/swagger-mcp"]
|
|
221
|
+
},
|
|
222
|
+
"env": {
|
|
223
|
+
"SWAGGER_MCP_SPEC_URL": "https://petstore.swagger.io/v2/swagger.json"
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🔧 Configuration Reference
|
|
233
|
+
|
|
234
|
+
All configuration parameters can be supplied via environment variables or CLI arguments. **`SWAGGER_MCP_SPEC_URL` is the only required parameter.**
|
|
235
|
+
|
|
236
|
+
| Environment Variable | CLI Argument | Required | Default | Description |
|
|
237
|
+
|---|---|---|---|---|
|
|
238
|
+
| `SWAGGER_MCP_SPEC_URL` | `--spec-url` | Yes | — | Swagger/OpenAPI spec URL |
|
|
239
|
+
| `SWAGGER_MCP_BASE_URL` | `--base-url` | No | Auto-derived | Override target API base URL |
|
|
240
|
+
| `SWAGGER_MCP_BEARER_TOKEN` | `--bearer-token` | No | — | Bearer token for `Authorization: Bearer <token>` |
|
|
241
|
+
| `SWAGGER_MCP_API_KEY` | `--api-key` | No | — | API Key header value |
|
|
242
|
+
| `SWAGGER_MCP_API_KEY_HEADER` | `--api-key-header` | No | `X-API-Key` | Custom header name for API Key |
|
|
243
|
+
| `SWAGGER_MCP_BASIC_USER` | `--basic-user` | No | — | Username for Basic Auth |
|
|
244
|
+
| `SWAGGER_MCP_BASIC_PASS` | `--basic-pass` | No | — | Password for Basic Auth |
|
|
245
|
+
| `SWAGGER_MCP_TIMEOUT` | `--timeout` | No | `30000` | HTTP request timeout in milliseconds |
|
|
246
|
+
| `SWAGGER_MCP_HEADERS` | `--headers` | No | `{}` | Extra HTTP headers as JSON string |
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
### 🔑 Authentication Examples
|
|
251
|
+
|
|
252
|
+
Multiple authentication methods can be set simultaneously:
|
|
253
|
+
|
|
254
|
+
```bash
|
|
255
|
+
# Bearer Token
|
|
256
|
+
SWAGGER_MCP_BEARER_TOKEN=sk-your-token-here
|
|
257
|
+
|
|
258
|
+
# API Key (Custom Header)
|
|
259
|
+
SWAGGER_MCP_API_KEY=your-api-key
|
|
260
|
+
SWAGGER_MCP_API_KEY_HEADER=X-Custom-Key
|
|
261
|
+
|
|
262
|
+
# Basic Auth
|
|
263
|
+
SWAGGER_MCP_BASIC_USER=admin
|
|
264
|
+
SWAGGER_MCP_BASIC_PASS=secret123
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
> [!NOTE]
|
|
268
|
+
> If both Bearer and Basic Auth are specified, Basic Auth will overwrite the `Authorization` header. Combine Bearer Token with API Key headers if multiple headers are required.
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 🏷️ Tool Naming Strategy
|
|
273
|
+
|
|
274
|
+
Endpoints from your OpenAPI spec are converted into MCP tools using the following priority order:
|
|
275
|
+
|
|
276
|
+
| Priority | Source | Example |
|
|
277
|
+
|---|---|---|
|
|
278
|
+
| **1st** | `operationId` defined in spec | `getUserById` |
|
|
279
|
+
| **2nd** | Tag + Method + Path | `users_get_by_id` |
|
|
280
|
+
| **3rd** | Method + Path | `get_api_v1_users_by_id` |
|
|
281
|
+
|
|
282
|
+
---
|
|
283
|
+
|
|
284
|
+
## 🧰 Built-in Meta Tools
|
|
285
|
+
|
|
286
|
+
| Tool | Description |
|
|
287
|
+
|---|---|
|
|
288
|
+
| `_swagger_mcp_reload` | Re-fetches and parses the Swagger spec live. Useful when developing or updating APIs without restarting the server. |
|
|
289
|
+
|
|
290
|
+
---
|
|
291
|
+
|
|
292
|
+
## 📁 Project Structure
|
|
293
|
+
|
|
294
|
+
```text
|
|
295
|
+
swagger-mcp/
|
|
296
|
+
├── package.json
|
|
297
|
+
├── tsconfig.json
|
|
298
|
+
├── src/
|
|
299
|
+
│ ├── index.ts # Entry point & CLI argument parser
|
|
300
|
+
│ ├── server.ts # MCP server initialization & tool registration
|
|
301
|
+
│ ├── swagger-parser.ts # OpenAPI 2.0/3.x spec fetcher & parser
|
|
302
|
+
│ ├── tool-builder.ts # Converts OpenAPI operations -> JSON Schema tools
|
|
303
|
+
│ ├── request-handler.ts # Proxies MCP tool calls to HTTP endpoints
|
|
304
|
+
│ ├── auth.ts # Authentication header builder
|
|
305
|
+
│ ├── config.ts # Environment & CLI configuration manager
|
|
306
|
+
│ └── types.ts # Shared TypeScript interfaces
|
|
307
|
+
└── dist/ # Compiled JavaScript output
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
## 📄 License
|
|
313
|
+
|
|
314
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ServerConfig } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Loads server configuration from environment variables and CLI arguments.
|
|
4
|
+
*
|
|
5
|
+
* Priority: CLI args override env vars.
|
|
6
|
+
* Only SWAGGER_MCP_SPEC_URL is required — everything else is optional.
|
|
7
|
+
*/
|
|
8
|
+
export declare function loadConfig(): ServerConfig;
|
|
9
|
+
/**
|
|
10
|
+
* Builds a ServerConfig from explicit values (useful for testing and programmatic use).
|
|
11
|
+
* Applies defaults for optional fields.
|
|
12
|
+
*/
|
|
13
|
+
export declare function buildConfig(overrides: Partial<ServerConfig> & {
|
|
14
|
+
specUrl: string;
|
|
15
|
+
}): ServerConfig;
|
|
16
|
+
/**
|
|
17
|
+
* Simple CLI argument parser.
|
|
18
|
+
* Supports: --key value and --key=value
|
|
19
|
+
* Returns a Record<string, string>.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseCliArgs(argv: string[]): Record<string, string>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Loads server configuration from environment variables and CLI arguments.
|
|
3
|
+
*
|
|
4
|
+
* Priority: CLI args override env vars.
|
|
5
|
+
* Only SWAGGER_MCP_SPEC_URL is required — everything else is optional.
|
|
6
|
+
*/
|
|
7
|
+
export function loadConfig() {
|
|
8
|
+
const args = parseCliArgs(process.argv.slice(2));
|
|
9
|
+
const specUrl = args["spec-url"] || process.env.SWAGGER_MCP_SPEC_URL;
|
|
10
|
+
if (!specUrl) {
|
|
11
|
+
console.error("Error: Swagger spec URL is required.\n" +
|
|
12
|
+
"Provide it via --spec-url <url> or SWAGGER_MCP_SPEC_URL env var.");
|
|
13
|
+
process.exit(1);
|
|
14
|
+
}
|
|
15
|
+
// Parse extra headers from JSON string
|
|
16
|
+
let defaultHeaders = {};
|
|
17
|
+
const headersRaw = args["headers"] || process.env.SWAGGER_MCP_HEADERS;
|
|
18
|
+
if (headersRaw) {
|
|
19
|
+
try {
|
|
20
|
+
defaultHeaders = JSON.parse(headersRaw);
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
console.error("Warning: SWAGGER_MCP_HEADERS is not valid JSON, ignoring.");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const timeoutRaw = args["timeout"] || process.env.SWAGGER_MCP_TIMEOUT;
|
|
27
|
+
return {
|
|
28
|
+
specUrl,
|
|
29
|
+
baseUrl: args["base-url"] || process.env.SWAGGER_MCP_BASE_URL || undefined,
|
|
30
|
+
auth: {
|
|
31
|
+
bearerToken: args["bearer-token"] ||
|
|
32
|
+
process.env.SWAGGER_MCP_BEARER_TOKEN ||
|
|
33
|
+
undefined,
|
|
34
|
+
apiKey: args["api-key"] || process.env.SWAGGER_MCP_API_KEY || undefined,
|
|
35
|
+
apiKeyHeader: args["api-key-header"] ||
|
|
36
|
+
process.env.SWAGGER_MCP_API_KEY_HEADER ||
|
|
37
|
+
undefined,
|
|
38
|
+
basicUser: args["basic-user"] ||
|
|
39
|
+
process.env.SWAGGER_MCP_BASIC_USER ||
|
|
40
|
+
undefined,
|
|
41
|
+
basicPass: args["basic-pass"] ||
|
|
42
|
+
process.env.SWAGGER_MCP_BASIC_PASS ||
|
|
43
|
+
undefined,
|
|
44
|
+
},
|
|
45
|
+
timeout: timeoutRaw ? parseInt(timeoutRaw, 10) : 30_000,
|
|
46
|
+
defaultHeaders,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Builds a ServerConfig from explicit values (useful for testing and programmatic use).
|
|
51
|
+
* Applies defaults for optional fields.
|
|
52
|
+
*/
|
|
53
|
+
export function buildConfig(overrides) {
|
|
54
|
+
return {
|
|
55
|
+
specUrl: overrides.specUrl,
|
|
56
|
+
baseUrl: overrides.baseUrl,
|
|
57
|
+
auth: overrides.auth ?? {},
|
|
58
|
+
timeout: overrides.timeout ?? 30_000,
|
|
59
|
+
defaultHeaders: overrides.defaultHeaders ?? {},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Simple CLI argument parser.
|
|
64
|
+
* Supports: --key value and --key=value
|
|
65
|
+
* Returns a Record<string, string>.
|
|
66
|
+
*/
|
|
67
|
+
export function parseCliArgs(argv) {
|
|
68
|
+
const result = {};
|
|
69
|
+
for (let i = 0; i < argv.length; i++) {
|
|
70
|
+
const arg = argv[i];
|
|
71
|
+
if (!arg.startsWith("--"))
|
|
72
|
+
continue;
|
|
73
|
+
const equalIndex = arg.indexOf("=");
|
|
74
|
+
if (equalIndex !== -1) {
|
|
75
|
+
// --key=value
|
|
76
|
+
const key = arg.substring(2, equalIndex);
|
|
77
|
+
result[key] = arg.substring(equalIndex + 1);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// --key value
|
|
81
|
+
const key = arg.substring(2);
|
|
82
|
+
const nextArg = argv[i + 1];
|
|
83
|
+
if (nextArg && !nextArg.startsWith("--")) {
|
|
84
|
+
result[key] = nextArg;
|
|
85
|
+
i++; // skip the value
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @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CAAC;YACzC,MAAM,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,cAAc;YACd,MAAM,GAAG,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;YAC7B,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC5B,IAAI,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;gBACzC,MAAM,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC;gBACtB,CAAC,EAAE,CAAC,CAAC,iBAAiB;YACxB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export declare const HTTP_METHODS: readonly ["get", "post", "put", "delete", "patch"];
|
|
2
|
+
export type HttpMethod = (typeof HTTP_METHODS)[number];
|
|
3
|
+
export interface ParsedParameter {
|
|
4
|
+
name: string;
|
|
5
|
+
in: "path" | "query" | "header" | "cookie";
|
|
6
|
+
description?: string;
|
|
7
|
+
required: boolean;
|
|
8
|
+
schema: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
export interface ParsedRequestBody {
|
|
11
|
+
description?: string;
|
|
12
|
+
required: boolean;
|
|
13
|
+
schema: Record<string, unknown>;
|
|
14
|
+
contentType: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ParsedOperation {
|
|
17
|
+
/** The operationId from the spec (may be undefined) */
|
|
18
|
+
operationId?: string;
|
|
19
|
+
/** HTTP method */
|
|
20
|
+
method: HttpMethod;
|
|
21
|
+
/** The raw path template, e.g. /users/{id} */
|
|
22
|
+
path: string;
|
|
23
|
+
/** First tag from the operation (if any) */
|
|
24
|
+
tag?: string;
|
|
25
|
+
/** Short summary from the spec */
|
|
26
|
+
summary?: string;
|
|
27
|
+
/** Longer description from the spec */
|
|
28
|
+
description?: string;
|
|
29
|
+
/** All parameters (path, query, header, cookie) */
|
|
30
|
+
parameters: ParsedParameter[];
|
|
31
|
+
/** Request body (for POST/PUT/PATCH) */
|
|
32
|
+
requestBody?: ParsedRequestBody;
|
|
33
|
+
}
|
|
34
|
+
export interface AuthConfig {
|
|
35
|
+
bearerToken?: string;
|
|
36
|
+
apiKey?: string;
|
|
37
|
+
apiKeyHeader?: string;
|
|
38
|
+
basicUser?: string;
|
|
39
|
+
basicPass?: string;
|
|
40
|
+
}
|
|
41
|
+
export interface ServerConfig {
|
|
42
|
+
/** Swagger/OpenAPI spec URL (required) */
|
|
43
|
+
specUrl: string;
|
|
44
|
+
/** Override base URL — auto-derived if omitted */
|
|
45
|
+
baseUrl?: string;
|
|
46
|
+
/** Authentication configuration */
|
|
47
|
+
auth: AuthConfig;
|
|
48
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
49
|
+
timeout: number;
|
|
50
|
+
/** Extra headers to attach to every outgoing request */
|
|
51
|
+
defaultHeaders: Record<string, string>;
|
|
52
|
+
}
|
|
53
|
+
export interface ToolMapping {
|
|
54
|
+
/** The MCP tool name */
|
|
55
|
+
toolName: string;
|
|
56
|
+
/** The parsed operation this tool maps to */
|
|
57
|
+
operation: ParsedOperation;
|
|
58
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/core/types.ts"],"names":[],"mappings":"AACA,+EAA+E;AAC/E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AuthConfig } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Builds authentication headers from the provided auth configuration.
|
|
4
|
+
* Multiple auth mechanisms can coexist — all matching headers are merged.
|
|
5
|
+
*
|
|
6
|
+
* Returns an empty object if no auth is configured.
|
|
7
|
+
*/
|
|
8
|
+
export declare function getAuthHeaders(auth: AuthConfig): Record<string, string>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builds authentication headers from the provided auth configuration.
|
|
3
|
+
* Multiple auth mechanisms can coexist — all matching headers are merged.
|
|
4
|
+
*
|
|
5
|
+
* Returns an empty object if no auth is configured.
|
|
6
|
+
*/
|
|
7
|
+
export function getAuthHeaders(auth) {
|
|
8
|
+
const headers = {};
|
|
9
|
+
// Bearer token → Authorization: Bearer <token>
|
|
10
|
+
if (auth.bearerToken) {
|
|
11
|
+
headers["Authorization"] = `Bearer ${auth.bearerToken}`;
|
|
12
|
+
}
|
|
13
|
+
// API Key → <header>: <key> (default header: X-API-Key)
|
|
14
|
+
if (auth.apiKey) {
|
|
15
|
+
const headerName = auth.apiKeyHeader || "X-API-Key";
|
|
16
|
+
headers[headerName] = auth.apiKey;
|
|
17
|
+
}
|
|
18
|
+
// Basic auth → Authorization: Basic <base64(user:pass)>
|
|
19
|
+
// Uses !== undefined to allow empty string passwords (which are valid in HTTP Basic Auth).
|
|
20
|
+
// Note: if bearer is also set, basic will overwrite the Authorization header.
|
|
21
|
+
if (auth.basicUser !== undefined && auth.basicPass !== undefined) {
|
|
22
|
+
if (auth.bearerToken) {
|
|
23
|
+
console.error("[swagger-mcp] Warning: Both Bearer token and Basic auth are configured. " +
|
|
24
|
+
"Basic auth will overwrite the Authorization header.");
|
|
25
|
+
}
|
|
26
|
+
const credentials = Buffer.from(`${auth.basicUser}:${auth.basicPass}`).toString("base64");
|
|
27
|
+
headers["Authorization"] = `Basic ${credentials}`;
|
|
28
|
+
}
|
|
29
|
+
return headers;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/http/auth.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,MAAM,OAAO,GAA2B,EAAE,CAAC;IAE3C,+CAA+C;IAC/C,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,OAAO,CAAC,eAAe,CAAC,GAAG,UAAU,IAAI,CAAC,WAAW,EAAE,CAAC;IAC1D,CAAC;IAED,wDAAwD;IACxD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,UAAU,GAAG,IAAI,CAAC,YAAY,IAAI,WAAW,CAAC;QACpD,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IACpC,CAAC;IAED,wDAAwD;IACxD,2FAA2F;IAC3F,8EAA8E;IAC9E,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;QACjE,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrB,OAAO,CAAC,KAAK,CACX,0EAA0E;gBACxE,qDAAqD,CACxD,CAAC;QACJ,CAAC;QACD,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAC7B,GAAG,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE,CACtC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACrB,OAAO,CAAC,eAAe,CAAC,GAAG,SAAS,WAAW,EAAE,CAAC;IACpD,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ServerConfig, ToolMapping } from "../core/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Executes an HTTP request for a tool invocation.
|
|
4
|
+
*
|
|
5
|
+
* Takes the tool mapping (which knows the operation details) and the
|
|
6
|
+
* arguments provided by the LLM, builds the full HTTP request, executes it,
|
|
7
|
+
* and returns the response as a string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function executeToolRequest(mapping: ToolMapping, args: Record<string, unknown>, config: ServerConfig, baseUrl: string): Promise<{
|
|
10
|
+
content: string;
|
|
11
|
+
isError: boolean;
|
|
12
|
+
}>;
|