proxy-api-mcp 1.0.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.
Files changed (144) hide show
  1. package/.env.example +57 -0
  2. package/README.md +443 -0
  3. package/api-tools.json.example +226 -0
  4. package/dist/examples/env-in-json-usage.d.ts +43 -0
  5. package/dist/examples/env-in-json-usage.d.ts.map +1 -0
  6. package/dist/examples/env-in-json-usage.js +242 -0
  7. package/dist/examples/env-in-json-usage.js.map +1 -0
  8. package/dist/examples/env-usage.d.ts +7 -0
  9. package/dist/examples/env-usage.d.ts.map +1 -0
  10. package/dist/examples/env-usage.js +108 -0
  11. package/dist/examples/env-usage.js.map +1 -0
  12. package/dist/examples/preprocessor-usage.d.ts +14 -0
  13. package/dist/examples/preprocessor-usage.d.ts.map +1 -0
  14. package/dist/examples/preprocessor-usage.js +196 -0
  15. package/dist/examples/preprocessor-usage.js.map +1 -0
  16. package/dist/src/config/env.d.ts +97 -0
  17. package/dist/src/config/env.d.ts.map +1 -0
  18. package/dist/src/config/env.js +228 -0
  19. package/dist/src/config/env.js.map +1 -0
  20. package/dist/src/core/registry.d.ts +59 -0
  21. package/dist/src/core/registry.d.ts.map +1 -0
  22. package/dist/src/core/registry.js +126 -0
  23. package/dist/src/core/registry.js.map +1 -0
  24. package/dist/src/core/router.d.ts +34 -0
  25. package/dist/src/core/router.d.ts.map +1 -0
  26. package/dist/src/core/router.js +108 -0
  27. package/dist/src/core/router.js.map +1 -0
  28. package/dist/src/core/server.d.ts +55 -0
  29. package/dist/src/core/server.d.ts.map +1 -0
  30. package/dist/src/core/server.js +159 -0
  31. package/dist/src/core/server.js.map +1 -0
  32. package/dist/src/core/session.d.ts +70 -0
  33. package/dist/src/core/session.d.ts.map +1 -0
  34. package/dist/src/core/session.js +171 -0
  35. package/dist/src/core/session.js.map +1 -0
  36. package/dist/src/core/transports/http.d.ts +16 -0
  37. package/dist/src/core/transports/http.d.ts.map +1 -0
  38. package/dist/src/core/transports/http.js +169 -0
  39. package/dist/src/core/transports/http.js.map +1 -0
  40. package/dist/src/core/transports/stdio.d.ts +9 -0
  41. package/dist/src/core/transports/stdio.d.ts.map +1 -0
  42. package/dist/src/core/transports/stdio.js +32 -0
  43. package/dist/src/core/transports/stdio.js.map +1 -0
  44. package/dist/src/index.d.ts +19 -0
  45. package/dist/src/index.d.ts.map +1 -0
  46. package/dist/src/index.js +22 -0
  47. package/dist/src/index.js.map +1 -0
  48. package/dist/src/server.d.ts +6 -0
  49. package/dist/src/server.d.ts.map +1 -0
  50. package/dist/src/server.js +121 -0
  51. package/dist/src/server.js.map +1 -0
  52. package/dist/src/tools/api/builder.d.ts +34 -0
  53. package/dist/src/tools/api/builder.d.ts.map +1 -0
  54. package/dist/src/tools/api/builder.js +196 -0
  55. package/dist/src/tools/api/builder.js.map +1 -0
  56. package/dist/src/tools/api/executor.d.ts +57 -0
  57. package/dist/src/tools/api/executor.d.ts.map +1 -0
  58. package/dist/src/tools/api/executor.js +317 -0
  59. package/dist/src/tools/api/executor.js.map +1 -0
  60. package/dist/src/tools/api/index.d.ts +12 -0
  61. package/dist/src/tools/api/index.d.ts.map +1 -0
  62. package/dist/src/tools/api/index.js +12 -0
  63. package/dist/src/tools/api/index.js.map +1 -0
  64. package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_chunaguanli.json +879 -0
  65. package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_yingfukuanguanli.json +1673 -0
  66. package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_yingshoukuanguanli.json +1081 -0
  67. package/dist/src/tools/api/json/kingdee/kingdee_caiwukuaiji_zongzhang.json +976 -0
  68. package/dist/src/tools/api/json/kingdee/kingdee_chengbenguanli_biaozhunchengbenfenxi.json +1 -0
  69. package/dist/src/tools/api/json/kingdee/kingdee_chengbenguanli_chanpinchengbenhesuan.json +1 -0
  70. package/dist/src/tools/api/json/kingdee/kingdee_chengbenguanli_cunhuohesuan.json +1858 -0
  71. package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_caigouguanli.json +1 -0
  72. package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_gongyingshangguanli.json +616 -0
  73. package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_kucunguanli.json +858 -0
  74. package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_xiaoshouguanli.json +858 -0
  75. package/dist/src/tools/api/json/kingdee/kingdee_gongyinglianguanli_zuzhijianjiesuan.json +858 -0
  76. package/dist/src/tools/api/json/kingdee/kingdee_jichuguanli_jichuziliao.json +867 -0
  77. package/dist/src/tools/api/json/kingdee/kingdee_jichuguanli_xiaoxipingtai.json +374 -0
  78. package/dist/src/tools/api/json/kingdee/kingdee_shengchanzhizao_chejianguanli.json +923 -0
  79. package/dist/src/tools/api/json/kingdee/kingdee_shengchanzhizao_gongchengshujuguanli.json +923 -0
  80. package/dist/src/tools/api/json/kingdee/kingdee_shengchanzhizao_shengchanguanli.json +858 -0
  81. package/dist/src/tools/api/json/kingdee/kingdee_shuiwuguanli_fapiaoguanli.json +1081 -0
  82. package/dist/src/tools/api/json/kingdee/kingdee_yuangongfuwu_renrenbaoxiao.json +858 -0
  83. package/dist/src/tools/api/json/kingdee/kingdee_zichanguanli_gudingzichan.json +1 -0
  84. package/dist/src/tools/api/json-config-loader.d.ts +28 -0
  85. package/dist/src/tools/api/json-config-loader.d.ts.map +1 -0
  86. package/dist/src/tools/api/json-config-loader.js +123 -0
  87. package/dist/src/tools/api/json-config-loader.js.map +1 -0
  88. package/dist/src/tools/api/json-config-mapping.d.ts +41 -0
  89. package/dist/src/tools/api/json-config-mapping.d.ts.map +1 -0
  90. package/dist/src/tools/api/json-config-mapping.js +138 -0
  91. package/dist/src/tools/api/json-config-mapping.js.map +1 -0
  92. package/dist/src/tools/api/loader.d.ts +38 -0
  93. package/dist/src/tools/api/loader.d.ts.map +1 -0
  94. package/dist/src/tools/api/loader.js +240 -0
  95. package/dist/src/tools/api/loader.js.map +1 -0
  96. package/dist/src/tools/api/preprocessor.d.ts +39 -0
  97. package/dist/src/tools/api/preprocessor.d.ts.map +1 -0
  98. package/dist/src/tools/api/preprocessor.js +64 -0
  99. package/dist/src/tools/api/preprocessor.js.map +1 -0
  100. package/dist/src/tools/api/preprocessors/example.d.ts +59 -0
  101. package/dist/src/tools/api/preprocessors/example.d.ts.map +1 -0
  102. package/dist/src/tools/api/preprocessors/example.js +133 -0
  103. package/dist/src/tools/api/preprocessors/example.js.map +1 -0
  104. package/dist/src/tools/api/preprocessors/index.d.ts +10 -0
  105. package/dist/src/tools/api/preprocessors/index.d.ts.map +1 -0
  106. package/dist/src/tools/api/preprocessors/index.js +29 -0
  107. package/dist/src/tools/api/preprocessors/index.js.map +1 -0
  108. package/dist/src/tools/api/preprocessors/kingdee.d.ts +24 -0
  109. package/dist/src/tools/api/preprocessors/kingdee.d.ts.map +1 -0
  110. package/dist/src/tools/api/preprocessors/kingdee.js +149 -0
  111. package/dist/src/tools/api/preprocessors/kingdee.js.map +1 -0
  112. package/dist/src/tools/api/types.d.ts +174 -0
  113. package/dist/src/tools/api/types.d.ts.map +1 -0
  114. package/dist/src/tools/api/types.js +5 -0
  115. package/dist/src/tools/api/types.js.map +1 -0
  116. package/dist/src/tools/examples/echo.d.ts +6 -0
  117. package/dist/src/tools/examples/echo.d.ts.map +1 -0
  118. package/dist/src/tools/examples/echo.js +61 -0
  119. package/dist/src/tools/examples/echo.js.map +1 -0
  120. package/dist/src/tools/types.d.ts +104 -0
  121. package/dist/src/tools/types.d.ts.map +1 -0
  122. package/dist/src/tools/types.js +15 -0
  123. package/dist/src/tools/types.js.map +1 -0
  124. package/dist/src/tools/validator.d.ts +27 -0
  125. package/dist/src/tools/validator.d.ts.map +1 -0
  126. package/dist/src/tools/validator.js +133 -0
  127. package/dist/src/tools/validator.js.map +1 -0
  128. package/dist/src/utils/cache.d.ts +14 -0
  129. package/dist/src/utils/cache.d.ts.map +1 -0
  130. package/dist/src/utils/cache.js +42 -0
  131. package/dist/src/utils/cache.js.map +1 -0
  132. package/dist/src/utils/env-replacer.d.ts +86 -0
  133. package/dist/src/utils/env-replacer.d.ts.map +1 -0
  134. package/dist/src/utils/env-replacer.js +196 -0
  135. package/dist/src/utils/env-replacer.js.map +1 -0
  136. package/dist/src/utils/errors.d.ts +102 -0
  137. package/dist/src/utils/errors.d.ts.map +1 -0
  138. package/dist/src/utils/errors.js +164 -0
  139. package/dist/src/utils/errors.js.map +1 -0
  140. package/dist/src/utils/logger.d.ts +77 -0
  141. package/dist/src/utils/logger.d.ts.map +1 -0
  142. package/dist/src/utils/logger.js +155 -0
  143. package/dist/src/utils/logger.js.map +1 -0
  144. package/package.json +73 -0
package/.env.example ADDED
@@ -0,0 +1,57 @@
1
+ # MCP 服务配置
2
+ MCP_TRANSPORT=http
3
+ MCP_PORT=3000
4
+ MCP_SESSION_TIMEOUT=3600000
5
+ MCP_LOG_LEVEL=info
6
+ MCP_TOOLS_DIR=./tools
7
+
8
+ # API 工具配置文件路径
9
+ MCP_API_TOOLS_CONFIG=./api-tools.json
10
+
11
+ # JSON 配置映射(通过预定义的key加载对应的JSON配置文件)
12
+ # 支持多个配置,用逗号分隔,例如:kingdee_basic,kingdee_finance
13
+ # 可用的配置keys:
14
+ # - kingdee_basic: 金蝶云星空-基础管理(基础资料、消息平台)
15
+ # - kingdee_finance: 金蝶云星空-财务会计(总账、应收应付、存货核算)
16
+ # - kingdee_scm: 金蝶云星空-供应链管理(库存、销售、供应商、组织间结算)
17
+ # - kingdee_manufacture: 金蝶云星空-生产制造(生产管理、车间管理、工程数据)
18
+ # - kingdee_tax: 金蝶云星空-税务管理(发票管理)
19
+ # - kingdee_employee: 金蝶云星空-员工服务(人人报销)
20
+ # - kingdee_all: 金蝶云星空-全部模块
21
+ # 示例:MCP_JSON_CONFIG=kingdee_basic,kingdee_finance
22
+ MCP_JSON_CONFIG=
23
+
24
+ # API 工具相关环境变量示例
25
+ # 这些变量可以在 api-tools.json 中通过 ${VAR_NAME} 或 ${VAR_NAME:default} 语法使用
26
+
27
+ # API 基础 URL
28
+ # API_BASE_URL=https://api.example.com
29
+
30
+ # API 认证 Token
31
+ # API_TOKEN=your_api_token_here
32
+
33
+ # 自定义 User-Agent
34
+ # USER_AGENT=DefinesysMCP/1.0
35
+
36
+ # API 超时时间(毫秒)
37
+ # API_TIMEOUT=30000
38
+
39
+ # JSONPlaceholder API 相关
40
+ # JSONPLACEHOLDER_BASE_URL=https://jsonplaceholder.typicode.com
41
+
42
+ # 金蝶云星空
43
+ # 域名
44
+ KINGDEE_DOMAIN=
45
+ # 账套ID
46
+ KINGDEE_ACCT_ID=
47
+ # 用户名
48
+ KINGDEE_USERNAME=
49
+ # 应用ID
50
+ KINGDEE_APP_ID=
51
+ # 应用密钥
52
+ KINGDEE_SECRET=
53
+ # 语言ID
54
+ KINGDEE_LCID=
55
+ # 算法
56
+ KINGDEE_ALGORITHM=
57
+
package/README.md ADDED
@@ -0,0 +1,443 @@
1
+ # Definesys MCP Framework
2
+
3
+ <p align="center">
4
+ <strong>一个灵活、易用的 MCP (Model Context Protocol) 服务框架</strong>
5
+ </p>
6
+
7
+ <p align="center">
8
+ 快速将业务接口转换为 MCP 工具,供 LLM 应用调用
9
+ </p>
10
+
11
+ ## 核心特性
12
+
13
+ - **简化工具扩展** - 声明式工具配置,无需关心 MCP 协议细节
14
+ - **多传输模式** - 支持 Stdio、SSE 和 Streamable HTTP 三种传输模式
15
+ - **JSON 配置驱动** - 通过 JSON 配置文件零代码创建 API 工具
16
+ - **环境变量支持** - 在 JSON 配置中使用环境变量,提升安全性和灵活性
17
+ - **请求预处理器** - 支持在 API 请求发送前进行自定义处理
18
+ - **JSON 配置映射** - 通过简单的 key 加载预定义的配置文件集合
19
+ - **类型安全** - 使用 TypeScript 开发,严格的类型检查
20
+ - **Schema 验证** - 基于 Zod 的输入输出验证
21
+
22
+ ## 安装
23
+
24
+ ### 使用 npx 直接运行 (推荐)
25
+
26
+ 无需安装,直接通过 npx 运行:
27
+
28
+ ```bash
29
+ npx proxy-api-mcp
30
+ ```
31
+
32
+ ### 全局安装
33
+
34
+ ```bash
35
+ npm install -g proxy-api-mcp
36
+ proxy-api-mcp
37
+ ```
38
+
39
+ ### 本地项目安装
40
+
41
+ ```bash
42
+ npm install proxy-api-mcp
43
+ ```
44
+
45
+ ## 快速开始
46
+
47
+ ### 创建一个简单的 MCP 服务
48
+
49
+ ```typescript
50
+ import { McpServer, startHttpServer, ToolConfig } from 'proxy-api-mcp';
51
+
52
+ // 定义工具
53
+ const greetTool: ToolConfig = {
54
+ name: 'greet',
55
+ description: 'Greets a person by name',
56
+ inputSchema: {
57
+ type: 'object',
58
+ properties: {
59
+ name: {
60
+ type: 'string',
61
+ description: 'The name of the person to greet',
62
+ },
63
+ },
64
+ required: ['name'],
65
+ },
66
+ handler: async (args) => {
67
+ const name = args.name as string;
68
+ return {
69
+ content: [
70
+ {
71
+ type: 'text',
72
+ text: `Hello, ${name}! Welcome to MCP!`,
73
+ },
74
+ ],
75
+ };
76
+ },
77
+ };
78
+
79
+ // 创建服务器
80
+ const server = new McpServer({
81
+ name: 'my-mcp-server',
82
+ version: '1.0.0',
83
+ });
84
+
85
+ // 注册工具
86
+ server.registerTool(greetTool);
87
+
88
+ // 启动 HTTP 服务器
89
+ await startHttpServer(server, { port: 3000 });
90
+ ```
91
+
92
+ ### 使用 Stdio 模式 (适用于 Claude Desktop)
93
+
94
+ ```typescript
95
+ import { McpServer, startStdioServer } from 'proxy-api-mcp';
96
+
97
+ const server = new McpServer({
98
+ name: 'my-mcp-server',
99
+ version: '1.0.0',
100
+ });
101
+
102
+ server.registerTool(greetTool);
103
+
104
+ await startStdioServer(server);
105
+ ```
106
+
107
+ ## 核心概念
108
+
109
+ ### 工具配置
110
+
111
+ 工具通过声明式配置进行定义:
112
+
113
+ ```typescript
114
+ interface ToolConfig {
115
+ name: string; // 工具唯一标识符
116
+ title?: string; // 工具的可读标题
117
+ description: string; // 工具功能描述
118
+ inputSchema: object; // 输入参数的 JSON Schema
119
+ outputSchema?: object; // 输出结果的 JSON Schema
120
+ handler: ToolHandler; // 工具处理函数
121
+ }
122
+ ```
123
+
124
+ ### 传输模式
125
+
126
+ 框架支持三种传输模式:
127
+
128
+ | 模式 | 场景 | 特点 |
129
+ |------|------|------|
130
+ | **stdio** | 本地进程,IDE 插件 | 零网络配置,最高安全性 |
131
+ | **http** | 远程服务,多客户端 | 支持并发,会话管理 |
132
+ | **sse** | 需要服务端推送 | 向后兼容旧版协议 |
133
+
134
+ ## JSON 配置 API 工具
135
+
136
+ 通过 JSON 配置文件自动生成 MCP 工具,无需编写代码即可调用 RESTful API。
137
+
138
+ ### 基本配置结构
139
+
140
+ ```json
141
+ {
142
+ "version": "1.0",
143
+ "globals": {
144
+ "baseUrl": "https://api.example.com",
145
+ "timeout": 30000,
146
+ "headers": {
147
+ "User-Agent": "MyApp/1.0"
148
+ }
149
+ },
150
+ "tools": [
151
+ {
152
+ "name": "get_user",
153
+ "description": "Get user by ID",
154
+ "method": "GET",
155
+ "path": "/users/{userId}",
156
+ "parameters": [
157
+ {
158
+ "name": "userId",
159
+ "in": "path",
160
+ "required": true,
161
+ "type": "integer"
162
+ }
163
+ ]
164
+ }
165
+ ]
166
+ }
167
+ ```
168
+
169
+ ### 在配置中使用环境变量
170
+
171
+ 支持在 JSON 配置中使用环境变量占位符:
172
+
173
+ ```json
174
+ {
175
+ "baseUrl": "${API_BASE_URL}",
176
+ "headers": {
177
+ "Authorization": "Bearer ${API_TOKEN}"
178
+ },
179
+ "timeout": "${API_TIMEOUT:30000}"
180
+ }
181
+ ```
182
+
183
+ - **基本语法**: `${ENV_VAR_NAME}`
184
+ - **带默认值**: `${ENV_VAR_NAME:default_value}`
185
+
186
+ ### JSON 配置映射
187
+
188
+ 通过环境变量快速加载预定义的配置文件集合:
189
+
190
+ ```bash
191
+ # .env 文件
192
+ MCP_JSON_CONFIG=kingdee_basic,kingdee_finance
193
+ ```
194
+
195
+ 可用配置 Keys:
196
+
197
+ | Key | 说明 |
198
+ |-----|------|
199
+ | `kingdee_basic` | 基础管理 |
200
+ | `kingdee_finance` | 财务会计 |
201
+ | `kingdee_scm` | 供应链管理 |
202
+ | `kingdee_manufacture` | 生产制造 |
203
+ | `kingdee_tax` | 税务管理 |
204
+ | `kingdee_employee` | 员工服务 |
205
+ | `kingdee_all` | 全部模块 |
206
+
207
+ ## 请求预处理器
208
+
209
+ 在 API 请求发送前对请求数据进行自定义处理:
210
+
211
+ ### 创建预处理器
212
+
213
+ ```typescript
214
+ import { type RequestPreprocessor, type RequestData } from 'proxy-api-mcp';
215
+
216
+ export class MyPreprocessor implements RequestPreprocessor {
217
+ readonly name = 'my_preprocessor';
218
+
219
+ preprocess(requestData: RequestData): RequestData {
220
+ requestData.headers['X-Custom-Header'] = 'value';
221
+ return requestData;
222
+ }
223
+ }
224
+ ```
225
+
226
+ ### 注册并使用
227
+
228
+ ```typescript
229
+ import { PreprocessorRegistry } from 'proxy-api-mcp';
230
+
231
+ PreprocessorRegistry.register(new MyPreprocessor());
232
+ ```
233
+
234
+ 在配置中指定预处理器:
235
+
236
+ ```json
237
+ {
238
+ "name": "my_api",
239
+ "preprocessor": "my_preprocessor",
240
+ "method": "GET",
241
+ "path": "/data"
242
+ }
243
+ ```
244
+
245
+ ## 环境变量管理
246
+
247
+ 使用集中式环境变量管理类:
248
+
249
+ ```typescript
250
+ import { env } from './config/env';
251
+
252
+ // 获取环境变量
253
+ const port = env.get('MCP_PORT');
254
+ const transport = env.get('MCP_TRANSPORT');
255
+
256
+ // 验证环境变量
257
+ env.validate();
258
+
259
+ // 判断运行环境
260
+ if (env.isProduction()) {
261
+ // 生产环境逻辑
262
+ }
263
+ ```
264
+
265
+ ## 配置
266
+
267
+ ### 环境变量
268
+
269
+ | 变量 | 默认值 | 说明 |
270
+ |------|--------|------|
271
+ | `MCP_TRANSPORT` | `http` | 传输模式 (stdio/sse/http) |
272
+ | `MCP_PORT` | `3000` | HTTP 端口 |
273
+ | `MCP_SESSION_TIMEOUT` | `3600000` | 会话超时时间(毫秒) |
274
+ | `MCP_LOG_LEVEL` | `info` | 日志级别 (debug/info/warn/error) |
275
+ | `MCP_TOOLS_DIR` | `./tools` | 工具目录路径 |
276
+ | `MCP_API_TOOLS_CONFIG` | `./api-tools.json` | API 工具配置文件路径 |
277
+ | `MCP_JSON_CONFIG` | - | JSON 配置映射 keys (逗号分隔) |
278
+ | `NODE_ENV` | `development` | 运行环境 |
279
+
280
+ ### Claude Desktop 配置
281
+
282
+ #### HTTP 模式
283
+
284
+ ```json
285
+ {
286
+ "mcpServers": {
287
+ "proxy-api-mcp": {
288
+ "type": "streamableHttp",
289
+ "url": "http://localhost:3000/mcp",
290
+ "timeout": 60000
291
+ }
292
+ }
293
+ }
294
+ ```
295
+
296
+ #### Stdio 模式
297
+
298
+ ```json
299
+ {
300
+ "mcpServers": {
301
+ "proxy-api-mcp": {
302
+ "command": "node",
303
+ "args": ["/path/to/proxy-api-mcp/dist/server.js"],
304
+ "env": {
305
+ "MCP_TRANSPORT": "stdio"
306
+ }
307
+ }
308
+ }
309
+ }
310
+ ```
311
+
312
+ ## 高级用法
313
+
314
+ ### 添加中间件
315
+
316
+ ```typescript
317
+ import { Middleware } from 'proxy-api-mcp';
318
+
319
+ const loggingMiddleware: Middleware = async (context, next) => {
320
+ console.log(`Tool called at ${new Date(context.timestamp)}`);
321
+ const result = await next();
322
+ console.log(`Tool completed`);
323
+ return result;
324
+ };
325
+
326
+ server.getRouter().use(loggingMiddleware);
327
+ ```
328
+
329
+ ### 批量注册工具
330
+
331
+ ```typescript
332
+ server.registerTools([
333
+ echoTool,
334
+ calculatorTool,
335
+ ]);
336
+ ```
337
+
338
+ ## 项目结构
339
+
340
+ ```
341
+ proxy-api-mcp/
342
+ ├── src/
343
+ │ ├── core/ # 核心框架
344
+ │ │ ├── server.ts # MCP Server 封装
345
+ │ │ ├── registry.ts # 工具注册器
346
+ │ │ ├── router.ts # 工具路由器
347
+ │ │ ├── session.ts # 会话管理器
348
+ │ │ └── transports/ # 传输层实现
349
+ │ ├── tools/ # 工具层
350
+ │ │ ├── types.ts # 类型定义
351
+ │ │ ├── validator.ts # Schema 验证器
352
+ │ │ ├── api/ # API 工具模块
353
+ │ │ │ ├── builder.ts # API 工具构建器
354
+ │ │ │ ├── executor.ts # API 请求执行器
355
+ │ │ │ ├── loader.ts # API 工具加载器
356
+ │ │ │ ├── preprocessor.ts # 预处理器注册表
357
+ │ │ │ └── json-config-*.ts # JSON 配置相关
358
+ │ │ └── examples/ # 示例工具
359
+ │ ├── config/ # 配置管理
360
+ │ │ └── env.ts # 环境变量管理
361
+ │ ├── utils/ # 工具函数
362
+ │ │ ├── logger.ts # 日志工具
363
+ │ │ ├── errors.ts # 错误定义
364
+ │ │ └── env-replacer.ts # 环境变量替换
365
+ │ └── index.ts # 框架入口
366
+ ├── examples/ # 使用示例
367
+ └── docs/ # 文档
368
+ ```
369
+
370
+ ## 文档
371
+
372
+ - [API 工具架构指南](./docs/API_TOOLS_GUIDE.md) - JSON 配置创建 API 工具
373
+ - [环境变量管理指南](./docs/ENV_GUIDE.md) - 环境变量管理类使用
374
+ - [JSON 配置中使用环境变量](./docs/ENV_IN_JSON_GUIDE.md) - 在配置中使用环境变量
375
+ - [请求预处理器指南](./docs/PREPROCESSOR_GUIDE.md) - 自定义请求处理
376
+ - [JSON 配置映射指南](./docs/JSON_CONFIG_MAPPING_GUIDE.md) - 配置映射加载
377
+ - [开发指南](./docs/DEVELOPMENT.md) - 项目开发总结
378
+ - [测试指南](./docs/TESTING.md) - 测试 MCP 服务器
379
+
380
+ ## 常用命令
381
+
382
+ ```bash
383
+ npm run build # 编译 TypeScript
384
+ npm run dev # 开发模式运行
385
+ npm start # 运行编译后的服务
386
+ npm run lint # 代码检查
387
+ npm test # 运行测试
388
+ ```
389
+
390
+ ## API 参考
391
+
392
+ ### McpServer
393
+
394
+ ```typescript
395
+ class McpServer {
396
+ constructor(config: ServerConfig);
397
+ registerTool(config: ToolConfig): void;
398
+ registerTools(configs: ToolConfig[]): void;
399
+ getRegistry(): ToolRegistry;
400
+ getRouter(): ToolRouter;
401
+ getSessionManager(): SessionManager;
402
+ close(): Promise<void>;
403
+ }
404
+ ```
405
+
406
+ ### PreprocessorRegistry
407
+
408
+ ```typescript
409
+ class PreprocessorRegistry {
410
+ static register(preprocessor: RequestPreprocessor): void;
411
+ static registerMany(preprocessors: RequestPreprocessor[]): void;
412
+ static get(name: string): RequestPreprocessor | undefined;
413
+ static has(name: string): boolean;
414
+ static unregister(name: string): boolean;
415
+ static getAll(): string[];
416
+ static clear(): void;
417
+ }
418
+ ```
419
+
420
+ ### EnvManager
421
+
422
+ ```typescript
423
+ class EnvManager {
424
+ get<K extends keyof EnvSchema>(key: K): EnvSchema[K];
425
+ getAll(): EnvSchema;
426
+ has(key: keyof EnvSchema): boolean;
427
+ validate(): void;
428
+ isProduction(): boolean;
429
+ isDevelopment(): boolean;
430
+ isTest(): boolean;
431
+ print(): void;
432
+ }
433
+ ```
434
+
435
+ ## 许可证
436
+
437
+ MIT License
438
+
439
+ ## 致谢
440
+
441
+ - [Model Context Protocol](https://modelcontextprotocol.io/) - MCP 官方规范
442
+ - [@modelcontextprotocol/sdk](https://github.com/modelcontextprotocol/typescript-sdk) - MCP TypeScript SDK
443
+ - [Zod](https://github.com/colinhacks/zod) - TypeScript-first schema validation