mcp-openapi 0.1.0 → 0.1.1
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/README.md +2 -12
- package/dist/src/config/cli-args.js +4 -4
- package/dist/src/server.d.ts +37 -3
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +49 -22
- package/dist/src/server.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -316,20 +316,10 @@ console.log(`Loaded ${tools.length} tools from ${spec.info.title}`);
|
|
|
316
316
|
Contributions are welcome. Here is how to get started:
|
|
317
317
|
|
|
318
318
|
```bash
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
cd auto-revenue
|
|
322
|
-
|
|
323
|
-
# Install dependencies
|
|
319
|
+
git clone https://github.com/Docat0209/mcp-openapi.git
|
|
320
|
+
cd mcp-openapi
|
|
324
321
|
pnpm install
|
|
325
|
-
|
|
326
|
-
# Navigate to the package
|
|
327
|
-
cd packages/mcp-servers/openapi
|
|
328
|
-
|
|
329
|
-
# Run tests
|
|
330
322
|
pnpm test
|
|
331
|
-
|
|
332
|
-
# Build
|
|
333
323
|
pnpm build
|
|
334
324
|
```
|
|
335
325
|
|
|
@@ -117,7 +117,7 @@ function printHelp() {
|
|
|
117
117
|
mcp-openapi - Convert any OpenAPI/Swagger spec into MCP tools
|
|
118
118
|
|
|
119
119
|
USAGE:
|
|
120
|
-
npx
|
|
120
|
+
npx mcp-openapi --spec <url-or-path> [options]
|
|
121
121
|
|
|
122
122
|
OPTIONS:
|
|
123
123
|
-s, --spec <url|path> OpenAPI spec URL or local file path (required)
|
|
@@ -146,9 +146,9 @@ AUTH OPTIONS:
|
|
|
146
146
|
--auth-scopes <scopes>
|
|
147
147
|
|
|
148
148
|
EXAMPLES:
|
|
149
|
-
npx
|
|
150
|
-
npx
|
|
151
|
-
npx
|
|
149
|
+
npx mcp-openapi --spec https://petstore3.swagger.io/api/v3/openapi.json
|
|
150
|
+
npx mcp-openapi --spec ./api.yaml --auth-type bearer --auth-token '$API_KEY'
|
|
151
|
+
npx mcp-openapi --spec ./api.json --prefix github --include 'listRepos,getRepo'
|
|
152
152
|
`);
|
|
153
153
|
}
|
|
154
154
|
//# sourceMappingURL=cli-args.js.map
|
package/dist/src/server.d.ts
CHANGED
|
@@ -1,8 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import type { McpOpenApiConfig } from "./config/types.js";
|
|
3
|
+
import type { GeneratedTool } from "./generator/tool-generator.js";
|
|
3
4
|
export declare function createServer(config: McpOpenApiConfig): Promise<{
|
|
4
|
-
server:
|
|
5
|
-
|
|
5
|
+
server: Server<{
|
|
6
|
+
method: string;
|
|
7
|
+
params?: {
|
|
8
|
+
[x: string]: unknown;
|
|
9
|
+
_meta?: {
|
|
10
|
+
[x: string]: unknown;
|
|
11
|
+
progressToken?: string | number | undefined;
|
|
12
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
13
|
+
taskId: string;
|
|
14
|
+
} | undefined;
|
|
15
|
+
} | undefined;
|
|
16
|
+
} | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
method: string;
|
|
19
|
+
params?: {
|
|
20
|
+
[x: string]: unknown;
|
|
21
|
+
_meta?: {
|
|
22
|
+
[x: string]: unknown;
|
|
23
|
+
progressToken?: string | number | undefined;
|
|
24
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
25
|
+
taskId: string;
|
|
26
|
+
} | undefined;
|
|
27
|
+
} | undefined;
|
|
28
|
+
} | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
[x: string]: unknown;
|
|
31
|
+
_meta?: {
|
|
32
|
+
[x: string]: unknown;
|
|
33
|
+
progressToken?: string | number | undefined;
|
|
34
|
+
"io.modelcontextprotocol/related-task"?: {
|
|
35
|
+
taskId: string;
|
|
36
|
+
} | undefined;
|
|
37
|
+
} | undefined;
|
|
38
|
+
}>;
|
|
39
|
+
tools: GeneratedTool[];
|
|
6
40
|
spec: import("./index.js").NormalizedSpec;
|
|
7
41
|
}>;
|
|
8
42
|
export declare function startServer(config: McpOpenApiConfig): Promise<void>;
|
package/dist/src/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAOnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAM1D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAInE,wBAAsB,YAAY,CAAC,MAAM,EAAE,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyF1D;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,gBAAgB,iBAOzD"}
|
package/dist/src/server.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
2
2
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
|
|
3
4
|
import { createAuthProvider } from "./auth/index.js";
|
|
4
5
|
import { DEFAULT_CONFIG } from "./config/types.js";
|
|
5
6
|
import { buildRequest } from "./executor/request-builder.js";
|
|
@@ -24,31 +25,57 @@ export async function createServer(config) {
|
|
|
24
25
|
}
|
|
25
26
|
// Create auth provider
|
|
26
27
|
const authProvider = createAuthProvider(mergedConfig.auth);
|
|
27
|
-
//
|
|
28
|
-
const
|
|
28
|
+
// Build tool lookup
|
|
29
|
+
const toolMap = new Map();
|
|
30
|
+
for (const tool of tools) {
|
|
31
|
+
toolMap.set(tool.name, tool);
|
|
32
|
+
}
|
|
33
|
+
// Create MCP server using low-level API
|
|
34
|
+
const server = new Server({
|
|
29
35
|
name: `mcp-openapi: ${spec.info.title}`,
|
|
30
36
|
version: spec.info.version,
|
|
37
|
+
}, {
|
|
38
|
+
capabilities: {
|
|
39
|
+
tools: {},
|
|
40
|
+
},
|
|
31
41
|
});
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
// Handle list tools
|
|
43
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
44
|
+
tools: tools.map((t) => ({
|
|
45
|
+
name: t.name,
|
|
46
|
+
description: t.description,
|
|
47
|
+
inputSchema: {
|
|
48
|
+
type: "object",
|
|
49
|
+
properties: t.inputSchema.properties ?? {},
|
|
50
|
+
...(t.inputSchema.required ? { required: t.inputSchema.required } : {}),
|
|
51
|
+
},
|
|
52
|
+
})),
|
|
53
|
+
}));
|
|
54
|
+
// Handle call tool
|
|
55
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
56
|
+
const tool = toolMap.get(request.params.name);
|
|
57
|
+
if (!tool) {
|
|
58
|
+
return {
|
|
59
|
+
content: [{ type: "text", text: `Unknown tool: ${request.params.name}` }],
|
|
60
|
+
isError: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
const args = (request.params.arguments ?? {});
|
|
64
|
+
// Build HTTP request from tool call args
|
|
65
|
+
let httpRequest = buildRequest(args, tool.endpointRef, mergedConfig.headers);
|
|
66
|
+
// Apply auth
|
|
67
|
+
if (authProvider) {
|
|
68
|
+
httpRequest = await authProvider.apply(httpRequest);
|
|
69
|
+
}
|
|
70
|
+
// Execute HTTP request
|
|
71
|
+
const response = await executeRequest(httpRequest, {
|
|
72
|
+
timeout: mergedConfig.timeout,
|
|
73
|
+
maxRetries: mergedConfig.maxRetries,
|
|
50
74
|
});
|
|
51
|
-
|
|
75
|
+
// Map to MCP result
|
|
76
|
+
const result = mapResponse(response);
|
|
77
|
+
return { ...result };
|
|
78
|
+
});
|
|
52
79
|
logger.info(`Registered ${tools.length} tools from ${spec.info.title} v${spec.info.version}`);
|
|
53
80
|
return { server, tools, spec };
|
|
54
81
|
}
|
package/dist/src/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACN,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAE9D,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAwB;IAC1D,MAAM,YAAY,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,MAAM,EAAE,CAAC;IA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,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CACV,cAAc,KAAK,CAAC,MAAM,eAAe,IAAI,CAAC,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAChF,CAAC;IAEF,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAChC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,MAAwB;IACzD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC;IAE9C,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhC,MAAM,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;AAC5C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mcp-openapi",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "LLM-aware OpenAPI/Swagger to MCP tools converter. Point at any API spec, get instant MCP tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -46,9 +46,9 @@
|
|
|
46
46
|
"tools"
|
|
47
47
|
],
|
|
48
48
|
"license": "MIT",
|
|
49
|
+
"homepage": "https://github.com/Docat0209/mcp-openapi#readme",
|
|
49
50
|
"repository": {
|
|
50
51
|
"type": "git",
|
|
51
|
-
"url": "https://github.com/Docat0209/
|
|
52
|
-
"directory": "packages/mcp-servers/openapi"
|
|
52
|
+
"url": "https://github.com/Docat0209/mcp-openapi"
|
|
53
53
|
}
|
|
54
54
|
}
|