@leeguoo/yapi-mcp 0.2.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.
@@ -0,0 +1,102 @@
1
+ export interface ApiInterface {
2
+ _id: string;
3
+ project_id?: number | string;
4
+ catid?: string;
5
+ status?: string;
6
+ tag?: string[];
7
+ title: string;
8
+ path: string;
9
+ method: string;
10
+ req_params: any[];
11
+ req_body_form: any[];
12
+ req_headers: any[];
13
+ req_query: any[];
14
+ req_body_type: string;
15
+ req_body_other: string;
16
+ req_body_is_json_schema?: boolean;
17
+ res_body_type: string;
18
+ res_body: string;
19
+ res_body_is_json_schema?: boolean;
20
+ switch_notice?: boolean;
21
+ api_opened?: boolean;
22
+ desc: string;
23
+ markdown: string;
24
+ message?: string;
25
+ }
26
+ export interface SaveApiInterfaceParams {
27
+ id?: string;
28
+ catid: string;
29
+ token?: string;
30
+ method: string;
31
+ path: string;
32
+ title: string;
33
+ project_id: string;
34
+ req_params?: any[];
35
+ req_headers?: any[];
36
+ req_query?: any[];
37
+ req_body_type?: string;
38
+ req_body_form?: any[];
39
+ req_body_other?: string;
40
+ req_body_is_json_schema?: boolean;
41
+ res_body_type?: string;
42
+ res_body?: string;
43
+ res_body_is_json_schema?: boolean;
44
+ desc?: string;
45
+ markdown?: string;
46
+ switch_notice?: boolean;
47
+ api_opened?: boolean;
48
+ tag?: string[];
49
+ status?: string;
50
+ }
51
+ export interface ProjectInfo {
52
+ _id: number | string;
53
+ name: string;
54
+ desc: string;
55
+ group_id: number;
56
+ uid: number;
57
+ basepath: string;
58
+ }
59
+ export interface CategoryInfo {
60
+ _id: string;
61
+ name: string;
62
+ desc: string;
63
+ project_id: number | string;
64
+ uid: number;
65
+ add_time: number;
66
+ up_time: number;
67
+ index: number;
68
+ }
69
+ export interface ApiSearchResultItem {
70
+ _id: string;
71
+ title: string;
72
+ path: string;
73
+ method: string;
74
+ project_id: number | string;
75
+ catid: string;
76
+ add_time: number;
77
+ up_time: number;
78
+ project_name?: string;
79
+ cat_name?: string;
80
+ }
81
+ export interface ApiResponse<T> {
82
+ errcode: number;
83
+ errmsg: string;
84
+ data: T;
85
+ }
86
+ export interface GetApiResponse extends ApiResponse<ApiInterface> {
87
+ }
88
+ export interface GetProjectResponse extends ApiResponse<ProjectInfo> {
89
+ }
90
+ export interface GetCategoryListResponse extends ApiResponse<CategoryInfo[]> {
91
+ }
92
+ export interface SaveApiResponse extends ApiResponse<{
93
+ _id: string;
94
+ [key: string]: any;
95
+ }> {
96
+ }
97
+ export interface ApiSearchResponse extends ApiResponse<{
98
+ total: number;
99
+ count: number;
100
+ list: ApiSearchResultItem[];
101
+ }> {
102
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/services/yapi/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ export interface ApiInterface {
2
+ _id: string;
3
+ title: string;
4
+ path: string;
5
+ method: string;
6
+ req_params: any[];
7
+ req_body_form: any[];
8
+ req_headers: any[];
9
+ req_query: any[];
10
+ req_body_type: string;
11
+ res_body_type: string;
12
+ res_body: string;
13
+ desc: string;
14
+ markdown: string;
15
+ }
16
+ export interface GetApiResponse {
17
+ errcode: number;
18
+ errmsg: string;
19
+ data: ApiInterface;
20
+ }
21
+ export declare class YApiService {
22
+ private readonly baseUrl;
23
+ private readonly token;
24
+ private readonly logger;
25
+ constructor(baseUrl: string, token: string);
26
+ private request;
27
+ getApiInterface(id: string): Promise<ApiInterface>;
28
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.YApiService = void 0;
37
+ const axios_1 = __importStar(require("axios"));
38
+ const logger_1 = require("./yapi/logger");
39
+ class YApiService {
40
+ baseUrl;
41
+ token;
42
+ logger;
43
+ constructor(baseUrl, token) {
44
+ this.baseUrl = baseUrl;
45
+ this.token = token;
46
+ this.logger = new logger_1.Logger("YApiService", "debug");
47
+ }
48
+ async request(endpoint, params = {}) {
49
+ try {
50
+ this.logger.debug(`调用 ${this.baseUrl}${endpoint}`);
51
+ const response = await axios_1.default.get(`${this.baseUrl}${endpoint}`, {
52
+ params: {
53
+ ...params,
54
+ token: this.token
55
+ }
56
+ });
57
+ return response.data;
58
+ }
59
+ catch (error) {
60
+ if (error instanceof axios_1.AxiosError && error.response) {
61
+ throw {
62
+ status: error.response.status,
63
+ message: error.response.data.errmsg || "未知错误",
64
+ };
65
+ }
66
+ throw new Error("与YApi服务器通信失败");
67
+ }
68
+ }
69
+ async getApiInterface(id) {
70
+ try {
71
+ const response = await this.request("/api/interface/get", { id });
72
+ if (response.errcode !== 0) {
73
+ throw new Error(response.errmsg || "获取API接口失败");
74
+ }
75
+ return response.data;
76
+ }
77
+ catch (error) {
78
+ console.error("获取API接口失败:", error);
79
+ throw error;
80
+ }
81
+ }
82
+ }
83
+ exports.YApiService = YApiService;
84
+ //# sourceMappingURL=yapi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yapi.js","sourceRoot":"","sources":["../../src/services/yapi.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA0C;AAC1C,0CAAuC;AAyBvC,MAAa,WAAW;IACL,OAAO,CAAS;IAChB,KAAK,CAAS;IACd,MAAM,CAAS;IAEhC,YAAY,OAAe,EAAE,KAAa;QACxC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC;IAEO,KAAK,CAAC,OAAO,CAAI,QAAgB,EAAE,SAA8B,EAAE;QACzE,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,IAAI,CAAC,OAAO,GAAG,QAAQ,EAAE,CAAC,CAAC;YACnD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,QAAQ,EAAE,EAAE;gBAC7D,MAAM,EAAE;oBACN,GAAG,MAAM;oBACT,KAAK,EAAE,IAAI,CAAC,KAAK;iBAClB;aACF,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,kBAAU,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAClD,MAAM;oBACJ,MAAM,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM;oBAC7B,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,IAAI,MAAM;iBAC9C,CAAC;YACJ,CAAC;YACD,MAAM,IAAI,KAAK,CAAC,cAAc,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,EAAU;QAC9B,IAAI,CAAC;YAEH,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAiB,oBAAoB,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;YAGlF,IAAI,QAAQ,CAAC,OAAO,KAAK,CAAC,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,IAAI,WAAW,CAAC,CAAC;YAClD,CAAC;YAED,OAAO,QAAQ,CAAC,IAAI,CAAC;QACvB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;YACnC,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF;AAjDD,kCAiDC"}
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "@leeguoo/yapi-mcp",
3
+ "version": "0.2.0",
4
+ "description": "YApi Auto MCP Server - Model Context Protocol server for YApi integration, enables AI tools like Cursor to interact with YApi API documentation",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "yapi-auto-mcp": "./dist/cli.js",
8
+ "yapi-mcp": "./dist/cli.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "README.md"
13
+ ],
14
+ "scripts": {
15
+ "build": "tsc && tsc-alias",
16
+ "type-check": "tsc --noEmit",
17
+ "start": "node dist/index.js",
18
+ "start:cli": "cross-env NODE_ENV=cli node dist/index.js",
19
+ "start:http": "node dist/index.js",
20
+ "dev": "cross-env NODE_ENV=development tsx watch src/index.ts",
21
+ "dev:cli": "cross-env NODE_ENV=development tsx watch src/index.ts --stdio",
22
+ "lint": "eslint . --ext .ts",
23
+ "format": "prettier --write \"src/**/*.ts\"",
24
+ "inspect": "pnpx @modelcontextprotocol/inspector",
25
+ "prepare": "pnpm run build && chmod +x ./dist/cli.js",
26
+ "pub:release": "pnpm build && npm publish"
27
+ },
28
+ "engines": {
29
+ "node": ">=20"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/leeguooooo/Yapi-MCP.git"
34
+ },
35
+ "keywords": [
36
+ "yapi",
37
+ "mcp",
38
+ "typescript",
39
+ "model-context-protocol",
40
+ "api-documentation",
41
+ "cursor",
42
+ "ai-tools",
43
+ "api-management",
44
+ "yapi-integration",
45
+ "claude",
46
+ "anthropic",
47
+ "ai-assistant",
48
+ "interface-management",
49
+ "api-design",
50
+ "documentation-tool"
51
+ ],
52
+ "author": "liangzhensheng <372959130@qq.com>",
53
+ "license": "MIT",
54
+ "publishConfig": {
55
+ "access": "public"
56
+ },
57
+ "dependencies": {
58
+ "@modelcontextprotocol/sdk": "^1.6.0",
59
+ "@types/yargs": "^17.0.33",
60
+ "axios": "^1.7.9",
61
+ "dotenv": "^16.4.7",
62
+ "express": "^4.21.2",
63
+ "remeda": "^2.20.1",
64
+ "yargs": "^17.7.2",
65
+ "zod": "^3.24.2"
66
+ },
67
+ "devDependencies": {
68
+ "@types/express": "^5.0.0",
69
+ "@types/node": "^20.17.32",
70
+ "@typescript-eslint/eslint-plugin": "^8.24.0",
71
+ "@typescript-eslint/parser": "^8.24.0",
72
+ "cross-env": "^7.0.3",
73
+ "eslint": "^9.20.1",
74
+ "eslint-config-prettier": "^10.0.1",
75
+ "prettier": "^3.5.0",
76
+ "tsc-alias": "^1.8.10",
77
+ "tsx": "^4.19.3",
78
+ "typescript": "^5.7.3"
79
+ }
80
+ }