@xiaozhi-client/mcp-core 1.10.5 → 1.10.6-beta.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/package.json +2 -1
- package/dist/index.d.ts +0 -681
- package/dist/index.js +0 -922
- package/dist/index.js.map +0 -1
package/package.json
CHANGED
package/dist/index.d.ts
DELETED
|
@@ -1,681 +0,0 @@
|
|
|
1
|
-
import { Tool, CompatibilityCallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
-
export { CompatibilityCallToolResult as ToolCallResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
4
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
5
|
-
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
6
|
-
import { EventEmitter } from 'node:events';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* MCP 核心库类型定义
|
|
10
|
-
* 统一管理所有 MCP 相关的类型定义
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* MCP 传输层联合类型定义
|
|
15
|
-
* 支持 STDIO、SSE、StreamableHTTP 三种传输协议
|
|
16
|
-
*/
|
|
17
|
-
type MCPServerTransport = StdioClientTransport | SSEClientTransport | StreamableHTTPClientTransport;
|
|
18
|
-
/**
|
|
19
|
-
* 通信方式枚举
|
|
20
|
-
* 定义 MCP 支持的传输类型
|
|
21
|
-
*/
|
|
22
|
-
declare enum MCPTransportType {
|
|
23
|
-
STDIO = "stdio",
|
|
24
|
-
SSE = "sse",
|
|
25
|
-
HTTP = "http"
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 传输类型字符串字面量
|
|
29
|
-
* 方便外部用户直接使用字符串而不需要导入枚举
|
|
30
|
-
*/
|
|
31
|
-
type MCPTransportTypeString = "stdio" | "sse" | "http";
|
|
32
|
-
/**
|
|
33
|
-
* 传输类型输入值(枚举或字符串字面量)
|
|
34
|
-
*/
|
|
35
|
-
type MCPTransportTypeInput = MCPTransportType | MCPTransportTypeString;
|
|
36
|
-
/**
|
|
37
|
-
* MCP 服务事件回调接口
|
|
38
|
-
* 用于替代 EventBus 依赖,提供灵活的事件处理机制
|
|
39
|
-
*/
|
|
40
|
-
interface MCPServiceEventCallbacks {
|
|
41
|
-
/** 连接成功回调 */
|
|
42
|
-
onConnected?: (data: {
|
|
43
|
-
serviceName: string;
|
|
44
|
-
tools: Tool[];
|
|
45
|
-
connectionTime: Date;
|
|
46
|
-
}) => void;
|
|
47
|
-
/** 断开连接回调 */
|
|
48
|
-
onDisconnected?: (data: {
|
|
49
|
-
serviceName: string;
|
|
50
|
-
reason?: string;
|
|
51
|
-
disconnectionTime: Date;
|
|
52
|
-
}) => void;
|
|
53
|
-
/** 连接失败回调 */
|
|
54
|
-
onConnectionFailed?: (data: {
|
|
55
|
-
serviceName: string;
|
|
56
|
-
error: Error;
|
|
57
|
-
attempt: number;
|
|
58
|
-
}) => void;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* ModelScope SSE 自定义选项接口
|
|
62
|
-
*/
|
|
63
|
-
interface ModelScopeSSEOptions {
|
|
64
|
-
eventSourceInit?: {
|
|
65
|
-
fetch?: (url: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
66
|
-
};
|
|
67
|
-
requestInit?: RequestInit;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 心跳检测配置接口
|
|
71
|
-
*/
|
|
72
|
-
interface HeartbeatConfig {
|
|
73
|
-
/** 是否启用心跳检测(默认 true) */
|
|
74
|
-
enabled?: boolean;
|
|
75
|
-
/** 心跳间隔(毫秒,默认 30000 = 30秒) */
|
|
76
|
-
interval?: number;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* MCP 服务配置接口
|
|
80
|
-
* 包含所有 MCP 服务的配置选项(不包含服务名称)
|
|
81
|
-
*
|
|
82
|
-
* @description
|
|
83
|
-
* 与 MCP 官方配置格式保持一致,支持三种传输类型:
|
|
84
|
-
* - stdio: 本地进程通信 { command, args, env }
|
|
85
|
-
* - sse: Server-Sent Events { url, headers }
|
|
86
|
-
* - http: Streamable HTTP { url, headers }
|
|
87
|
-
*
|
|
88
|
-
* 向后兼容:自动将 streamable-http/streamable_http/streamableHttp 转换为 http
|
|
89
|
-
*/
|
|
90
|
-
interface MCPServiceConfig {
|
|
91
|
-
type?: MCPTransportTypeInput;
|
|
92
|
-
command?: string;
|
|
93
|
-
args?: string[];
|
|
94
|
-
env?: Record<string, string>;
|
|
95
|
-
url?: string;
|
|
96
|
-
apiKey?: string;
|
|
97
|
-
headers?: Record<string, string>;
|
|
98
|
-
customSSEOptions?: ModelScopeSSEOptions;
|
|
99
|
-
heartbeat?: HeartbeatConfig;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* 内部使用的 MCP 服务配置接口(包含 name 字段)
|
|
103
|
-
* 用于 TransportFactory 等内部函数
|
|
104
|
-
*/
|
|
105
|
-
interface InternalMCPServiceConfig extends MCPServiceConfig {
|
|
106
|
-
name: string;
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* 连接状态枚举
|
|
110
|
-
*/
|
|
111
|
-
declare enum ConnectionState {
|
|
112
|
-
DISCONNECTED = "disconnected",
|
|
113
|
-
CONNECTING = "connecting",
|
|
114
|
-
CONNECTED = "connected",
|
|
115
|
-
RECONNECTING = "reconnecting",
|
|
116
|
-
FAILED = "failed",
|
|
117
|
-
ERROR = "error"
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* MCP 服务状态接口
|
|
121
|
-
*/
|
|
122
|
-
interface MCPServiceStatus {
|
|
123
|
-
name: string;
|
|
124
|
-
connected: boolean;
|
|
125
|
-
initialized: boolean;
|
|
126
|
-
transportType: MCPTransportType;
|
|
127
|
-
toolCount: number;
|
|
128
|
-
lastError?: string;
|
|
129
|
-
connectionState: ConnectionState;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* JSON Schema 类型定义
|
|
134
|
-
*/
|
|
135
|
-
type JSONSchema = (Record<string, unknown> & {
|
|
136
|
-
type: "object";
|
|
137
|
-
properties?: Record<string, unknown>;
|
|
138
|
-
required?: string[];
|
|
139
|
-
additionalProperties?: boolean;
|
|
140
|
-
}) | Record<string, unknown>;
|
|
141
|
-
/**
|
|
142
|
-
* 类型守卫:检查对象是否为有效的 MCP Tool JSON Schema
|
|
143
|
-
*/
|
|
144
|
-
declare function isValidToolJSONSchema(obj: unknown): obj is {
|
|
145
|
-
type: "object";
|
|
146
|
-
properties?: Record<string, unknown>;
|
|
147
|
-
required?: string[];
|
|
148
|
-
additionalProperties?: boolean;
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* 确保对象符合 MCP Tool JSON Schema 格式
|
|
152
|
-
*/
|
|
153
|
-
declare function ensureToolJSONSchema(schema: JSONSchema): {
|
|
154
|
-
type: "object";
|
|
155
|
-
properties?: Record<string, object>;
|
|
156
|
-
required?: string[];
|
|
157
|
-
additionalProperties?: boolean;
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* CustomMCP 工具类型定义
|
|
161
|
-
*/
|
|
162
|
-
interface CustomMCPTool {
|
|
163
|
-
name: string;
|
|
164
|
-
description?: string;
|
|
165
|
-
inputSchema: JSONSchema;
|
|
166
|
-
handler?: {
|
|
167
|
-
type: string;
|
|
168
|
-
config?: Record<string, unknown>;
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* 工具信息接口
|
|
173
|
-
*/
|
|
174
|
-
interface ToolInfo {
|
|
175
|
-
serviceName: string;
|
|
176
|
-
originalName: string;
|
|
177
|
-
tool: Tool;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* 增强的工具信息接口
|
|
181
|
-
*/
|
|
182
|
-
interface EnhancedToolInfo {
|
|
183
|
-
/** 工具唯一标识符,格式为 "{serviceName}__{originalName}" */
|
|
184
|
-
name: string;
|
|
185
|
-
/** 工具描述信息 */
|
|
186
|
-
description: string;
|
|
187
|
-
/** 工具输入参数的 JSON Schema 定义 */
|
|
188
|
-
inputSchema: JSONSchema;
|
|
189
|
-
/** 工具所属的 MCP 服务名称 */
|
|
190
|
-
serviceName: string;
|
|
191
|
-
/** 工具在 MCP 服务中的原始名称 */
|
|
192
|
-
originalName: string;
|
|
193
|
-
/** 工具是否启用 */
|
|
194
|
-
enabled: boolean;
|
|
195
|
-
/** 工具使用次数统计 */
|
|
196
|
-
usageCount: number;
|
|
197
|
-
/** 工具最后使用时间 */
|
|
198
|
-
lastUsedTime: string;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* 统一服务器配置接口
|
|
202
|
-
*/
|
|
203
|
-
interface UnifiedServerConfig {
|
|
204
|
-
name?: string;
|
|
205
|
-
enableLogging?: boolean;
|
|
206
|
-
logLevel?: string;
|
|
207
|
-
configs?: Record<string, MCPServiceConfig>;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* 统一服务器状态接口
|
|
211
|
-
*/
|
|
212
|
-
interface UnifiedServerStatus {
|
|
213
|
-
isRunning: boolean;
|
|
214
|
-
serviceStatus: ManagerStatus;
|
|
215
|
-
transportCount: number;
|
|
216
|
-
activeConnections: number;
|
|
217
|
-
config: UnifiedServerConfig;
|
|
218
|
-
services?: Record<string, MCPServiceConnectionStatus>;
|
|
219
|
-
totalTools?: number;
|
|
220
|
-
availableTools?: string[];
|
|
221
|
-
}
|
|
222
|
-
/**
|
|
223
|
-
* MCP 服务连接状态接口
|
|
224
|
-
*/
|
|
225
|
-
interface MCPServiceConnectionStatus {
|
|
226
|
-
connected: boolean;
|
|
227
|
-
clientName: string;
|
|
228
|
-
}
|
|
229
|
-
/**
|
|
230
|
-
* 管理器状态接口
|
|
231
|
-
*/
|
|
232
|
-
interface ManagerStatus {
|
|
233
|
-
services: Record<string, MCPServiceConnectionStatus>;
|
|
234
|
-
totalTools: number;
|
|
235
|
-
availableTools: string[];
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* 工具调用参数接口
|
|
239
|
-
*/
|
|
240
|
-
interface ToolCallParams {
|
|
241
|
-
name: string;
|
|
242
|
-
arguments?: Record<string, unknown>;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* 验证后的工具调用参数
|
|
246
|
-
*/
|
|
247
|
-
interface ValidatedToolCallParams {
|
|
248
|
-
name: string;
|
|
249
|
-
arguments?: Record<string, unknown>;
|
|
250
|
-
}
|
|
251
|
-
/**
|
|
252
|
-
* 工具调用验证选项
|
|
253
|
-
*/
|
|
254
|
-
interface ToolCallValidationOptions {
|
|
255
|
-
validateName?: boolean;
|
|
256
|
-
validateArguments?: boolean;
|
|
257
|
-
allowEmptyArguments?: boolean;
|
|
258
|
-
customValidator?: (params: ToolCallParams) => string | null;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* 工具调用错误码枚举
|
|
262
|
-
*/
|
|
263
|
-
declare enum ToolCallErrorCode {
|
|
264
|
-
INVALID_PARAMS = -32602,
|
|
265
|
-
TOOL_NOT_FOUND = -32601,
|
|
266
|
-
SERVICE_UNAVAILABLE = -32001,
|
|
267
|
-
TIMEOUT = -32002,
|
|
268
|
-
TOOL_EXECUTION_ERROR = -32000
|
|
269
|
-
}
|
|
270
|
-
/**
|
|
271
|
-
* 工具调用错误类
|
|
272
|
-
*/
|
|
273
|
-
declare class ToolCallError extends Error {
|
|
274
|
-
code: ToolCallErrorCode;
|
|
275
|
-
data?: unknown | undefined;
|
|
276
|
-
constructor(code: ToolCallErrorCode, message: string, data?: unknown | undefined);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* MCP 连接管理模块
|
|
281
|
-
*
|
|
282
|
-
* 提供 MCPConnection 类,负责管理单个 MCP 服务的连接生命周期
|
|
283
|
-
* 包括连接建立、工具列表管理、工具调用、心跳检测等功能
|
|
284
|
-
*
|
|
285
|
-
* @module connection
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* MCP 连接类
|
|
290
|
-
* 负责管理单个 MCP 服务的连接、工具管理和调用
|
|
291
|
-
*/
|
|
292
|
-
declare class MCPConnection {
|
|
293
|
-
private name;
|
|
294
|
-
private config;
|
|
295
|
-
private client;
|
|
296
|
-
private transport;
|
|
297
|
-
private tools;
|
|
298
|
-
private connectionState;
|
|
299
|
-
private connectionTimeout;
|
|
300
|
-
private initialized;
|
|
301
|
-
private callbacks?;
|
|
302
|
-
private heartbeatTimer;
|
|
303
|
-
private heartbeatConfig?;
|
|
304
|
-
constructor(name: string, config: MCPServiceConfig, callbacks?: MCPServiceEventCallbacks);
|
|
305
|
-
/**
|
|
306
|
-
* 验证配置
|
|
307
|
-
*/
|
|
308
|
-
private validateConfig;
|
|
309
|
-
/**
|
|
310
|
-
* 连接到 MCP 服务
|
|
311
|
-
*/
|
|
312
|
-
connect(): Promise<void>;
|
|
313
|
-
/**
|
|
314
|
-
* 尝试建立连接
|
|
315
|
-
*/
|
|
316
|
-
private attemptConnection;
|
|
317
|
-
/**
|
|
318
|
-
* 处理连接成功
|
|
319
|
-
*/
|
|
320
|
-
private handleConnectionSuccess;
|
|
321
|
-
/**
|
|
322
|
-
* 处理连接错误
|
|
323
|
-
*/
|
|
324
|
-
private handleConnectionError;
|
|
325
|
-
/**
|
|
326
|
-
* 清理连接资源
|
|
327
|
-
*/
|
|
328
|
-
private cleanupConnection;
|
|
329
|
-
/**
|
|
330
|
-
* 刷新工具列表
|
|
331
|
-
*/
|
|
332
|
-
private refreshTools;
|
|
333
|
-
/**
|
|
334
|
-
* 断开连接
|
|
335
|
-
*/
|
|
336
|
-
disconnect(): Promise<void>;
|
|
337
|
-
/**
|
|
338
|
-
* 获取工具列表
|
|
339
|
-
*/
|
|
340
|
-
getTools(): Tool[];
|
|
341
|
-
/**
|
|
342
|
-
* 检测是否为会话过期错误
|
|
343
|
-
*/
|
|
344
|
-
private isSessionExpiredError;
|
|
345
|
-
/**
|
|
346
|
-
* 自动重连
|
|
347
|
-
*/
|
|
348
|
-
private reconnect;
|
|
349
|
-
/**
|
|
350
|
-
* 启动心跳检测
|
|
351
|
-
*/
|
|
352
|
-
private startHeartbeat;
|
|
353
|
-
/**
|
|
354
|
-
* 执行一次心跳检查
|
|
355
|
-
*/
|
|
356
|
-
private performHeartbeat;
|
|
357
|
-
/**
|
|
358
|
-
* 停止心跳检测
|
|
359
|
-
*/
|
|
360
|
-
private stopHeartbeat;
|
|
361
|
-
/**
|
|
362
|
-
* 调用工具
|
|
363
|
-
*/
|
|
364
|
-
callTool(name: string, arguments_: Record<string, unknown>): Promise<CompatibilityCallToolResult>;
|
|
365
|
-
/**
|
|
366
|
-
* 获取服务配置
|
|
367
|
-
*/
|
|
368
|
-
getConfig(): MCPServiceConfig & {
|
|
369
|
-
name: string;
|
|
370
|
-
};
|
|
371
|
-
/**
|
|
372
|
-
* 获取服务状态
|
|
373
|
-
*/
|
|
374
|
-
getStatus(): MCPServiceStatus;
|
|
375
|
-
/**
|
|
376
|
-
* 检查是否已连接
|
|
377
|
-
*/
|
|
378
|
-
isConnected(): boolean;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* MCP 服务管理器
|
|
383
|
-
* 提供简洁的 API 来管理多个 MCP 服务
|
|
384
|
-
*/
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* MCP 服务管理器
|
|
388
|
-
* 提供简洁的 API 来管理多个 MCP 服务
|
|
389
|
-
*
|
|
390
|
-
* @example
|
|
391
|
-
* ```typescript
|
|
392
|
-
* const manager = new MCPManager();
|
|
393
|
-
*
|
|
394
|
-
* // 添加服务
|
|
395
|
-
* manager.addServer('datetime', {
|
|
396
|
-
* type: 'stdio',
|
|
397
|
-
* command: 'node',
|
|
398
|
-
* args: ['datetime.js']
|
|
399
|
-
* });
|
|
400
|
-
*
|
|
401
|
-
* // 连接所有服务
|
|
402
|
-
* await manager.connect();
|
|
403
|
-
*
|
|
404
|
-
* // 调用工具
|
|
405
|
-
* const result = await manager.callTool('datetime', 'get_current_time', {
|
|
406
|
-
* format: 'YYYY-MM-DD HH:mm:ss'
|
|
407
|
-
* });
|
|
408
|
-
*
|
|
409
|
-
* // 断开连接
|
|
410
|
-
* await manager.disconnect();
|
|
411
|
-
* ```
|
|
412
|
-
*/
|
|
413
|
-
declare class MCPManager extends EventEmitter {
|
|
414
|
-
private connections;
|
|
415
|
-
private configs;
|
|
416
|
-
constructor();
|
|
417
|
-
/**
|
|
418
|
-
* 添加 MCP 服务器配置
|
|
419
|
-
* @param name 服务器名称
|
|
420
|
-
* @param config 服务器配置
|
|
421
|
-
*
|
|
422
|
-
* @example
|
|
423
|
-
* ```typescript
|
|
424
|
-
* // 添加 stdio 服务
|
|
425
|
-
* manager.addServer('calculator', {
|
|
426
|
-
* type: 'stdio',
|
|
427
|
-
* command: 'node',
|
|
428
|
-
* args: ['calculator.js']
|
|
429
|
-
* });
|
|
430
|
-
*
|
|
431
|
-
* // 添加 HTTP 服务
|
|
432
|
-
* manager.addServer('web-search', {
|
|
433
|
-
* type: 'http',
|
|
434
|
-
* url: 'https://api.example.com/mcp',
|
|
435
|
-
* headers: {
|
|
436
|
-
* Authorization: 'Bearer your-api-key'
|
|
437
|
-
* }
|
|
438
|
-
* });
|
|
439
|
-
* ```
|
|
440
|
-
*/
|
|
441
|
-
addServer(name: string, config: MCPServiceConfig): void;
|
|
442
|
-
/**
|
|
443
|
-
* 移除服务器配置
|
|
444
|
-
* @param name 服务器名称
|
|
445
|
-
*/
|
|
446
|
-
removeServer(name: string): boolean;
|
|
447
|
-
/**
|
|
448
|
-
* 连接所有已添加的 MCP 服务
|
|
449
|
-
* 所有服务并行连接,单个服务失败不会影响其他服务
|
|
450
|
-
*
|
|
451
|
-
* @example
|
|
452
|
-
* ```typescript
|
|
453
|
-
* await manager.connect();
|
|
454
|
-
* ```
|
|
455
|
-
*/
|
|
456
|
-
connect(): Promise<void>;
|
|
457
|
-
/**
|
|
458
|
-
* 断开所有 MCP 服务连接
|
|
459
|
-
*
|
|
460
|
-
* @example
|
|
461
|
-
* ```typescript
|
|
462
|
-
* await manager.disconnect();
|
|
463
|
-
* ```
|
|
464
|
-
*/
|
|
465
|
-
disconnect(): Promise<void>;
|
|
466
|
-
/**
|
|
467
|
-
* 调用指定服务的工具
|
|
468
|
-
* @param serverName 服务名称
|
|
469
|
-
* @param toolName 工具名称
|
|
470
|
-
* @param args 工具参数
|
|
471
|
-
*
|
|
472
|
-
* @example
|
|
473
|
-
* ```typescript
|
|
474
|
-
* const result = await manager.callTool('datetime', 'get_current_time', {
|
|
475
|
-
* format: 'YYYY-MM-DD HH:mm:ss'
|
|
476
|
-
* });
|
|
477
|
-
* ```
|
|
478
|
-
*/
|
|
479
|
-
callTool(serverName: string, toolName: string, args: Record<string, unknown>): Promise<CompatibilityCallToolResult>;
|
|
480
|
-
/**
|
|
481
|
-
* 列出所有可用的工具
|
|
482
|
-
* @returns 工具列表,格式为 [{ name, serverName, description, inputSchema }]
|
|
483
|
-
*
|
|
484
|
-
* @example
|
|
485
|
-
* ```typescript
|
|
486
|
-
* const tools = manager.listTools();
|
|
487
|
-
* console.log('可用工具:', tools.map(t => `${t.serverName}/${t.name}`));
|
|
488
|
-
* ```
|
|
489
|
-
*/
|
|
490
|
-
listTools(): Array<{
|
|
491
|
-
name: string;
|
|
492
|
-
serverName: string;
|
|
493
|
-
description: string;
|
|
494
|
-
inputSchema: unknown;
|
|
495
|
-
}>;
|
|
496
|
-
/**
|
|
497
|
-
* 获取服务状态
|
|
498
|
-
* @param serverName 服务名称
|
|
499
|
-
* @returns 服务状态,如果服务不存在则返回 null
|
|
500
|
-
*
|
|
501
|
-
* @example
|
|
502
|
-
* ```typescript
|
|
503
|
-
* const status = manager.getServerStatus('datetime');
|
|
504
|
-
* if (status) {
|
|
505
|
-
* console.log(`已连接: ${status.connected}, 工具数: ${status.toolCount}`);
|
|
506
|
-
* }
|
|
507
|
-
* ```
|
|
508
|
-
*/
|
|
509
|
-
getServerStatus(serverName: string): {
|
|
510
|
-
connected: boolean;
|
|
511
|
-
toolCount: number;
|
|
512
|
-
} | null;
|
|
513
|
-
/**
|
|
514
|
-
* 获取所有服务的状态
|
|
515
|
-
* @returns 所有服务的状态映射
|
|
516
|
-
*
|
|
517
|
-
* @example
|
|
518
|
-
* ```typescript
|
|
519
|
-
* const statuses = manager.getAllServerStatus();
|
|
520
|
-
* console.log(statuses);
|
|
521
|
-
* // {
|
|
522
|
-
* // datetime: { connected: true, toolCount: 3 },
|
|
523
|
-
* // calculator: { connected: true, toolCount: 1 }
|
|
524
|
-
* // }
|
|
525
|
-
* ```
|
|
526
|
-
*/
|
|
527
|
-
getAllServerStatus(): Record<string, {
|
|
528
|
-
connected: boolean;
|
|
529
|
-
toolCount: number;
|
|
530
|
-
}>;
|
|
531
|
-
/**
|
|
532
|
-
* 检查服务是否已连接
|
|
533
|
-
* @param serverName 服务名称
|
|
534
|
-
*
|
|
535
|
-
* @example
|
|
536
|
-
* ```typescript
|
|
537
|
-
* if (manager.isConnected('datetime')) {
|
|
538
|
-
* console.log('datetime 服务已连接');
|
|
539
|
-
* }
|
|
540
|
-
* ```
|
|
541
|
-
*/
|
|
542
|
-
isConnected(serverName: string): boolean;
|
|
543
|
-
/**
|
|
544
|
-
* 获取已配置的服务列表
|
|
545
|
-
* @returns 服务名称数组
|
|
546
|
-
*
|
|
547
|
-
* @example
|
|
548
|
-
* ```typescript
|
|
549
|
-
* const servers = manager.getServerNames();
|
|
550
|
-
* console.log('已配置的服务:', servers);
|
|
551
|
-
* ```
|
|
552
|
-
*/
|
|
553
|
-
getServerNames(): string[];
|
|
554
|
-
/**
|
|
555
|
-
* 获取已连接的服务列表
|
|
556
|
-
* @returns 已连接的服务名称数组
|
|
557
|
-
*
|
|
558
|
-
* @example
|
|
559
|
-
* ```typescript
|
|
560
|
-
* const connectedServers = manager.getConnectedServerNames();
|
|
561
|
-
* console.log('已连接的服务:', connectedServers);
|
|
562
|
-
* ```
|
|
563
|
-
*/
|
|
564
|
-
getConnectedServerNames(): string[];
|
|
565
|
-
}
|
|
566
|
-
|
|
567
|
-
/**
|
|
568
|
-
* MCP 传输层工厂模块
|
|
569
|
-
*
|
|
570
|
-
* 提供创建不同类型传输层实例的工厂函数
|
|
571
|
-
* 支持 STDIO、SSE、StreamableHTTP 三种传输协议
|
|
572
|
-
*
|
|
573
|
-
* @module transport-factory
|
|
574
|
-
*/
|
|
575
|
-
|
|
576
|
-
/**
|
|
577
|
-
* 创建 transport 实例
|
|
578
|
-
* @param config MCP 服务配置(包含 name)
|
|
579
|
-
* @returns transport 实例
|
|
580
|
-
*/
|
|
581
|
-
declare function createTransport(config: InternalMCPServiceConfig): MCPServerTransport;
|
|
582
|
-
/**
|
|
583
|
-
* 验证配置
|
|
584
|
-
* 注意:name 验证已在 MCPConnection 构造函数中进行
|
|
585
|
-
* @param config MCP 服务配置(包含 name)
|
|
586
|
-
*/
|
|
587
|
-
declare function validateConfig(config: InternalMCPServiceConfig): void;
|
|
588
|
-
/**
|
|
589
|
-
* 获取支持的传输类型列表
|
|
590
|
-
*/
|
|
591
|
-
declare function getSupportedTypes(): MCPTransportType[];
|
|
592
|
-
/**
|
|
593
|
-
* Transport 工厂对象(保持 API 兼容性)
|
|
594
|
-
*/
|
|
595
|
-
declare const TransportFactory: {
|
|
596
|
-
create: typeof createTransport;
|
|
597
|
-
validateConfig: typeof validateConfig;
|
|
598
|
-
getSupportedTypes: typeof getSupportedTypes;
|
|
599
|
-
};
|
|
600
|
-
|
|
601
|
-
/**
|
|
602
|
-
* MCP 服务器配置 Type 字段标准化工具
|
|
603
|
-
* 支持将各种 type 字段格式转换为 MCP 官方标准格式
|
|
604
|
-
*
|
|
605
|
-
* @description
|
|
606
|
-
* 标准格式与 MCP 官方保持一致:
|
|
607
|
-
* - stdio: 本地进程通信
|
|
608
|
-
* - sse: Server-Sent Events
|
|
609
|
-
* - http: Streamable HTTP(推荐使用 http 而非 streamable-http)
|
|
610
|
-
*
|
|
611
|
-
* 向后兼容:自动转换各种变体格式
|
|
612
|
-
*/
|
|
613
|
-
/**
|
|
614
|
-
* MCP 服务器配置的基础接口
|
|
615
|
-
* 定义包含可选 type 字段的配置对象结构
|
|
616
|
-
*/
|
|
617
|
-
interface MCPBaseConfig {
|
|
618
|
-
type?: string;
|
|
619
|
-
[key: string]: unknown;
|
|
620
|
-
}
|
|
621
|
-
/**
|
|
622
|
-
* MCP 服务器配置 Type 字段标准化工具类
|
|
623
|
-
*/
|
|
624
|
-
declare namespace TypeFieldNormalizer {
|
|
625
|
-
/**
|
|
626
|
-
* 标准化 type 字段格式
|
|
627
|
-
*
|
|
628
|
-
* 支持的转换:
|
|
629
|
-
* - http 变体:http → http(标准值)
|
|
630
|
-
* - streamable-http → http
|
|
631
|
-
* - streamable_http → http
|
|
632
|
-
* - streamableHttp → http
|
|
633
|
-
* - sse 变体:sse → sse(标准值)
|
|
634
|
-
* - s_se → sse
|
|
635
|
-
* - s-se → sse
|
|
636
|
-
* - stdio 变体:stdio → stdio(标准值)
|
|
637
|
-
*/
|
|
638
|
-
function normalizeTypeField<T extends MCPBaseConfig>(config: T): T;
|
|
639
|
-
function normalizeTypeField(config: unknown): unknown;
|
|
640
|
-
/**
|
|
641
|
-
* 标准化单个 type 值
|
|
642
|
-
*/
|
|
643
|
-
function normalizeTypeValue(type: string): string;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* 导出便捷函数
|
|
647
|
-
*/
|
|
648
|
-
declare function normalizeTypeField<T extends MCPBaseConfig>(config: T): T;
|
|
649
|
-
declare function normalizeTypeField(config: unknown): unknown;
|
|
650
|
-
|
|
651
|
-
/**
|
|
652
|
-
* 根据 URL 路径推断传输类型
|
|
653
|
-
* 基于路径末尾推断,支持包含多个 / 的复杂路径
|
|
654
|
-
*
|
|
655
|
-
* @param url - 要推断的 URL
|
|
656
|
-
* @param options - 可选配置项
|
|
657
|
-
* @returns 推断出的传输类型
|
|
658
|
-
*/
|
|
659
|
-
declare function inferTransportTypeFromUrl(url: string, options?: {
|
|
660
|
-
serviceName?: string;
|
|
661
|
-
}): MCPTransportType;
|
|
662
|
-
/**
|
|
663
|
-
* 完整的配置类型推断(包括 command 字段)
|
|
664
|
-
*
|
|
665
|
-
* @param config - MCP 服务配置
|
|
666
|
-
* @param serviceName - 服务名称(用于日志输出)
|
|
667
|
-
* @returns 完整的配置对象,包含推断出的类型
|
|
668
|
-
*/
|
|
669
|
-
declare function inferTransportTypeFromConfig(config: MCPServiceConfig, serviceName?: string): MCPServiceConfig;
|
|
670
|
-
/**
|
|
671
|
-
* 验证工具调用参数
|
|
672
|
-
* 对传入的参数进行完整性和格式验证
|
|
673
|
-
*
|
|
674
|
-
* @param params 待验证的参数
|
|
675
|
-
* @param options 验证选项
|
|
676
|
-
* @returns 验证后的参数
|
|
677
|
-
* @throws ToolCallError 验证失败时抛出
|
|
678
|
-
*/
|
|
679
|
-
declare function validateToolCallParams(params: unknown, options?: ToolCallValidationOptions): ValidatedToolCallParams;
|
|
680
|
-
|
|
681
|
-
export { ConnectionState, type CustomMCPTool, type EnhancedToolInfo, type JSONSchema, MCPConnection, MCPManager, type MCPServerTransport, type MCPServiceConfig, type MCPServiceConnectionStatus, type MCPServiceEventCallbacks, MCPManager as MCPServiceManager, type MCPServiceStatus, MCPTransportType, type ManagerStatus, type ModelScopeSSEOptions, ToolCallError, ToolCallErrorCode, type ToolCallParams, type ToolCallValidationOptions, type ToolInfo, TransportFactory, TypeFieldNormalizer, type UnifiedServerConfig, type UnifiedServerStatus, type ValidatedToolCallParams, ensureToolJSONSchema, inferTransportTypeFromConfig, inferTransportTypeFromUrl, isValidToolJSONSchema, normalizeTypeField, validateToolCallParams };
|