@koseha/api-mcp 0.0.5 → 0.0.7

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.
@@ -20,9 +20,57 @@ export function registerGetApiDetail(server) {
20
20
  };
21
21
  }
22
22
  const swagger = await loadSwagger();
23
- const api = swagger.paths[requestUrl][httpMethod];
23
+ const api = swagger.paths?.[requestUrl]?.[httpMethod];
24
+ if (!api) {
25
+ return {
26
+ content: [{ type: "text", text: "해당 API를 찾을 수 없습니다." }],
27
+ };
28
+ }
29
+ // parameters 변환
30
+ const parameters = (api.parameters || []).map((param) => ({
31
+ name: param.name,
32
+ in: param.in,
33
+ required: param.required || false,
34
+ schema: {
35
+ type: param.schema?.type || null,
36
+ format: param.schema?.format || null,
37
+ enum: param.schema?.enum || null,
38
+ },
39
+ }));
40
+ // requestBody 변환
41
+ let requestBody = null;
42
+ if (api.requestBody?.content) {
43
+ const jsonContent = api.requestBody.content["application/json"];
44
+ if (jsonContent?.schema) {
45
+ const schema = jsonContent.schema;
46
+ requestBody = {
47
+ required: schema.required || [],
48
+ type: schema.type || "object",
49
+ properties: schema.properties || {},
50
+ };
51
+ }
52
+ }
53
+ // responses 변환 (200 응답의 schema 추출)
54
+ let responses = null;
55
+ if (api.responses?.["200"]?.content?.["application/json"]?.schema) {
56
+ const schema = api.responses["200"].content["application/json"].schema;
57
+ responses = {
58
+ type: schema.type || "object",
59
+ properties: schema.properties || {},
60
+ };
61
+ }
62
+ const result = {};
63
+ if (parameters.length > 0) {
64
+ result.parameters = parameters;
65
+ }
66
+ if (requestBody) {
67
+ result.requestBody = requestBody;
68
+ }
69
+ if (responses) {
70
+ result.responses = responses;
71
+ }
24
72
  return {
25
- content: [{ type: "text", text: JSON.stringify(api) }],
73
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
26
74
  };
27
75
  });
28
76
  }
@@ -9,8 +9,23 @@ export function registerGetApiList(server) {
9
9
  }, async () => {
10
10
  const swagger = await loadSwagger();
11
11
  // paths → list 가공
12
+ const result = {};
13
+ for (const [path, methods] of Object.entries(swagger.paths || {})) {
14
+ if (!methods || typeof methods !== "object")
15
+ continue;
16
+ result[path] = {};
17
+ for (const [method, operation] of Object.entries(methods)) {
18
+ if (typeof operation === "object" && operation !== null) {
19
+ result[path][method] = {
20
+ tags: operation.tags,
21
+ operationId: operation.operationId,
22
+ summary: operation.summary,
23
+ };
24
+ }
25
+ }
26
+ }
12
27
  return {
13
- content: [{ type: "text", text: JSON.stringify(swagger.paths) }],
28
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
14
29
  };
15
30
  });
16
31
  }
@@ -1,11 +1,9 @@
1
1
  /**
2
2
  * 모든 Tool 등록
3
3
  */
4
- import { registerAddTool } from "./add.tool.js";
5
4
  import { registerGetApiList } from "./getApiList.tool.js";
6
5
  import { registerGetApiDetail } from "./getApiDetail.tool.js";
7
6
  export function registerTools(server) {
8
- registerAddTool(server);
9
7
  registerGetApiList(server);
10
8
  registerGetApiDetail(server);
11
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koseha/api-mcp",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "An API MCP based on Swagger docs",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/koseha/api-mcp#readme",
@@ -1,10 +0,0 @@
1
- import { z } from "zod";
2
- export function registerAddTool(server) {
3
- server.registerTool("add", {
4
- title: "Addition Tool",
5
- description: "Add two numbers",
6
- inputSchema: { a: z.number(), b: z.number() },
7
- }, async ({ a, b }) => ({
8
- content: [{ type: "text", text: String(a + b) }],
9
- }));
10
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,5 +0,0 @@
1
- export function registerListEndpointsTool(server, endpoints) {
2
- server.tool("list_endpoints", "List all API endpoints", {}, async () => {
3
- return endpoints.map((e) => `${e.method} ${e.path}`);
4
- });
5
- }