openapi-dynamic-mcp 0.1.3 → 0.2.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 +150 -105
- package/dist/auth/env.d.ts +7 -1
- package/dist/auth/env.js +25 -12
- package/dist/auth/env.js.map +1 -1
- package/dist/auth/oauthClient.d.ts +1 -1
- package/dist/auth/oauthClient.js +13 -13
- package/dist/auth/oauthClient.js.map +1 -1
- package/dist/auth/resolveAuth.d.ts +3 -3
- package/dist/auth/resolveAuth.js +58 -19
- package/dist/auth/resolveAuth.js.map +1 -1
- package/dist/cli.js +11 -11
- package/dist/cli.js.map +1 -1
- package/dist/config/loadConfig.d.ts +1 -1
- package/dist/config/loadConfig.js +46 -34
- package/dist/config/loadConfig.js.map +1 -1
- package/dist/errors.d.ts +1 -1
- package/dist/errors.js +7 -7
- package/dist/http/requestExecutor.d.ts +3 -2
- package/dist/http/requestExecutor.js +201 -67
- package/dist/http/requestExecutor.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +6 -6
- package/dist/mcp/context.d.ts +2 -2
- package/dist/mcp/server.d.ts +1 -1
- package/dist/mcp/server.js +86 -59
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/tools/common.d.ts +6 -6
- package/dist/mcp/tools/common.js +15 -14
- package/dist/mcp/tools/common.js.map +1 -1
- package/dist/mcp/tools/getApiEndpoint.d.ts +2 -2
- package/dist/mcp/tools/getApiEndpoint.js +19 -15
- package/dist/mcp/tools/getApiEndpoint.js.map +1 -1
- package/dist/mcp/tools/getApiSchema.d.ts +2 -2
- package/dist/mcp/tools/getApiSchema.js +6 -6
- package/dist/mcp/tools/getApiSchema.js.map +1 -1
- package/dist/mcp/tools/index.d.ts +5 -5
- package/dist/mcp/tools/index.js +5 -5
- package/dist/mcp/tools/listApiEndpoints.d.ts +2 -2
- package/dist/mcp/tools/listApiEndpoints.js +4 -4
- package/dist/mcp/tools/listApis.d.ts +2 -2
- package/dist/mcp/tools/listApis.js +2 -2
- package/dist/mcp/tools/makeEndpointRequest.d.ts +2 -2
- package/dist/mcp/tools/makeEndpointRequest.js +21 -19
- package/dist/mcp/tools/makeEndpointRequest.js.map +1 -1
- package/dist/openapi/endpointIndex.d.ts +2 -2
- package/dist/openapi/endpointIndex.js +13 -13
- package/dist/openapi/endpointIndex.js.map +1 -1
- package/dist/openapi/jsonPointer.js +15 -12
- package/dist/openapi/jsonPointer.js.map +1 -1
- package/dist/openapi/loadSpec.d.ts +1 -1
- package/dist/openapi/loadSpec.js +46 -17
- package/dist/openapi/loadSpec.js.map +1 -1
- package/dist/types.d.ts +29 -9
- package/dist/types.js +9 -1
- package/dist/types.js.map +1 -1
- package/package.json +16 -2
package/dist/mcp/server.js
CHANGED
|
@@ -1,99 +1,124 @@
|
|
|
1
|
-
import { Server } from
|
|
2
|
-
import { StdioServerTransport } from
|
|
3
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, } from
|
|
4
|
-
import { getApiEndpointTool, getApiSchemaTool, listApiEndpointsTool, listApisTool, makeEndpointRequestTool, } from
|
|
5
|
-
import { fail } from
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
3
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { getApiEndpointTool, getApiSchemaTool, listApiEndpointsTool, listApisTool, makeEndpointRequestTool, } from './tools/index.js';
|
|
5
|
+
import { fail } from './tools/common.js';
|
|
6
6
|
const TOOLS = [
|
|
7
7
|
{
|
|
8
|
-
name:
|
|
9
|
-
description:
|
|
8
|
+
name: 'list_apis',
|
|
9
|
+
description: 'List configured APIs loaded from the YAML configuration.',
|
|
10
10
|
inputSchema: {
|
|
11
|
-
type:
|
|
11
|
+
type: 'object',
|
|
12
12
|
properties: {},
|
|
13
13
|
additionalProperties: false,
|
|
14
14
|
},
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
name:
|
|
18
|
-
description:
|
|
17
|
+
name: 'list_api_endpoints',
|
|
18
|
+
description: 'List endpoints from a specific API with optional filters.',
|
|
19
19
|
inputSchema: {
|
|
20
|
-
type:
|
|
20
|
+
type: 'object',
|
|
21
21
|
properties: {
|
|
22
|
-
apiName: { type:
|
|
23
|
-
method: { type:
|
|
24
|
-
tag: { type:
|
|
25
|
-
pathContains: { type:
|
|
26
|
-
search: { type:
|
|
27
|
-
limit: { type:
|
|
28
|
-
cursor: { type:
|
|
22
|
+
apiName: { type: 'string' },
|
|
23
|
+
method: { type: 'string' },
|
|
24
|
+
tag: { type: 'string' },
|
|
25
|
+
pathContains: { type: 'string' },
|
|
26
|
+
search: { type: 'array', items: { type: 'string' } },
|
|
27
|
+
limit: { type: 'integer', minimum: 1 },
|
|
28
|
+
cursor: { type: 'string' },
|
|
29
29
|
},
|
|
30
|
-
required: [
|
|
30
|
+
required: ['apiName'],
|
|
31
31
|
additionalProperties: false,
|
|
32
32
|
},
|
|
33
33
|
},
|
|
34
34
|
{
|
|
35
|
-
name:
|
|
36
|
-
description:
|
|
35
|
+
name: 'get_api_endpoint',
|
|
36
|
+
description: 'Get details for one endpoint in a specific API.',
|
|
37
37
|
inputSchema: {
|
|
38
|
-
type:
|
|
38
|
+
type: 'object',
|
|
39
39
|
properties: {
|
|
40
|
-
apiName: { type:
|
|
41
|
-
endpointId: { type:
|
|
40
|
+
apiName: { type: 'string' },
|
|
41
|
+
endpointId: { type: 'string' },
|
|
42
42
|
},
|
|
43
|
-
required: [
|
|
43
|
+
required: ['apiName', 'endpointId'],
|
|
44
44
|
additionalProperties: false,
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
|
-
name:
|
|
49
|
-
description:
|
|
48
|
+
name: 'get_api_schema',
|
|
49
|
+
description: 'Get the full dereferenced API schema or a JSON pointer fragment.',
|
|
50
50
|
inputSchema: {
|
|
51
|
-
type:
|
|
51
|
+
type: 'object',
|
|
52
52
|
properties: {
|
|
53
|
-
apiName: { type:
|
|
54
|
-
pointer: { type:
|
|
53
|
+
apiName: { type: 'string' },
|
|
54
|
+
pointer: { type: 'string' },
|
|
55
55
|
},
|
|
56
|
-
required: [
|
|
56
|
+
required: ['apiName'],
|
|
57
57
|
additionalProperties: false,
|
|
58
58
|
},
|
|
59
59
|
},
|
|
60
60
|
{
|
|
61
|
-
name:
|
|
62
|
-
description:
|
|
61
|
+
name: 'make_endpoint_request',
|
|
62
|
+
description: 'Execute an HTTP request for an endpoint by endpointId.',
|
|
63
63
|
inputSchema: {
|
|
64
|
-
type:
|
|
64
|
+
type: 'object',
|
|
65
65
|
properties: {
|
|
66
|
-
apiName: { type:
|
|
67
|
-
endpointId: { type:
|
|
68
|
-
pathParams: { type:
|
|
69
|
-
query: { type:
|
|
70
|
-
headers: { type:
|
|
71
|
-
cookies: { type:
|
|
72
|
-
body: {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
66
|
+
apiName: { type: 'string' },
|
|
67
|
+
endpointId: { type: 'string' },
|
|
68
|
+
pathParams: { type: 'object' },
|
|
69
|
+
query: { type: 'object' },
|
|
70
|
+
headers: { type: 'object', additionalProperties: { type: 'string' } },
|
|
71
|
+
cookies: { type: 'object', additionalProperties: { type: 'string' } },
|
|
72
|
+
body: {
|
|
73
|
+
description: 'Request body. For file uploads, use the files parameter instead.',
|
|
74
|
+
},
|
|
75
|
+
files: {
|
|
76
|
+
type: 'object',
|
|
77
|
+
description: 'Optional file payload(s) for multipart/form-data or application/octet-stream. Keys represent the form field name. Values must contain EXACTLY ONE of: base64, text, or filePath.',
|
|
78
|
+
additionalProperties: {
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
name: {
|
|
82
|
+
type: 'string',
|
|
83
|
+
description: 'Optional filename (e.g. avatar.png)',
|
|
84
|
+
},
|
|
85
|
+
contentType: {
|
|
86
|
+
type: 'string',
|
|
87
|
+
description: 'Optional MIME type (e.g. image/png)',
|
|
88
|
+
},
|
|
89
|
+
base64: { type: 'string', description: 'Base64 encoded content' },
|
|
90
|
+
text: { type: 'string', description: 'Raw text content' },
|
|
91
|
+
filePath: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
description: 'Absolute path to local file',
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
contentType: { type: 'string' },
|
|
99
|
+
accept: { type: 'string' },
|
|
100
|
+
timeoutMs: { type: 'integer', minimum: 1 },
|
|
76
101
|
retry429: {
|
|
77
|
-
type:
|
|
102
|
+
type: 'object',
|
|
78
103
|
properties: {
|
|
79
|
-
maxRetries: { type:
|
|
80
|
-
baseDelayMs: { type:
|
|
81
|
-
maxDelayMs: { type:
|
|
82
|
-
jitterRatio: { type:
|
|
83
|
-
respectRetryAfter: { type:
|
|
104
|
+
maxRetries: { type: 'integer', minimum: 0 },
|
|
105
|
+
baseDelayMs: { type: 'integer', minimum: 1 },
|
|
106
|
+
maxDelayMs: { type: 'integer', minimum: 1 },
|
|
107
|
+
jitterRatio: { type: 'number', minimum: 0, maximum: 1 },
|
|
108
|
+
respectRetryAfter: { type: 'boolean' },
|
|
84
109
|
},
|
|
85
110
|
additionalProperties: false,
|
|
86
111
|
},
|
|
87
112
|
},
|
|
88
|
-
required: [
|
|
113
|
+
required: ['apiName', 'endpointId'],
|
|
89
114
|
additionalProperties: false,
|
|
90
115
|
},
|
|
91
116
|
},
|
|
92
117
|
];
|
|
93
118
|
export async function startMcpServer(context) {
|
|
94
119
|
const server = new Server({
|
|
95
|
-
name:
|
|
96
|
-
version:
|
|
120
|
+
name: 'openapi-mcp',
|
|
121
|
+
version: '0.1.0',
|
|
97
122
|
}, {
|
|
98
123
|
capabilities: {
|
|
99
124
|
tools: {},
|
|
@@ -102,19 +127,21 @@ export async function startMcpServer(context) {
|
|
|
102
127
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
103
128
|
return { tools: [...TOOLS] };
|
|
104
129
|
});
|
|
105
|
-
server.setRequestHandler(CallToolRequestSchema,
|
|
130
|
+
server.setRequestHandler(CallToolRequestSchema,
|
|
131
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
132
|
+
async (request) => {
|
|
106
133
|
const toolName = request.params.name;
|
|
107
134
|
const args = request.params.arguments ?? {};
|
|
108
135
|
switch (toolName) {
|
|
109
|
-
case
|
|
136
|
+
case 'list_apis':
|
|
110
137
|
return listApisTool(context);
|
|
111
|
-
case
|
|
138
|
+
case 'list_api_endpoints':
|
|
112
139
|
return listApiEndpointsTool(context, args);
|
|
113
|
-
case
|
|
140
|
+
case 'get_api_endpoint':
|
|
114
141
|
return getApiEndpointTool(context, args);
|
|
115
|
-
case
|
|
142
|
+
case 'get_api_schema':
|
|
116
143
|
return getApiSchemaTool(context, args);
|
|
117
|
-
case
|
|
144
|
+
case 'make_endpoint_request':
|
|
118
145
|
return makeEndpointRequestTool(context, args);
|
|
119
146
|
default:
|
|
120
147
|
return fail(new Error(`Unknown tool: ${toolName}`));
|
package/dist/mcp/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EACL,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,GACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,KAAK,GAAG;IACZ;QACE,IAAI,EAAE,WAAW;QACjB,WAAW,EAAE,0DAA0D;QACvE,WAAW,EAAE;YACX,IAAI,EAAE,QA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QAAQ,EAAE,CAAC;YACjB,KAAK,WAAW;gBACd,OAAO,YAAY,CAAC,OAAO,CAAC,CAAC;YAC/B,KAAK,oBAAoB;gBACvB,OAAO,oBAAoB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC7C,KAAK,kBAAkB;gBACrB,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC3C,KAAK,gBAAgB;gBACnB,OAAO,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACzC,KAAK,uBAAuB;gBAC1B,OAAO,uBAAuB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAChD;gBACE,OAAO,IAAI,CAAC,IAAI,KAAK,CAAC,iBAAiB,QAAQ,EAAE,CAAC,CAAC,CAAC;QACxD,CAAC;IACH,CAAC,CACF,CAAC;IAEF,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { LoadedApi } from
|
|
2
|
-
import type { ToolContext } from
|
|
3
|
-
import { z } from
|
|
1
|
+
import type { LoadedApi } from '../../types.js';
|
|
2
|
+
import type { ToolContext } from '../context.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
4
|
export interface ToolResult {
|
|
5
5
|
isError?: boolean;
|
|
6
|
-
content:
|
|
7
|
-
type:
|
|
6
|
+
content: {
|
|
7
|
+
type: 'text';
|
|
8
8
|
text: string;
|
|
9
|
-
}
|
|
9
|
+
}[];
|
|
10
10
|
structuredContent?: unknown;
|
|
11
11
|
}
|
|
12
12
|
export declare function ok(data: unknown): ToolResult;
|
package/dist/mcp/tools/common.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { asErrorResponse, OpenApiMcpError } from
|
|
1
|
+
import { asErrorResponse, OpenApiMcpError } from '../../errors.js';
|
|
2
2
|
export function ok(data) {
|
|
3
3
|
return {
|
|
4
4
|
content: [
|
|
5
5
|
{
|
|
6
|
-
type:
|
|
7
|
-
text: JSON.stringify(data, null, 2)
|
|
8
|
-
}
|
|
6
|
+
type: 'text',
|
|
7
|
+
text: JSON.stringify(data, null, 2),
|
|
8
|
+
},
|
|
9
9
|
],
|
|
10
|
-
structuredContent: data
|
|
10
|
+
structuredContent: data,
|
|
11
11
|
};
|
|
12
12
|
}
|
|
13
13
|
export function fail(error) {
|
|
@@ -16,32 +16,33 @@ export function fail(error) {
|
|
|
16
16
|
isError: true,
|
|
17
17
|
content: [
|
|
18
18
|
{
|
|
19
|
-
type:
|
|
20
|
-
text: JSON.stringify(payload, null, 2)
|
|
21
|
-
}
|
|
19
|
+
type: 'text',
|
|
20
|
+
text: JSON.stringify(payload, null, 2),
|
|
21
|
+
},
|
|
22
22
|
],
|
|
23
|
-
structuredContent: payload
|
|
23
|
+
structuredContent: payload,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
export function requireApi(context, apiName) {
|
|
27
27
|
const api = context.registry.byName.get(apiName.toLowerCase());
|
|
28
28
|
if (!api) {
|
|
29
|
-
throw new OpenApiMcpError(
|
|
29
|
+
throw new OpenApiMcpError('API_NOT_FOUND', `Unknown API '${apiName}'`);
|
|
30
30
|
}
|
|
31
31
|
return api;
|
|
32
32
|
}
|
|
33
33
|
export function parseInput(args, schema) {
|
|
34
34
|
const parsed = schema.safeParse(args ?? {});
|
|
35
35
|
if (parsed.success) {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
36
37
|
return parsed.data;
|
|
37
38
|
}
|
|
38
39
|
const issue = parsed.error.issues[0];
|
|
39
|
-
const path = issue.path.length ? issue.path.join(
|
|
40
|
-
throw new OpenApiMcpError(
|
|
40
|
+
const path = issue.path.length ? issue.path.join('.') : 'arguments';
|
|
41
|
+
throw new OpenApiMcpError('REQUEST_ERROR', `${path}: ${issue.message}`, {
|
|
41
42
|
issues: parsed.error.issues.map((item) => ({
|
|
42
43
|
path: item.path,
|
|
43
|
-
message: item.message
|
|
44
|
-
}))
|
|
44
|
+
message: item.message,
|
|
45
|
+
})),
|
|
45
46
|
});
|
|
46
47
|
}
|
|
47
48
|
export function toStringMap(value) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../../src/mcp/tools/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAWnE,MAAM,UAAU,EAAE,CAAC,IAAa;IAC9B,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;aACpC;SACF;QACD,iBAAiB,EAAE,IAAI;KACxB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,KAAc;IACjC,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,OAAO;QACL,OAAO,EAAE,IAAI;QACb,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;aACvC;SACF;QACD,iBAAiB,EAAE,OAAO;KAC3B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,OAAoB,EAAE,OAAe;IAC9D,MAAM,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IAC/D,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,eAAe,CAAC,eAAe,EAAE,gBAAgB,OAAO,GAAG,CAAC,CAAC;IACzE,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,IAAa,EACb,MAAS;IAET,M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C,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;IACpE,MAAM,IAAI,eAAe,CAAC,eAAe,EAAE,GAAG,IAAI,KAAK,KAAK,CAAC,OAAO,EAAE,EAAE;QACtE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACzC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;KACJ,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,WAAW,CACzB,KAAiD;IAEjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAChD,IAAI,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YACxC,SAAS;QACX,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAiC,CAAC,CAAC;IACvD,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ToolContext } from
|
|
2
|
-
import { type ToolResult } from
|
|
1
|
+
import type { ToolContext } from '../context.js';
|
|
2
|
+
import { type ToolResult } from './common.js';
|
|
3
3
|
export declare function getApiEndpointTool(context: ToolContext, args: unknown): Promise<ToolResult>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { OpenApiMcpError } from
|
|
2
|
-
import { z } from
|
|
3
|
-
import { fail, ok, parseInput, requireApi } from
|
|
1
|
+
import { OpenApiMcpError } from '../../errors.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { fail, ok, parseInput, requireApi } from './common.js';
|
|
4
4
|
const getApiEndpointInputSchema = z
|
|
5
5
|
.object({
|
|
6
6
|
apiName: z.string().min(1),
|
|
7
|
-
endpointId: z.string().min(1)
|
|
7
|
+
endpointId: z.string().min(1),
|
|
8
8
|
})
|
|
9
9
|
.strict();
|
|
10
10
|
export async function getApiEndpointTool(context, args) {
|
|
@@ -15,12 +15,15 @@ export async function getApiEndpointTool(context, args) {
|
|
|
15
15
|
const api = requireApi(context, apiName);
|
|
16
16
|
const endpoint = api.endpointById.get(endpointId);
|
|
17
17
|
if (!endpoint) {
|
|
18
|
-
throw new OpenApiMcpError(
|
|
19
|
-
apiName
|
|
18
|
+
throw new OpenApiMcpError('ENDPOINT_NOT_FOUND', `Unknown endpoint '${endpointId}'`, {
|
|
19
|
+
apiName,
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
-
const parameters = [
|
|
23
|
-
.
|
|
22
|
+
const parameters = [
|
|
23
|
+
...(endpoint.pathItem.parameters ?? []),
|
|
24
|
+
...(endpoint.operation.parameters ?? []),
|
|
25
|
+
]
|
|
26
|
+
.filter((item) => !('$ref' in item))
|
|
24
27
|
.map((param) => ({
|
|
25
28
|
name: param.name,
|
|
26
29
|
in: param.in,
|
|
@@ -28,11 +31,11 @@ export async function getApiEndpointTool(context, args) {
|
|
|
28
31
|
description: param.description,
|
|
29
32
|
style: param.style,
|
|
30
33
|
explode: param.explode,
|
|
31
|
-
schema: param.schema
|
|
34
|
+
schema: param.schema,
|
|
32
35
|
}));
|
|
33
|
-
const requestContentTypes = Object.keys(endpoint.operation.requestBody &&
|
|
36
|
+
const requestContentTypes = Object.keys(endpoint.operation.requestBody && '$ref' in endpoint.operation.requestBody
|
|
34
37
|
? {}
|
|
35
|
-
: endpoint.operation.requestBody?.content ?? {});
|
|
38
|
+
: (endpoint.operation.requestBody?.content ?? {}));
|
|
36
39
|
return ok({
|
|
37
40
|
endpointId: endpoint.endpointId,
|
|
38
41
|
method: endpoint.method,
|
|
@@ -43,13 +46,14 @@ export async function getApiEndpointTool(context, args) {
|
|
|
43
46
|
tags: endpoint.tags ?? [],
|
|
44
47
|
parameters,
|
|
45
48
|
requestBody: {
|
|
46
|
-
required: endpoint.operation.requestBody &&
|
|
47
|
-
|
|
49
|
+
required: endpoint.operation.requestBody &&
|
|
50
|
+
!('$ref' in endpoint.operation.requestBody)
|
|
51
|
+
? (endpoint.operation.requestBody.required ?? false)
|
|
48
52
|
: false,
|
|
49
|
-
contentTypes: requestContentTypes
|
|
53
|
+
contentTypes: requestContentTypes,
|
|
50
54
|
},
|
|
51
55
|
responses: endpoint.operation.responses,
|
|
52
|
-
security: endpoint.operation.security ?? api.schema.security ?? []
|
|
56
|
+
security: endpoint.operation.security ?? api.schema.security ?? [],
|
|
53
57
|
});
|
|
54
58
|
}
|
|
55
59
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getApiEndpoint.js","sourceRoot":"","sources":["../../../src/mcp/tools/getApiEndpoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAEhF,MAAM,yBAAyB,GAAG,CAAC;KAChC,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;CAC9B,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,CAAC,KAAK,UAAU,kBAAkB,
|
|
1
|
+
{"version":3,"file":"getApiEndpoint.js","sourceRoot":"","sources":["../../../src/mcp/tools/getApiEndpoint.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,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,IAAI,GAAG,CAAC,MAAM,CAAC,QAAQ,IAAI,EAAE;SACnE,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ToolContext } from
|
|
2
|
-
import { type ToolResult } from
|
|
1
|
+
import type { ToolContext } from '../context.js';
|
|
2
|
+
import { type ToolResult } from './common.js';
|
|
3
3
|
export declare function getApiSchemaTool(context: ToolContext, args: unknown): Promise<ToolResult>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { getByJsonPointer } from
|
|
2
|
-
import { z } from
|
|
3
|
-
import { fail, ok, parseInput, requireApi } from
|
|
1
|
+
import { getByJsonPointer } from '../../openapi/jsonPointer.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { fail, ok, parseInput, requireApi } from './common.js';
|
|
4
4
|
const getApiSchemaInputSchema = z
|
|
5
5
|
.object({
|
|
6
6
|
apiName: z.string().min(1),
|
|
7
|
-
pointer: z.string().optional()
|
|
7
|
+
pointer: z.string().optional(),
|
|
8
8
|
})
|
|
9
9
|
.strict();
|
|
10
10
|
export async function getApiSchemaTool(context, args) {
|
|
@@ -16,8 +16,8 @@ export async function getApiSchemaTool(context, args) {
|
|
|
16
16
|
const schema = getByJsonPointer(api.schema, pointer);
|
|
17
17
|
return ok({
|
|
18
18
|
apiName: api.config.name,
|
|
19
|
-
pointer: pointer ??
|
|
20
|
-
schema
|
|
19
|
+
pointer: pointer ?? '',
|
|
20
|
+
schema,
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getApiSchema.js","sourceRoot":"","sources":["../../../src/mcp/tools/getApiSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AA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,gBAAgB,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAErD,OAAO,EAAE,CAAC;YACR,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI;YACxB,OAAO,EAAE,OAAO,IAAI,EAAE;YACtB,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { getApiEndpointTool } from
|
|
2
|
-
export { getApiSchemaTool } from
|
|
3
|
-
export { listApiEndpointsTool } from
|
|
4
|
-
export { listApisTool } from
|
|
5
|
-
export { makeEndpointRequestTool } from
|
|
1
|
+
export { getApiEndpointTool } from './getApiEndpoint.js';
|
|
2
|
+
export { getApiSchemaTool } from './getApiSchema.js';
|
|
3
|
+
export { listApiEndpointsTool } from './listApiEndpoints.js';
|
|
4
|
+
export { listApisTool } from './listApis.js';
|
|
5
|
+
export { makeEndpointRequestTool } from './makeEndpointRequest.js';
|
package/dist/mcp/tools/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { getApiEndpointTool } from
|
|
2
|
-
export { getApiSchemaTool } from
|
|
3
|
-
export { listApiEndpointsTool } from
|
|
4
|
-
export { listApisTool } from
|
|
5
|
-
export { makeEndpointRequestTool } from
|
|
1
|
+
export { getApiEndpointTool } from './getApiEndpoint.js';
|
|
2
|
+
export { getApiSchemaTool } from './getApiSchema.js';
|
|
3
|
+
export { listApiEndpointsTool } from './listApiEndpoints.js';
|
|
4
|
+
export { listApisTool } from './listApis.js';
|
|
5
|
+
export { makeEndpointRequestTool } from './makeEndpointRequest.js';
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ToolContext } from
|
|
2
|
-
import { type ToolResult } from
|
|
1
|
+
import type { ToolContext } from '../context.js';
|
|
2
|
+
import { type ToolResult } from './common.js';
|
|
3
3
|
export declare function listApiEndpointsTool(context: ToolContext, args: unknown): Promise<ToolResult>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { z } from
|
|
2
|
-
import { fail, ok, parseInput, requireApi } from
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { fail, ok, parseInput, requireApi } from './common.js';
|
|
3
3
|
const listApiEndpointsInputSchema = z
|
|
4
4
|
.object({
|
|
5
5
|
apiName: z.string().min(1),
|
|
@@ -20,7 +20,7 @@ export async function listApiEndpointsTool(context, args) {
|
|
|
20
20
|
const pathContains = input.pathContains;
|
|
21
21
|
const searchTerms = input.search?.map((s) => s.trim().toLowerCase()) ?? [];
|
|
22
22
|
const limit = Math.min(input.limit ?? 50, 200);
|
|
23
|
-
const offset = typeof input.cursor ===
|
|
23
|
+
const offset = typeof input.cursor === 'string' && input.cursor.trim()
|
|
24
24
|
? Number.parseInt(input.cursor, 10)
|
|
25
25
|
: 0;
|
|
26
26
|
const filtered = api.endpoints.filter((endpoint) => {
|
|
@@ -43,7 +43,7 @@ export async function listApiEndpointsTool(context, args) {
|
|
|
43
43
|
endpoint.description,
|
|
44
44
|
...(endpoint.tags ?? []),
|
|
45
45
|
]
|
|
46
|
-
.filter((value) => typeof value ===
|
|
46
|
+
.filter((value) => typeof value === 'string')
|
|
47
47
|
.map((value) => value.toLowerCase());
|
|
48
48
|
// Check if ANY search term matches any field in the haystack (OR logic)
|
|
49
49
|
const matchesAnyTerm = searchTerms.some((term) => haystack.some((value) => value.includes(term)));
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ToolContext } from
|
|
2
|
-
import { type ToolResult } from
|
|
1
|
+
import type { ToolContext } from '../context.js';
|
|
2
|
+
import { type ToolResult } from './common.js';
|
|
3
3
|
export declare function listApisTool(context: ToolContext): Promise<ToolResult>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fail, ok } from
|
|
1
|
+
import { fail, ok } from './common.js';
|
|
2
2
|
export async function listApisTool(context) {
|
|
3
3
|
try {
|
|
4
4
|
const apis = [...context.registry.byName.values()].map((api) => ({
|
|
@@ -7,7 +7,7 @@ export async function listApisTool(context) {
|
|
|
7
7
|
version: api.schema.info?.version,
|
|
8
8
|
baseUrl: api.baseUrl,
|
|
9
9
|
specPath: api.schemaPath,
|
|
10
|
-
authSchemes: api.authSchemeNames
|
|
10
|
+
authSchemes: api.authSchemeNames,
|
|
11
11
|
}));
|
|
12
12
|
return ok({ apis });
|
|
13
13
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { ToolContext } from
|
|
2
|
-
import { type ToolResult } from
|
|
1
|
+
import type { ToolContext } from '../context.js';
|
|
2
|
+
import { type ToolResult } from './common.js';
|
|
3
3
|
export declare function makeEndpointRequestTool(context: ToolContext, args: unknown): Promise<ToolResult>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { executeEndpointRequest } from
|
|
2
|
-
import { OpenApiMcpError } from
|
|
3
|
-
import { z } from
|
|
4
|
-
import { fail, ok, parseInput, requireApi, toStringMap } from
|
|
1
|
+
import { executeEndpointRequest } from '../../http/requestExecutor.js';
|
|
2
|
+
import { OpenApiMcpError } from '../../errors.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { fail, ok, parseInput, requireApi, toStringMap, } from './common.js';
|
|
5
5
|
const makeEndpointRequestInputSchema = z
|
|
6
6
|
.object({
|
|
7
7
|
apiName: z.string().min(1),
|
|
@@ -11,20 +11,19 @@ const makeEndpointRequestInputSchema = z
|
|
|
11
11
|
headers: z.record(z.unknown()).nullable().optional(),
|
|
12
12
|
cookies: z.record(z.unknown()).nullable().optional(),
|
|
13
13
|
body: z.unknown().optional(),
|
|
14
|
+
files: z
|
|
15
|
+
.record(z.object({
|
|
16
|
+
name: z.string().optional(),
|
|
17
|
+
contentType: z.string().optional(),
|
|
18
|
+
base64: z.string().optional(),
|
|
19
|
+
text: z.string().optional(),
|
|
20
|
+
filePath: z.string().optional(),
|
|
21
|
+
}))
|
|
22
|
+
.optional(),
|
|
14
23
|
contentType: z.string().optional(),
|
|
15
24
|
accept: z.string().optional(),
|
|
16
25
|
timeoutMs: z.number().int().positive().optional(),
|
|
17
|
-
|
|
18
|
-
.object({
|
|
19
|
-
maxRetries: z.number().int().nonnegative().optional(),
|
|
20
|
-
baseDelayMs: z.number().int().positive().optional(),
|
|
21
|
-
maxDelayMs: z.number().int().positive().optional(),
|
|
22
|
-
jitterRatio: z.number().min(0).max(1).optional(),
|
|
23
|
-
respectRetryAfter: z.boolean().optional()
|
|
24
|
-
})
|
|
25
|
-
.strict()
|
|
26
|
-
.nullable()
|
|
27
|
-
.optional()
|
|
26
|
+
maxRetries429: z.number().int().nonnegative().optional(),
|
|
28
27
|
})
|
|
29
28
|
.strict();
|
|
30
29
|
export async function makeEndpointRequestTool(context, args) {
|
|
@@ -35,8 +34,8 @@ export async function makeEndpointRequestTool(context, args) {
|
|
|
35
34
|
const api = requireApi(context, apiName);
|
|
36
35
|
const endpoint = api.endpointById.get(endpointId);
|
|
37
36
|
if (!endpoint) {
|
|
38
|
-
throw new OpenApiMcpError(
|
|
39
|
-
apiName
|
|
37
|
+
throw new OpenApiMcpError('ENDPOINT_NOT_FOUND', `Unknown endpoint '${endpointId}'`, {
|
|
38
|
+
apiName,
|
|
40
39
|
});
|
|
41
40
|
}
|
|
42
41
|
const result = await executeEndpointRequest({
|
|
@@ -47,12 +46,15 @@ export async function makeEndpointRequestTool(context, args) {
|
|
|
47
46
|
headers: toStringMap(input.headers),
|
|
48
47
|
cookies: toStringMap(input.cookies),
|
|
49
48
|
body: input.body,
|
|
49
|
+
files: input.files,
|
|
50
50
|
contentType: input.contentType,
|
|
51
51
|
accept: input.accept,
|
|
52
52
|
timeoutMs: input.timeoutMs,
|
|
53
|
-
retry429: input.
|
|
53
|
+
retry429: input.maxRetries429 !== undefined
|
|
54
|
+
? { maxRetries: input.maxRetries429 }
|
|
55
|
+
: undefined,
|
|
54
56
|
oauthClient: context.oauthClient,
|
|
55
|
-
env: context.env
|
|
57
|
+
env: context.env,
|
|
56
58
|
});
|
|
57
59
|
return ok(result);
|
|
58
60
|
}
|