Skip to content

Commit 31d1f8a

Browse files
authored
refactor(agent-tars): refine mcp types (#596)
1 parent 236f375 commit 31d1f8a

File tree

3 files changed

+25
-33
lines changed

3 files changed

+25
-33
lines changed

packages/multimodal/agent/src/mcp-agent/mcp-agent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class MCPAgent extends Agent {
1919
super(options);
2020

2121
this.mcpServerConfig = options.mcpServers;
22-
this.clientVersion = options.mcpClientVersion || 'v1';
22+
this.clientVersion = options.mcpClientVersion ?? 'v2';
2323
}
2424

2525
/**

packages/multimodal/agent/src/mcp-agent/mcp-client-v2.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,14 @@ export class MCPClientV2 implements IMCPClient {
2626
[
2727
{
2828
name: serverName,
29-
...this.convertConfigToV2Format(config),
29+
...config,
3030
status: 'activate',
3131
},
3232
],
3333
{ isDebug: false },
3434
);
3535
}
3636

37-
/**
38-
* Convert v1 server config format to v2 format
39-
*/
40-
private convertConfigToV2Format(config: MCPServerConfig) {
41-
const v2Config: MCPServerConfig = {};
42-
43-
if (config.command) {
44-
v2Config.command = config.command;
45-
}
46-
47-
if (config.args) {
48-
v2Config.args = config.args;
49-
}
50-
51-
if (config.env) {
52-
v2Config.env = config.env;
53-
}
54-
55-
if (config.url) {
56-
v2Config.url = config.url;
57-
v2Config.type = 'sse'; // Default to SSE for URL-based servers
58-
}
59-
60-
return v2Config;
61-
}
62-
6337
async initialize(): Promise<Tool[]> {
6438
if (this.isInitialized) {
6539
return this.tools;

packages/multimodal/agent/src/mcp-agent/mcp-types.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ export interface MCPAgentOptions extends AgentOptions {
1313
*/
1414
mcpServers: MCPServerRegistry;
1515
/**
16-
* Version of MCP client to use
16+
* Version of MCP client to use.
17+
* This is a config for test ONLY, DO NOT depends on it.
18+
*
1719
* - 'v1': Use the built-in MCP client (default)
1820
* - 'v2': Use @agent-infra/mcp-client package
1921
*
20-
* @default 'v1'
22+
* @default 'v2'
2123
*/
2224
mcpClientVersion?: 'v1' | 'v2';
2325
}
@@ -27,13 +29,29 @@ export interface MCPClientResult {
2729
}
2830

2931
export interface MCPServerConfig {
30-
// Command based server config
32+
/**
33+
* Transport: "stdio"
34+
* @see https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#stdio
35+
*/
3136
command?: string;
3237
args?: string[];
3338
env?: Record<string, string>;
34-
// SSE based server config
39+
40+
/**
41+
* Transport: "sse" or "streaming-http"
42+
* @see https://modelcontextprotocol.io/specification/2025-03-26/basic/transports#streamable-http
43+
* @see https://modelcontextprotocol.io/specification/2024-11-05/basic/transports#http-with-sse
44+
*/
3545
url?: string;
36-
type?: 'sse';
46+
/**
47+
* @see https://github.com/modelcontextprotocol/typescript-sdk/blob/bac916e804599ee9e2ecd20f56ac2677c94989f4/src/client/sse.ts#L225-L226
48+
*/
49+
headers?: RequestInit['headers'];
50+
51+
/**
52+
* Rest custom configurations.
53+
*/
54+
[key: string]: unknown;
3755
}
3856

3957
export interface MCPServerRegistry {

0 commit comments

Comments
 (0)