openapi-dynamic-mcp 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.
- package/LICENSE +21 -0
- package/README.md +247 -0
- package/dist/auth/env.d.ts +14 -0
- package/dist/auth/env.js +64 -0
- package/dist/auth/env.js.map +1 -0
- package/dist/auth/oauthClient.d.ts +12 -0
- package/dist/auth/oauthClient.js +55 -0
- package/dist/auth/oauthClient.js.map +1 -0
- package/dist/auth/resolveAuth.d.ts +10 -0
- package/dist/auth/resolveAuth.js +118 -0
- package/dist/auth/resolveAuth.js.map +1 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +50 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/loadConfig.d.ts +2 -0
- package/dist/config/loadConfig.js +89 -0
- package/dist/config/loadConfig.js.map +1 -0
- package/dist/errors.d.ts +11 -0
- package/dist/errors.js +31 -0
- package/dist/errors.js.map +1 -0
- package/dist/http/requestExecutor.d.ts +19 -0
- package/dist/http/requestExecutor.js +342 -0
- package/dist/http/requestExecutor.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/context.d.ts +7 -0
- package/dist/mcp/context.js +2 -0
- package/dist/mcp/context.js.map +1 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.js +125 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/tools/common.d.ts +16 -0
- package/dist/mcp/tools/common.js +60 -0
- package/dist/mcp/tools/common.js.map +1 -0
- package/dist/mcp/tools/getApiEndpoint.d.ts +3 -0
- package/dist/mcp/tools/getApiEndpoint.js +59 -0
- package/dist/mcp/tools/getApiEndpoint.js.map +1 -0
- package/dist/mcp/tools/getApiSchema.d.ts +3 -0
- package/dist/mcp/tools/getApiSchema.js +27 -0
- package/dist/mcp/tools/getApiSchema.js.map +1 -0
- package/dist/mcp/tools/index.d.ts +5 -0
- package/dist/mcp/tools/index.js +6 -0
- package/dist/mcp/tools/index.js.map +1 -0
- package/dist/mcp/tools/listApiEndpoints.d.ts +3 -0
- package/dist/mcp/tools/listApiEndpoints.js +55 -0
- package/dist/mcp/tools/listApiEndpoints.js.map +1 -0
- package/dist/mcp/tools/listApis.d.ts +3 -0
- package/dist/mcp/tools/listApis.js +18 -0
- package/dist/mcp/tools/listApis.js.map +1 -0
- package/dist/mcp/tools/makeEndpointRequest.d.ts +3 -0
- package/dist/mcp/tools/makeEndpointRequest.js +63 -0
- package/dist/mcp/tools/makeEndpointRequest.js.map +1 -0
- package/dist/openapi/endpointIndex.d.ts +6 -0
- package/dist/openapi/endpointIndex.js +75 -0
- package/dist/openapi/endpointIndex.js.map +1 -0
- package/dist/openapi/jsonPointer.d.ts +1 -0
- package/dist/openapi/jsonPointer.js +40 -0
- package/dist/openapi/jsonPointer.js.map +1 -0
- package/dist/openapi/loadSpec.d.ts +2 -0
- package/dist/openapi/loadSpec.js +67 -0
- package/dist/openapi/loadSpec.js.map +1 -0
- package/dist/types.d.ts +98 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1,125 @@
|
|
|
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
|
+
const TOOLS = [
|
|
7
|
+
{
|
|
8
|
+
name: "list_apis",
|
|
9
|
+
description: "List configured APIs loaded from the YAML configuration.",
|
|
10
|
+
inputSchema: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: {},
|
|
13
|
+
additionalProperties: false
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "list_api_endpoints",
|
|
18
|
+
description: "List endpoints from a specific API with optional filters.",
|
|
19
|
+
inputSchema: {
|
|
20
|
+
type: "object",
|
|
21
|
+
properties: {
|
|
22
|
+
apiName: { type: "string" },
|
|
23
|
+
method: { type: "string" },
|
|
24
|
+
tag: { type: "string" },
|
|
25
|
+
pathContains: { type: "string" },
|
|
26
|
+
limit: { type: "integer", minimum: 1 },
|
|
27
|
+
cursor: { type: "string" }
|
|
28
|
+
},
|
|
29
|
+
required: ["apiName"],
|
|
30
|
+
additionalProperties: false
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "get_api_endpoint",
|
|
35
|
+
description: "Get details for one endpoint in a specific API.",
|
|
36
|
+
inputSchema: {
|
|
37
|
+
type: "object",
|
|
38
|
+
properties: {
|
|
39
|
+
apiName: { type: "string" },
|
|
40
|
+
endpointId: { type: "string" }
|
|
41
|
+
},
|
|
42
|
+
required: ["apiName", "endpointId"],
|
|
43
|
+
additionalProperties: false
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "get_api_schema",
|
|
48
|
+
description: "Get the full dereferenced API schema or a JSON pointer fragment.",
|
|
49
|
+
inputSchema: {
|
|
50
|
+
type: "object",
|
|
51
|
+
properties: {
|
|
52
|
+
apiName: { type: "string" },
|
|
53
|
+
pointer: { type: "string" }
|
|
54
|
+
},
|
|
55
|
+
required: ["apiName"],
|
|
56
|
+
additionalProperties: false
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "make_endpoint_request",
|
|
61
|
+
description: "Execute an HTTP request for an endpoint by endpointId.",
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: "object",
|
|
64
|
+
properties: {
|
|
65
|
+
apiName: { type: "string" },
|
|
66
|
+
endpointId: { type: "string" },
|
|
67
|
+
pathParams: { type: "object" },
|
|
68
|
+
query: { type: "object" },
|
|
69
|
+
headers: { type: "object", additionalProperties: { type: "string" } },
|
|
70
|
+
cookies: { type: "object", additionalProperties: { type: "string" } },
|
|
71
|
+
body: {},
|
|
72
|
+
contentType: { type: "string" },
|
|
73
|
+
accept: { type: "string" },
|
|
74
|
+
timeoutMs: { type: "integer", minimum: 1 },
|
|
75
|
+
retry429: {
|
|
76
|
+
type: "object",
|
|
77
|
+
properties: {
|
|
78
|
+
maxRetries: { type: "integer", minimum: 0 },
|
|
79
|
+
baseDelayMs: { type: "integer", minimum: 1 },
|
|
80
|
+
maxDelayMs: { type: "integer", minimum: 1 },
|
|
81
|
+
jitterRatio: { type: "number", minimum: 0, maximum: 1 },
|
|
82
|
+
respectRetryAfter: { type: "boolean" }
|
|
83
|
+
},
|
|
84
|
+
additionalProperties: false
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
required: ["apiName", "endpointId"],
|
|
88
|
+
additionalProperties: false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
];
|
|
92
|
+
export async function startMcpServer(context) {
|
|
93
|
+
const server = new Server({
|
|
94
|
+
name: "openapi-mcp",
|
|
95
|
+
version: "0.1.0"
|
|
96
|
+
}, {
|
|
97
|
+
capabilities: {
|
|
98
|
+
tools: {}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
102
|
+
return { tools: [...TOOLS] };
|
|
103
|
+
});
|
|
104
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
105
|
+
const toolName = request.params.name;
|
|
106
|
+
const args = request.params.arguments ?? {};
|
|
107
|
+
switch (toolName) {
|
|
108
|
+
case "list_apis":
|
|
109
|
+
return listApisTool(context);
|
|
110
|
+
case "list_api_endpoints":
|
|
111
|
+
return listApiEndpointsTool(context, args);
|
|
112
|
+
case "get_api_endpoint":
|
|
113
|
+
return getApiEndpointTool(context, args);
|
|
114
|
+
case "get_api_schema":
|
|
115
|
+
return getApiSchemaTool(context, args);
|
|
116
|
+
case "make_endpoint_request":
|
|
117
|
+
return makeEndpointRequestTool(context, args);
|
|
118
|
+
default:
|
|
119
|
+
return fail(new Error(`Unknown tool: ${toolName}`));
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
const transport = new StdioServerTransport();
|
|
123
|
+
await server.connect(transport);
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +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,EACvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EACL,kBAAkB,EAClB,gBAAgB,EAChB,oBAAoB,EACpB,YAAY,EACZ,uBAAuB,EACxB,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,QAAQ;YACd,UAAU,EAAE,EAAE;YACd,oBAAoB,EAAE,KAAK;SAC5B;KACF;IACD;QACE,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EAAE,2DAA2D;QACxE,WAAW,EAAE;YACX,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC3B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAC1B,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBACvB,YAAY,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;gBAChC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAA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AC,qBAAqB,EAAE,KAAK,EAAE,OAAO,EAAgB,EAAE;QAC9E,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC;QACrC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,IAAI,EAAE,CAAC;QAE5C,QAAQ,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,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { LoadedApi } from "../../types.js";
|
|
2
|
+
import type { ToolContext } from "../context.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
export interface ToolResult {
|
|
5
|
+
isError?: boolean;
|
|
6
|
+
content: Array<{
|
|
7
|
+
type: "text";
|
|
8
|
+
text: string;
|
|
9
|
+
}>;
|
|
10
|
+
structuredContent?: unknown;
|
|
11
|
+
}
|
|
12
|
+
export declare function ok(data: unknown): ToolResult;
|
|
13
|
+
export declare function fail(error: unknown): ToolResult;
|
|
14
|
+
export declare function requireApi(context: ToolContext, apiName: string): LoadedApi;
|
|
15
|
+
export declare function parseInput<T extends z.ZodTypeAny>(args: unknown, schema: T): z.infer<T>;
|
|
16
|
+
export declare function toStringMap(value: Record<string, unknown> | undefined | null): Record<string, string>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { asErrorResponse, OpenApiMcpError } from "../../errors.js";
|
|
2
|
+
export function ok(data) {
|
|
3
|
+
return {
|
|
4
|
+
content: [
|
|
5
|
+
{
|
|
6
|
+
type: "text",
|
|
7
|
+
text: JSON.stringify(data, null, 2)
|
|
8
|
+
}
|
|
9
|
+
],
|
|
10
|
+
structuredContent: data
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export function fail(error) {
|
|
14
|
+
const payload = asErrorResponse(error);
|
|
15
|
+
return {
|
|
16
|
+
isError: true,
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
type: "text",
|
|
20
|
+
text: JSON.stringify(payload, null, 2)
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
structuredContent: payload
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export function requireApi(context, apiName) {
|
|
27
|
+
const api = context.registry.byName.get(apiName.toLowerCase());
|
|
28
|
+
if (!api) {
|
|
29
|
+
throw new OpenApiMcpError("API_NOT_FOUND", `Unknown API '${apiName}'`);
|
|
30
|
+
}
|
|
31
|
+
return api;
|
|
32
|
+
}
|
|
33
|
+
export function parseInput(args, schema) {
|
|
34
|
+
const parsed = schema.safeParse(args ?? {});
|
|
35
|
+
if (parsed.success) {
|
|
36
|
+
return parsed.data;
|
|
37
|
+
}
|
|
38
|
+
const issue = parsed.error.issues[0];
|
|
39
|
+
const path = issue.path.length ? issue.path.join(".") : "arguments";
|
|
40
|
+
throw new OpenApiMcpError("REQUEST_ERROR", `${path}: ${issue.message}`, {
|
|
41
|
+
issues: parsed.error.issues.map((item) => ({
|
|
42
|
+
path: item.path,
|
|
43
|
+
message: item.message
|
|
44
|
+
}))
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function toStringMap(value) {
|
|
48
|
+
if (!value) {
|
|
49
|
+
return {};
|
|
50
|
+
}
|
|
51
|
+
const out = {};
|
|
52
|
+
for (const [key, item] of Object.entries(value)) {
|
|
53
|
+
if (item === undefined || item === null) {
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
out[key] = String(item);
|
|
57
|
+
}
|
|
58
|
+
return out;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +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,eA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C,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { OpenApiMcpError } from "../../errors.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { fail, ok, parseInput, requireApi } from "./common.js";
|
|
4
|
+
const getApiEndpointInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
apiName: z.string().min(1),
|
|
7
|
+
endpointId: z.string().min(1)
|
|
8
|
+
})
|
|
9
|
+
.strict();
|
|
10
|
+
export async function getApiEndpointTool(context, args) {
|
|
11
|
+
try {
|
|
12
|
+
const input = parseInput(args, getApiEndpointInputSchema);
|
|
13
|
+
const apiName = input.apiName;
|
|
14
|
+
const endpointId = input.endpointId;
|
|
15
|
+
const api = requireApi(context, apiName);
|
|
16
|
+
const endpoint = api.endpointById.get(endpointId);
|
|
17
|
+
if (!endpoint) {
|
|
18
|
+
throw new OpenApiMcpError("ENDPOINT_NOT_FOUND", `Unknown endpoint '${endpointId}'`, {
|
|
19
|
+
apiName
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const parameters = [...(endpoint.pathItem.parameters ?? []), ...(endpoint.operation.parameters ?? [])]
|
|
23
|
+
.filter((item) => !("$ref" in item))
|
|
24
|
+
.map((param) => ({
|
|
25
|
+
name: param.name,
|
|
26
|
+
in: param.in,
|
|
27
|
+
required: param.required ?? false,
|
|
28
|
+
description: param.description,
|
|
29
|
+
style: param.style,
|
|
30
|
+
explode: param.explode,
|
|
31
|
+
schema: param.schema
|
|
32
|
+
}));
|
|
33
|
+
const requestContentTypes = Object.keys(endpoint.operation.requestBody && "$ref" in endpoint.operation.requestBody
|
|
34
|
+
? {}
|
|
35
|
+
: endpoint.operation.requestBody?.content ?? {});
|
|
36
|
+
return ok({
|
|
37
|
+
endpointId: endpoint.endpointId,
|
|
38
|
+
method: endpoint.method,
|
|
39
|
+
path: endpoint.path,
|
|
40
|
+
operationId: endpoint.operationId,
|
|
41
|
+
summary: endpoint.summary,
|
|
42
|
+
description: endpoint.description,
|
|
43
|
+
tags: endpoint.tags ?? [],
|
|
44
|
+
parameters,
|
|
45
|
+
requestBody: {
|
|
46
|
+
required: endpoint.operation.requestBody && !("$ref" in endpoint.operation.requestBody)
|
|
47
|
+
? endpoint.operation.requestBody.required ?? false
|
|
48
|
+
: false,
|
|
49
|
+
contentTypes: requestContentTypes
|
|
50
|
+
},
|
|
51
|
+
responses: endpoint.operation.responses,
|
|
52
|
+
security: endpoint.operation.security ?? api.schema.security ?? []
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
return fail(error);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=getApiEndpoint.js.map
|
|
@@ -0,0 +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,CAAC,OAAoB,EAAE,IAAa;IAC1E,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,yBAAyB,CAAC,CAAC;QAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B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AC,UAAU;YAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,IAAI,EAAE,QAAQ,CAAC,IAAI;YACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;YACzB,WAAW,EAAE,QAAQ,CAAC,WAAW;YACjC,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE;YACzB,UAAU;YACV,WAAW,EAAE;gBACX,QAAQ,EACN,QAAQ,CAAC,SAAS,CAAC,WAAW,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC;oBAC3E,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC,WAAW,CAAC,QAAQ,IAAI,KAAK;oBAClD,CAAC,CAAC,KAAK;gBACX,YAAY,EAAE,mBAAmB;aAClC;YACD,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,SAAS;YACvC,QAAQ,EAAE,QAAQ,CAAC,SAAS,CAAC,QAAQ,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"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { getByJsonPointer } from "../../openapi/jsonPointer.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { fail, ok, parseInput, requireApi } from "./common.js";
|
|
4
|
+
const getApiSchemaInputSchema = z
|
|
5
|
+
.object({
|
|
6
|
+
apiName: z.string().min(1),
|
|
7
|
+
pointer: z.string().optional()
|
|
8
|
+
})
|
|
9
|
+
.strict();
|
|
10
|
+
export async function getApiSchemaTool(context, args) {
|
|
11
|
+
try {
|
|
12
|
+
const input = parseInput(args, getApiSchemaInputSchema);
|
|
13
|
+
const apiName = input.apiName;
|
|
14
|
+
const pointer = input.pointer;
|
|
15
|
+
const api = requireApi(context, apiName);
|
|
16
|
+
const schema = getByJsonPointer(api.schema, pointer);
|
|
17
|
+
return ok({
|
|
18
|
+
apiName: api.config.name,
|
|
19
|
+
pointer: pointer ?? "",
|
|
20
|
+
schema
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
return fail(error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=getApiSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getApiSchema.js","sourceRoot":"","sources":["../../../src/mcp/tools/getApiSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,UAAU,EAAE,UAAU,EAAmB,MAAM,aAAa,CAAC;AAEhF,MAAM,uBAAuB,GAAG,CAAC;KAC9B,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,OAAoB,EAAE,IAAa;IACxE,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,uBAAuB,CAAC,CAAC;QACxD,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC;QAE9B,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACzC,MAAM,MAAM,GAAG,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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
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";
|
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcp/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { fail, ok, parseInput, requireApi } from "./common.js";
|
|
3
|
+
const listApiEndpointsInputSchema = z
|
|
4
|
+
.object({
|
|
5
|
+
apiName: z.string().min(1),
|
|
6
|
+
method: z.string().optional(),
|
|
7
|
+
tag: z.string().optional(),
|
|
8
|
+
pathContains: z.string().optional(),
|
|
9
|
+
limit: z.number().int().positive().optional(),
|
|
10
|
+
cursor: z.string().optional()
|
|
11
|
+
})
|
|
12
|
+
.strict();
|
|
13
|
+
export async function listApiEndpointsTool(context, args) {
|
|
14
|
+
try {
|
|
15
|
+
const input = parseInput(args, listApiEndpointsInputSchema);
|
|
16
|
+
const api = requireApi(context, input.apiName);
|
|
17
|
+
const methodFilter = input.method?.toLowerCase();
|
|
18
|
+
const tagFilter = input.tag;
|
|
19
|
+
const pathContains = input.pathContains;
|
|
20
|
+
const limit = Math.min(input.limit ?? 50, 200);
|
|
21
|
+
const offset = typeof input.cursor === "string" && input.cursor.trim()
|
|
22
|
+
? Number.parseInt(input.cursor, 10)
|
|
23
|
+
: 0;
|
|
24
|
+
const filtered = api.endpoints.filter((endpoint) => {
|
|
25
|
+
if (methodFilter && endpoint.method !== methodFilter) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
if (tagFilter && !(endpoint.tags ?? []).includes(tagFilter)) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
if (pathContains && !endpoint.path.includes(pathContains)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
const safeOffset = Number.isFinite(offset) && offset >= 0 ? offset : 0;
|
|
37
|
+
const paged = filtered.slice(safeOffset, safeOffset + limit);
|
|
38
|
+
const nextOffset = safeOffset + paged.length;
|
|
39
|
+
return ok({
|
|
40
|
+
endpoints: paged.map((endpoint) => ({
|
|
41
|
+
endpointId: endpoint.endpointId,
|
|
42
|
+
method: endpoint.method,
|
|
43
|
+
path: endpoint.path,
|
|
44
|
+
operationId: endpoint.operationId,
|
|
45
|
+
summary: endpoint.summary,
|
|
46
|
+
tags: endpoint.tags ?? []
|
|
47
|
+
})),
|
|
48
|
+
nextCursor: nextOffset < filtered.length ? String(nextOffset) : undefined
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return fail(error);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=listApiEndpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listApiEndpoints.js","sourceRoot":"","sources":["../../../src/mcp/tools/listApiEndpoints.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EACL,IAAI,EACJ,EAAE,EACF,UAAU,EACV,UAAU,EAEX,MAAM,aAAa,CAAC;AAErB,MAAM,2BAA2B,GAAG,CAAC;KAClC,MAAM,CAAC;IACN,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC1B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC7C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC9B,CAAC;KACD,MAAM,EAAE,CAAC;AAEZ,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,OAAoB,EACpB,IAAa;IAEb,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,UAAU,CAAC,IAAI,EAAE,2BAA2B,CAAC,CAAC;QAC5D,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAE/C,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,EAAE,WAAW,EAA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E7C,OAAO,EAAE,CAAC;YACR,SAAS,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAClC,UAAU,EAAE,QAAQ,CAAC,UAAU;gBAC/B,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,IAAI,EAAE,QAAQ,CAAC,IAAI;gBACnB,WAAW,EAAE,QAAQ,CAAC,WAAW;gBACjC,OAAO,EAAE,QAAQ,CAAC,OAAO;gBACzB,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE;aAC1B,CAAC,CAAC;YACH,UAAU,EAAE,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS;SAC1E,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { fail, ok } from "./common.js";
|
|
2
|
+
export async function listApisTool(context) {
|
|
3
|
+
try {
|
|
4
|
+
const apis = [...context.registry.byName.values()].map((api) => ({
|
|
5
|
+
name: api.config.name,
|
|
6
|
+
title: api.schema.info?.title,
|
|
7
|
+
version: api.schema.info?.version,
|
|
8
|
+
baseUrl: api.baseUrl,
|
|
9
|
+
specPath: api.schemaPath,
|
|
10
|
+
authSchemes: api.authSchemeNames
|
|
11
|
+
}));
|
|
12
|
+
return ok({ apis });
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
return fail(error);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=listApis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"listApis.js","sourceRoot":"","sources":["../../../src/mcp/tools/listApis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,EAAE,EAAmB,MAAM,aAAa,CAAC;AAExD,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,OAAoB;IACrD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,CAAC,GAAG,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC/D,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI;YACrB,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK;YAC7B,OAAO,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO;YACjC,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,QAAQ,EAAE,GAAG,CAAC,UAAU;YACxB,WAAW,EAAE,GAAG,CAAC,eAAe;SACjC,CAAC,CAAC,CAAC;QAEJ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
const makeEndpointRequestInputSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
apiName: z.string().min(1),
|
|
8
|
+
endpointId: z.string().min(1),
|
|
9
|
+
pathParams: z.record(z.unknown()).nullable().optional(),
|
|
10
|
+
query: z.record(z.unknown()).nullable().optional(),
|
|
11
|
+
headers: z.record(z.unknown()).nullable().optional(),
|
|
12
|
+
cookies: z.record(z.unknown()).nullable().optional(),
|
|
13
|
+
body: z.unknown().optional(),
|
|
14
|
+
contentType: z.string().optional(),
|
|
15
|
+
accept: z.string().optional(),
|
|
16
|
+
timeoutMs: z.number().int().positive().optional(),
|
|
17
|
+
retry429: z
|
|
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()
|
|
28
|
+
})
|
|
29
|
+
.strict();
|
|
30
|
+
export async function makeEndpointRequestTool(context, args) {
|
|
31
|
+
try {
|
|
32
|
+
const input = parseInput(args, makeEndpointRequestInputSchema);
|
|
33
|
+
const apiName = input.apiName;
|
|
34
|
+
const endpointId = input.endpointId;
|
|
35
|
+
const api = requireApi(context, apiName);
|
|
36
|
+
const endpoint = api.endpointById.get(endpointId);
|
|
37
|
+
if (!endpoint) {
|
|
38
|
+
throw new OpenApiMcpError("ENDPOINT_NOT_FOUND", `Unknown endpoint '${endpointId}'`, {
|
|
39
|
+
apiName
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const result = await executeEndpointRequest({
|
|
43
|
+
api,
|
|
44
|
+
endpoint,
|
|
45
|
+
pathParams: input.pathParams ?? {},
|
|
46
|
+
query: input.query ?? {},
|
|
47
|
+
headers: toStringMap(input.headers),
|
|
48
|
+
cookies: toStringMap(input.cookies),
|
|
49
|
+
body: input.body,
|
|
50
|
+
contentType: input.contentType,
|
|
51
|
+
accept: input.accept,
|
|
52
|
+
timeoutMs: input.timeoutMs,
|
|
53
|
+
retry429: input.retry429 ?? undefined,
|
|
54
|
+
oauthClient: context.oauthClient,
|
|
55
|
+
env: context.env
|
|
56
|
+
});
|
|
57
|
+
return ok(result);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return fail(error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMapp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AC,CAAC;QACL,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,sBAAsB,CAAC;YAC1C,GAAG;YACH,QAAQ;YACR,UAAU,EAAE,KAAK,CAAC,UAAU,IAAI,EAAE;YAClC,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,EAAE;YACxB,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;YACnC,OAAO,EAAE,WAAW,CAAC,KAAK,CAAC,OAAO,CAAC;YACnC,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,SAAS,EAAE,KAAK,CAAC,SAAS;YAC1B,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,SAAS;YACrC,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,GAAG,EAAE,OAAO,CAAC,GAAG;SACjB,CAAC,CAAC;QAEH,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;IACrB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { OpenAPIV3 } from "openapi-types";
|
|
2
|
+
import type { EndpointDefinition } from "../types.js";
|
|
3
|
+
export declare function buildEndpointIndex(document: OpenAPIV3.Document): {
|
|
4
|
+
endpoints: EndpointDefinition[];
|
|
5
|
+
endpointById: Map<string, EndpointDefinition>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { OpenApiMcpError } from "../errors.js";
|
|
2
|
+
const METHODS = [
|
|
3
|
+
"get",
|
|
4
|
+
"put",
|
|
5
|
+
"post",
|
|
6
|
+
"delete",
|
|
7
|
+
"options",
|
|
8
|
+
"head",
|
|
9
|
+
"patch",
|
|
10
|
+
"trace"
|
|
11
|
+
];
|
|
12
|
+
function normalizePathForId(path) {
|
|
13
|
+
return path.replace(/\s+/g, "").replace(/\/+$/, "") || "/";
|
|
14
|
+
}
|
|
15
|
+
export function buildEndpointIndex(document) {
|
|
16
|
+
const paths = document.paths ?? {};
|
|
17
|
+
const opIdCounts = new Map();
|
|
18
|
+
for (const path of Object.keys(paths)) {
|
|
19
|
+
const item = paths[path];
|
|
20
|
+
if (!item) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
for (const method of METHODS) {
|
|
24
|
+
const op = item[method];
|
|
25
|
+
if (op?.operationId) {
|
|
26
|
+
opIdCounts.set(op.operationId, (opIdCounts.get(op.operationId) ?? 0) + 1);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const endpoints = [];
|
|
31
|
+
const endpointById = new Map();
|
|
32
|
+
for (const path of Object.keys(paths)) {
|
|
33
|
+
const pathItem = paths[path];
|
|
34
|
+
if (!pathItem) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
for (const method of METHODS) {
|
|
38
|
+
const operation = pathItem[method];
|
|
39
|
+
if (!operation) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const uniqueOpId = operation.operationId && opIdCounts.get(operation.operationId) === 1
|
|
43
|
+
? operation.operationId
|
|
44
|
+
: undefined;
|
|
45
|
+
const endpointId = uniqueOpId ?? `${method.toUpperCase()} ${normalizePathForId(path)}`;
|
|
46
|
+
const endpoint = {
|
|
47
|
+
endpointId,
|
|
48
|
+
method,
|
|
49
|
+
path,
|
|
50
|
+
operationId: operation.operationId,
|
|
51
|
+
summary: operation.summary,
|
|
52
|
+
description: operation.description,
|
|
53
|
+
tags: operation.tags,
|
|
54
|
+
operation,
|
|
55
|
+
pathItem: pathItem
|
|
56
|
+
};
|
|
57
|
+
if (endpointById.has(endpointId)) {
|
|
58
|
+
throw new OpenApiMcpError("SCHEMA_ERROR", `Endpoint ID collision for '${endpointId}'`, {
|
|
59
|
+
path,
|
|
60
|
+
method
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
endpointById.set(endpointId, endpoint);
|
|
64
|
+
endpoints.push(endpoint);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
endpoints.sort((a, b) => {
|
|
68
|
+
if (a.path === b.path) {
|
|
69
|
+
return a.method.localeCompare(b.method);
|
|
70
|
+
}
|
|
71
|
+
return a.path.localeCompare(b.path);
|
|
72
|
+
});
|
|
73
|
+
return { endpoints, endpointById };
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=endpointIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpointIndex.js","sourceRoot":"","sources":["../../src/openapi/endpointIndex.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAG/C,MAAM,OAAO,GAAiB;IAC5B,KAAK;IACL,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;CACR,CAAC;AAEF,SAAS,kBAAkB,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AAC7D,CAAC;AAED,MAAM,UAAU,kBAAkB,CAAC,QAA4B;IAI7D,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;IACnC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAE7C,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QACtC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACzB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,SAAS;QACX,CAAC;QACD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;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