@tencent-ai/agent-sdk 0.1.22 → 0.1.24
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/cli/CHANGELOG.md +42 -0
- package/cli/dist/codebuddy.js +3 -3
- package/cli/package.json +1 -1
- package/cli/product.cloudhosted.json +2 -2
- package/cli/product.internal.json +2 -2
- package/cli/product.ioa.json +2 -2
- package/cli/product.json +2 -2
- package/cli/product.selfhosted.json +2 -2
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/mcp/create-sdk-mcp-server.d.ts +159 -0
- package/lib/mcp/create-sdk-mcp-server.d.ts.map +1 -0
- package/lib/mcp/create-sdk-mcp-server.js +143 -0
- package/lib/mcp/create-sdk-mcp-server.js.map +1 -0
- package/lib/mcp/index.d.ts +11 -0
- package/lib/mcp/index.d.ts.map +1 -0
- package/lib/mcp/index.js +15 -0
- package/lib/mcp/index.js.map +1 -0
- package/lib/mcp/sdk-control-server-transport.d.ts +60 -0
- package/lib/mcp/sdk-control-server-transport.d.ts.map +1 -0
- package/lib/mcp/sdk-control-server-transport.js +78 -0
- package/lib/mcp/sdk-control-server-transport.js.map +1 -0
- package/lib/query.d.ts +29 -0
- package/lib/query.d.ts.map +1 -1
- package/lib/query.js +171 -4
- package/lib/query.js.map +1 -1
- package/lib/session.d.ts.map +1 -1
- package/lib/session.js +1 -0
- package/lib/session.js.map +1 -1
- package/lib/types.d.ts +45 -2
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js.map +1 -1
- package/package.json +4 -1
package/cli/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tencent-ai/codebuddy-code",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.34.0",
|
|
4
4
|
"description": "Use CodeBuddy, Tencent's AI assistant, right from your terminal. CodeBuddy can understand your codebase, edit files, run terminal commands, and handle entire workflows for you.",
|
|
5
5
|
"main": "lib/node/index.js",
|
|
6
6
|
"typings": "lib/node/index.d.ts",
|
|
@@ -316,6 +316,6 @@
|
|
|
316
316
|
"BillingNotice": false,
|
|
317
317
|
"CustomModelsJSON": true
|
|
318
318
|
},
|
|
319
|
-
"commit": "
|
|
320
|
-
"date": "2026-01-
|
|
319
|
+
"commit": "03dfa8482bf24abc92075fd676c34bd515b80024",
|
|
320
|
+
"date": "2026-01-14T15:40:57.998Z"
|
|
321
321
|
}
|
|
@@ -318,6 +318,6 @@
|
|
|
318
318
|
"BillingNotice": false,
|
|
319
319
|
"CustomModelsJSON": true
|
|
320
320
|
},
|
|
321
|
-
"commit": "
|
|
322
|
-
"date": "2026-01-
|
|
321
|
+
"commit": "03dfa8482bf24abc92075fd676c34bd515b80024",
|
|
322
|
+
"date": "2026-01-14T15:40:55.276Z"
|
|
323
323
|
}
|
package/cli/product.ioa.json
CHANGED
|
@@ -525,6 +525,6 @@
|
|
|
525
525
|
"BillingNotice": false,
|
|
526
526
|
"CustomModelsJSON": true
|
|
527
527
|
},
|
|
528
|
-
"commit": "
|
|
529
|
-
"date": "2026-01-
|
|
528
|
+
"commit": "03dfa8482bf24abc92075fd676c34bd515b80024",
|
|
529
|
+
"date": "2026-01-14T15:40:56.605Z"
|
|
530
530
|
}
|
package/cli/product.json
CHANGED
|
@@ -1017,6 +1017,6 @@
|
|
|
1017
1017
|
"description": "tool-lsp-description"
|
|
1018
1018
|
}
|
|
1019
1019
|
],
|
|
1020
|
-
"commit": "
|
|
1021
|
-
"date": "2026-01-
|
|
1020
|
+
"commit": "03dfa8482bf24abc92075fd676c34bd515b80024",
|
|
1021
|
+
"date": "2026-01-14T15:40:53.946Z"
|
|
1022
1022
|
}
|
|
@@ -198,6 +198,6 @@
|
|
|
198
198
|
"BillingNotice": false,
|
|
199
199
|
"CustomModelsJSON": true
|
|
200
200
|
},
|
|
201
|
-
"commit": "
|
|
202
|
-
"date": "2026-01-
|
|
201
|
+
"commit": "03dfa8482bf24abc92075fd676c34bd515b80024",
|
|
202
|
+
"date": "2026-01-14T15:40:59.310Z"
|
|
203
203
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
export { query } from './query';
|
|
19
19
|
export { Query } from './query';
|
|
20
20
|
export { createSession as unstable_v2_createSession, resumeSession as unstable_v2_resumeSession, prompt as unstable_v2_prompt, } from './session';
|
|
21
|
+
export { createSdkMcpServer, tool } from './mcp';
|
|
22
|
+
export type { SdkMcpServerOptions, SdkMcpServerResult, SdkMcpToolDefinition, AnyZodRawShape, InferShape, ToolHandler, } from './mcp';
|
|
21
23
|
export { HOOK_EVENTS, EXIT_REASONS } from './types';
|
|
22
24
|
export { AbortError } from './errors';
|
|
23
25
|
export type { Options, SessionOptions } from './types';
|
|
@@ -27,7 +29,7 @@ export type { Message, SystemMessage, UserMessage, AssistantMessage, PartialAssi
|
|
|
27
29
|
export type { SlashCommand, ModelInfo, AccountInfo, McpServerStatus, } from './types';
|
|
28
30
|
export type { OutputFormat, JsonSchemaOutputFormat } from './types';
|
|
29
31
|
export type { RawMessageStreamEvent } from './types';
|
|
30
|
-
export type { McpServerConfig, McpStdioServerConfig, McpSSEServerConfig, McpHttpServerConfig, } from './types';
|
|
32
|
+
export type { McpServerConfig, McpStdioServerConfig, McpSSEServerConfig, McpHttpServerConfig, McpSdkServerConfig, } from './types';
|
|
31
33
|
export type { AgentDefinition } from './types';
|
|
32
34
|
export type { AskUserQuestionOption, AskUserQuestionQuestion, AskUserQuestionInput, ToolInputMap, KnownToolName, } from './types';
|
|
33
35
|
export type { SandboxSettings } from './types';
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO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,WAAW,EACX,eAAe,GAClB,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAGpE,YAAY,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAGrD,YAAY,EACR,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,GACrB,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,YAAY,EACR,qBAAqB,EACrB,uBAAuB,EACvB,oBAAoB,EACpB,YAAY,EACZ,aAAa,GAChB,MAAM,SAAS,CAAC;AAGjB,YAAY,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAG/C,YAAY,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* ```
|
|
18
18
|
*/
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.AbortError = exports.EXIT_REASONS = exports.HOOK_EVENTS = exports.unstable_v2_resumeSession = exports.unstable_v2_createSession = exports.Query = exports.query = void 0;
|
|
20
|
+
exports.AbortError = exports.EXIT_REASONS = exports.HOOK_EVENTS = exports.tool = exports.createSdkMcpServer = exports.unstable_v2_resumeSession = exports.unstable_v2_createSession = exports.Query = exports.query = void 0;
|
|
21
21
|
// ============= Main API =============
|
|
22
22
|
var query_1 = require("./query");
|
|
23
23
|
Object.defineProperty(exports, "query", { enumerable: true, get: function () { return query_1.query; } });
|
|
@@ -28,6 +28,10 @@ var session_1 = require("./session");
|
|
|
28
28
|
Object.defineProperty(exports, "unstable_v2_createSession", { enumerable: true, get: function () { return session_1.createSession; } });
|
|
29
29
|
Object.defineProperty(exports, "unstable_v2_resumeSession", { enumerable: true, get: function () { return session_1.resumeSession; } });
|
|
30
30
|
Object.defineProperty(exports, "unstable_v2_prompt", { enumerable: true, get: function () { return session_1.prompt; } });
|
|
31
|
+
// ============= MCP Server API =============
|
|
32
|
+
var mcp_1 = require("./mcp");
|
|
33
|
+
Object.defineProperty(exports, "createSdkMcpServer", { enumerable: true, get: function () { return mcp_1.createSdkMcpServer; } });
|
|
34
|
+
Object.defineProperty(exports, "tool", { enumerable: true, get: function () { return mcp_1.tool; } });
|
|
31
35
|
// ============= Constants =============
|
|
32
36
|
var types_1 = require("./types");
|
|
33
37
|
Object.defineProperty(exports, "HOOK_EVENTS", { enumerable: true, get: function () { return types_1.HOOK_EVENTS; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,uCAAuC;AAEvC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,oBAAoB;AACpB,qCAImB;AAHf,oHAAA,aAAa,OAA6B;AAC1C,oHAAA,aAAa,OAA6B;AAC1C,6GAAA,MAAM,OAAsB;AAGhC,wCAAwC;AAExC,iCAAoD;AAA3C,oGAAA,WAAW,OAAA;AAAE,qGAAA,YAAY,OAAA;AAElC,qCAAqC;AAErC,mCAAsC;AAA7B,oGAAA,UAAU,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;AAEH,uCAAuC;AAEvC,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AAEd,oBAAoB;AACpB,qCAImB;AAHf,oHAAA,aAAa,OAA6B;AAC1C,oHAAA,aAAa,OAA6B;AAC1C,6GAAA,MAAM,OAAsB;AAGhC,6CAA6C;AAE7C,6BAAiD;AAAxC,yGAAA,kBAAkB,OAAA;AAAE,2FAAA,IAAI,OAAA;AAUjC,wCAAwC;AAExC,iCAAoD;AAA3C,oGAAA,WAAW,OAAA;AAAE,qGAAA,YAAY,OAAA;AAElC,qCAAqC;AAErC,mCAAsC;AAA7B,oGAAA,UAAU,OAAA"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* createSdkMcpServer - Create an SDK MCP Server
|
|
3
|
+
*
|
|
4
|
+
* This function creates an MCP server that can be integrated into the SDK
|
|
5
|
+
* and used with the CLI via the control protocol.
|
|
6
|
+
*/
|
|
7
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
8
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import type { ZodRawShape } from 'zod';
|
|
10
|
+
type ZodRawShapeV4 = {
|
|
11
|
+
[k: string]: any;
|
|
12
|
+
};
|
|
13
|
+
export type AnyZodRawShape = ZodRawShape | ZodRawShapeV4;
|
|
14
|
+
/**
|
|
15
|
+
* Infer the output type from a Zod raw shape.
|
|
16
|
+
* Works with both Zod 3 and Zod 4 schemas.
|
|
17
|
+
*/
|
|
18
|
+
export type InferShape<T extends AnyZodRawShape> = {
|
|
19
|
+
[K in keyof T]: T[K] extends {
|
|
20
|
+
_output: infer O;
|
|
21
|
+
} ? O : never;
|
|
22
|
+
} & {};
|
|
23
|
+
/**
|
|
24
|
+
* Tool handler function type.
|
|
25
|
+
* This is a simplified version that works with our InferShape type.
|
|
26
|
+
*/
|
|
27
|
+
export type ToolHandler<Schema extends AnyZodRawShape> = (args: InferShape<Schema>, extra: unknown) => CallToolResult | Promise<CallToolResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Tool definition for SDK MCP Server.
|
|
30
|
+
* Contains a handler function, so not serializable.
|
|
31
|
+
* Supports both Zod 3 and Zod 4 schemas.
|
|
32
|
+
*/
|
|
33
|
+
export interface SdkMcpToolDefinition<Schema extends AnyZodRawShape = AnyZodRawShape> {
|
|
34
|
+
/** Tool name */
|
|
35
|
+
name: string;
|
|
36
|
+
/** Tool description */
|
|
37
|
+
description: string;
|
|
38
|
+
/** Input schema as Zod shape */
|
|
39
|
+
inputSchema: Schema;
|
|
40
|
+
/** Handler function */
|
|
41
|
+
handler: ToolHandler<Schema>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Options for creating an SDK MCP Server.
|
|
45
|
+
*/
|
|
46
|
+
export interface SdkMcpServerOptions {
|
|
47
|
+
/** Server name (must be unique within the session) */
|
|
48
|
+
name: string;
|
|
49
|
+
/** Server version (defaults to "1.0.0") */
|
|
50
|
+
version?: string;
|
|
51
|
+
/** Tool definitions to register */
|
|
52
|
+
tools?: Array<SdkMcpToolDefinition<any>>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Result type for createSdkMcpServer.
|
|
56
|
+
*/
|
|
57
|
+
export interface SdkMcpServerResult {
|
|
58
|
+
/** Type discriminator - always "sdk" for SDK MCP servers */
|
|
59
|
+
type: 'sdk';
|
|
60
|
+
/** Server name */
|
|
61
|
+
name: string;
|
|
62
|
+
/** The MCP server instance */
|
|
63
|
+
instance: McpServer;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Helper function to define an MCP tool with type-safe schema and handler.
|
|
67
|
+
*
|
|
68
|
+
* This function provides a convenient way to create tool definitions that can be
|
|
69
|
+
* passed to createSdkMcpServer(). It ensures type safety between the input schema
|
|
70
|
+
* and the handler function parameters.
|
|
71
|
+
*
|
|
72
|
+
* @param name - The name of the tool (should be unique within the server)
|
|
73
|
+
* @param description - A description of what the tool does
|
|
74
|
+
* @param inputSchema - A Zod shape defining the input parameters
|
|
75
|
+
* @param handler - The function that executes when the tool is called
|
|
76
|
+
* @returns A tool definition object
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { tool, createSdkMcpServer } from '@tencent-ai/genie-agent-sdk';
|
|
81
|
+
* import { z } from 'zod';
|
|
82
|
+
*
|
|
83
|
+
* const weatherTool = tool(
|
|
84
|
+
* 'get_weather',
|
|
85
|
+
* 'Get current weather for a location',
|
|
86
|
+
* {
|
|
87
|
+
* location: z.string().describe('City name or coordinates'),
|
|
88
|
+
* units: z.enum(['celsius', 'fahrenheit']).optional().describe('Temperature units')
|
|
89
|
+
* },
|
|
90
|
+
* async ({ location, units }) => {
|
|
91
|
+
* const weather = await fetchWeather(location, units);
|
|
92
|
+
* return {
|
|
93
|
+
* content: [
|
|
94
|
+
* { type: 'text', text: `Weather in ${location}: ${weather.temperature}°` }
|
|
95
|
+
* ]
|
|
96
|
+
* };
|
|
97
|
+
* }
|
|
98
|
+
* );
|
|
99
|
+
*
|
|
100
|
+
* const server = createSdkMcpServer({
|
|
101
|
+
* name: 'weather-server',
|
|
102
|
+
* tools: [weatherTool]
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function tool<Schema extends AnyZodRawShape>(name: string, description: string, inputSchema: Schema, handler: ToolHandler<Schema>): SdkMcpToolDefinition<Schema>;
|
|
107
|
+
/**
|
|
108
|
+
* Create an SDK MCP Server.
|
|
109
|
+
*
|
|
110
|
+
* This function creates an MCP server that can be passed to the query() function
|
|
111
|
+
* via the mcpServers option. The server runs within the SDK process and
|
|
112
|
+
* communicates with the CLI via the control protocol.
|
|
113
|
+
*
|
|
114
|
+
* @param options - Server configuration options
|
|
115
|
+
* @returns SDK MCP server result that can be passed to query()
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* import { createSdkMcpServer, tool, query } from '@tencent-ai/genie-agent-sdk';
|
|
120
|
+
* import { z } from 'zod';
|
|
121
|
+
*
|
|
122
|
+
* // Define tools using the tool() helper
|
|
123
|
+
* const weatherTool = tool(
|
|
124
|
+
* 'get_weather',
|
|
125
|
+
* 'Get weather for a location',
|
|
126
|
+
* {
|
|
127
|
+
* location: z.string().describe('The location to get weather for'),
|
|
128
|
+
* units: z.enum(['celsius', 'fahrenheit']).optional()
|
|
129
|
+
* },
|
|
130
|
+
* async ({ location, units }) => {
|
|
131
|
+
* return {
|
|
132
|
+
* content: [
|
|
133
|
+
* { type: 'text', text: `Weather for ${location}: Sunny, 72°` }
|
|
134
|
+
* ]
|
|
135
|
+
* };
|
|
136
|
+
* }
|
|
137
|
+
* );
|
|
138
|
+
*
|
|
139
|
+
* // Create server with tools
|
|
140
|
+
* const myServer = createSdkMcpServer({
|
|
141
|
+
* name: 'my-custom-server',
|
|
142
|
+
* version: '1.0.0',
|
|
143
|
+
* tools: [weatherTool]
|
|
144
|
+
* });
|
|
145
|
+
*
|
|
146
|
+
* // Use in query
|
|
147
|
+
* const result = query({
|
|
148
|
+
* prompt: "What's the weather in Tokyo?",
|
|
149
|
+
* options: {
|
|
150
|
+
* mcpServers: {
|
|
151
|
+
* 'my-custom-server': myServer
|
|
152
|
+
* }
|
|
153
|
+
* }
|
|
154
|
+
* });
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare function createSdkMcpServer(options: SdkMcpServerOptions): SdkMcpServerResult;
|
|
158
|
+
export {};
|
|
159
|
+
//# sourceMappingURL=create-sdk-mcp-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-sdk-mcp-server.d.ts","sourceRoot":"","sources":["../../src/mcp/create-sdk-mcp-server.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAIvC,KAAK,aAAa,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC;AAC1C,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG,aAAa,CAAC;AAEzD;;;GAGG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,cAAc,IAAI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AC,MAAM,CAAC,GAC7B,oBAAoB,CAAC,MAAM,CAAC,CAO9B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAuCnF"}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* createSdkMcpServer - Create an SDK MCP Server
|
|
4
|
+
*
|
|
5
|
+
* This function creates an MCP server that can be integrated into the SDK
|
|
6
|
+
* and used with the CLI via the control protocol.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.tool = tool;
|
|
10
|
+
exports.createSdkMcpServer = createSdkMcpServer;
|
|
11
|
+
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
12
|
+
/**
|
|
13
|
+
* Helper function to define an MCP tool with type-safe schema and handler.
|
|
14
|
+
*
|
|
15
|
+
* This function provides a convenient way to create tool definitions that can be
|
|
16
|
+
* passed to createSdkMcpServer(). It ensures type safety between the input schema
|
|
17
|
+
* and the handler function parameters.
|
|
18
|
+
*
|
|
19
|
+
* @param name - The name of the tool (should be unique within the server)
|
|
20
|
+
* @param description - A description of what the tool does
|
|
21
|
+
* @param inputSchema - A Zod shape defining the input parameters
|
|
22
|
+
* @param handler - The function that executes when the tool is called
|
|
23
|
+
* @returns A tool definition object
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* import { tool, createSdkMcpServer } from '@tencent-ai/genie-agent-sdk';
|
|
28
|
+
* import { z } from 'zod';
|
|
29
|
+
*
|
|
30
|
+
* const weatherTool = tool(
|
|
31
|
+
* 'get_weather',
|
|
32
|
+
* 'Get current weather for a location',
|
|
33
|
+
* {
|
|
34
|
+
* location: z.string().describe('City name or coordinates'),
|
|
35
|
+
* units: z.enum(['celsius', 'fahrenheit']).optional().describe('Temperature units')
|
|
36
|
+
* },
|
|
37
|
+
* async ({ location, units }) => {
|
|
38
|
+
* const weather = await fetchWeather(location, units);
|
|
39
|
+
* return {
|
|
40
|
+
* content: [
|
|
41
|
+
* { type: 'text', text: `Weather in ${location}: ${weather.temperature}°` }
|
|
42
|
+
* ]
|
|
43
|
+
* };
|
|
44
|
+
* }
|
|
45
|
+
* );
|
|
46
|
+
*
|
|
47
|
+
* const server = createSdkMcpServer({
|
|
48
|
+
* name: 'weather-server',
|
|
49
|
+
* tools: [weatherTool]
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
function tool(name, description, inputSchema, handler) {
|
|
54
|
+
return {
|
|
55
|
+
name,
|
|
56
|
+
description,
|
|
57
|
+
inputSchema,
|
|
58
|
+
handler,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create an SDK MCP Server.
|
|
63
|
+
*
|
|
64
|
+
* This function creates an MCP server that can be passed to the query() function
|
|
65
|
+
* via the mcpServers option. The server runs within the SDK process and
|
|
66
|
+
* communicates with the CLI via the control protocol.
|
|
67
|
+
*
|
|
68
|
+
* @param options - Server configuration options
|
|
69
|
+
* @returns SDK MCP server result that can be passed to query()
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* import { createSdkMcpServer, tool, query } from '@tencent-ai/genie-agent-sdk';
|
|
74
|
+
* import { z } from 'zod';
|
|
75
|
+
*
|
|
76
|
+
* // Define tools using the tool() helper
|
|
77
|
+
* const weatherTool = tool(
|
|
78
|
+
* 'get_weather',
|
|
79
|
+
* 'Get weather for a location',
|
|
80
|
+
* {
|
|
81
|
+
* location: z.string().describe('The location to get weather for'),
|
|
82
|
+
* units: z.enum(['celsius', 'fahrenheit']).optional()
|
|
83
|
+
* },
|
|
84
|
+
* async ({ location, units }) => {
|
|
85
|
+
* return {
|
|
86
|
+
* content: [
|
|
87
|
+
* { type: 'text', text: `Weather for ${location}: Sunny, 72°` }
|
|
88
|
+
* ]
|
|
89
|
+
* };
|
|
90
|
+
* }
|
|
91
|
+
* );
|
|
92
|
+
*
|
|
93
|
+
* // Create server with tools
|
|
94
|
+
* const myServer = createSdkMcpServer({
|
|
95
|
+
* name: 'my-custom-server',
|
|
96
|
+
* version: '1.0.0',
|
|
97
|
+
* tools: [weatherTool]
|
|
98
|
+
* });
|
|
99
|
+
*
|
|
100
|
+
* // Use in query
|
|
101
|
+
* const result = query({
|
|
102
|
+
* prompt: "What's the weather in Tokyo?",
|
|
103
|
+
* options: {
|
|
104
|
+
* mcpServers: {
|
|
105
|
+
* 'my-custom-server': myServer
|
|
106
|
+
* }
|
|
107
|
+
* }
|
|
108
|
+
* });
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
function createSdkMcpServer(options) {
|
|
112
|
+
var _a;
|
|
113
|
+
// Create MCP server instance
|
|
114
|
+
const server = new mcp_js_1.McpServer({
|
|
115
|
+
name: options.name,
|
|
116
|
+
version: (_a = options.version) !== null && _a !== void 0 ? _a : '1.0.0',
|
|
117
|
+
}, {
|
|
118
|
+
capabilities: {
|
|
119
|
+
tools: options.tools ? {} : undefined,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
// Register tools
|
|
123
|
+
if (options.tools) {
|
|
124
|
+
for (const toolDef of options.tools) {
|
|
125
|
+
// Type assertion is needed because:
|
|
126
|
+
// 1. MCP SDK's ToolCallback uses z.objectOutputType<Args, ZodTypeAny> for args inference
|
|
127
|
+
// 2. We use InferShape<Schema> which is structurally equivalent but TypeScript cannot verify
|
|
128
|
+
// 3. The 'extra' parameter type differs (RequestHandlerExtra vs unknown)
|
|
129
|
+
// At runtime, both produce the same shape, so this is safe.
|
|
130
|
+
server.registerTool(toolDef.name, {
|
|
131
|
+
description: toolDef.description,
|
|
132
|
+
inputSchema: toolDef.inputSchema,
|
|
133
|
+
}, toolDef.handler);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Return server info
|
|
137
|
+
return {
|
|
138
|
+
type: 'sdk',
|
|
139
|
+
name: options.name,
|
|
140
|
+
instance: server,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=create-sdk-mcp-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-sdk-mcp-server.js","sourceRoot":"","sources":["../../src/mcp/create-sdk-mcp-server.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;AA4GH,oBAYC;AAoDD,gDAuCC;AAjND,oEAAoE;AAiEpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,SAAgB,IAAI,CAChB,IAAY,EACZ,WAAmB,EACnB,WAAmB,EACnB,OAA4B;IAE5B,OAAO;QACH,IAAI;QACJ,WAAW;QACX,WAAW;QACX,OAAO;KACV,CAAC;AACN,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,SAAgB,kBAAkB,CAAC,OAA4B;;IAC3D,6BAA6B;IAC7B,MAAM,MAAM,GAAG,IAAI,kBAAS,CACxB;QACI,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,OAAO;KACtC,EACD;QACI,YAAY,EAAE;YACV,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;SACxC;KACJ,CACJ,CAAC;IAEF,iBAAiB;IACjB,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClC,oCAAoC;YACpC,yFAAyF;YACzF,6FAA6F;YAC7F,yEAAyE;YACzE,4DAA4D;YAC5D,MAAM,CAAC,YAAY,CACf,OAAO,CAAC,IAAI,EACZ;gBACI,WAAW,EAAE,OAAO,CAAC,WAAW;gBAChC,WAAW,EAAE,OAAO,CAAC,WAAW;aACnC,EACD,OAAO,CAAC,OAAO,CAClB,CAAC;QACN,CAAC;IACL,CAAC;IAED,qBAAqB;IACrB,OAAO;QACH,IAAI,EAAE,KAAK;QACX,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,QAAQ,EAAE,MAAM;KACnB,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP (Model Context Protocol) Integration
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for creating and managing SDK MCP servers
|
|
5
|
+
* that can be integrated with the CLI via the control protocol.
|
|
6
|
+
*/
|
|
7
|
+
export { createSdkMcpServer, tool } from './create-sdk-mcp-server';
|
|
8
|
+
export type { SdkMcpServerOptions, SdkMcpServerResult, SdkMcpToolDefinition, AnyZodRawShape, InferShape, ToolHandler, } from './create-sdk-mcp-server';
|
|
9
|
+
export { SdkControlServerTransport } from './sdk-control-server-transport';
|
|
10
|
+
export type { SendMcpMessageCallback } from './sdk-control-server-transport';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,yBAAyB,CAAC;AACnE,YAAY,EACR,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,WAAW,GACd,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,YAAY,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC"}
|
package/lib/mcp/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MCP (Model Context Protocol) Integration
|
|
4
|
+
*
|
|
5
|
+
* This module provides utilities for creating and managing SDK MCP servers
|
|
6
|
+
* that can be integrated with the CLI via the control protocol.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SdkControlServerTransport = exports.tool = exports.createSdkMcpServer = void 0;
|
|
10
|
+
var create_sdk_mcp_server_1 = require("./create-sdk-mcp-server");
|
|
11
|
+
Object.defineProperty(exports, "createSdkMcpServer", { enumerable: true, get: function () { return create_sdk_mcp_server_1.createSdkMcpServer; } });
|
|
12
|
+
Object.defineProperty(exports, "tool", { enumerable: true, get: function () { return create_sdk_mcp_server_1.tool; } });
|
|
13
|
+
var sdk_control_server_transport_1 = require("./sdk-control-server-transport");
|
|
14
|
+
Object.defineProperty(exports, "SdkControlServerTransport", { enumerable: true, get: function () { return sdk_control_server_transport_1.SdkControlServerTransport; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,iEAAmE;AAA1D,2HAAA,kBAAkB,OAAA;AAAE,6GAAA,IAAI,OAAA;AAUjC,+EAA2E;AAAlE,yIAAA,yBAAyB,OAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Control Server Transport
|
|
3
|
+
*
|
|
4
|
+
* Custom transport implementation that bridges SDK MCP servers to CLI process.
|
|
5
|
+
* This transport forwards MCP messages through the control protocol.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
8
|
+
import type { JSONRPCMessage as McpJSONRPCMessage } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
export type { McpJSONRPCMessage };
|
|
10
|
+
/**
|
|
11
|
+
* Callback function type for sending MCP messages to CLI.
|
|
12
|
+
*/
|
|
13
|
+
export type SendMcpMessageCallback = (message: McpJSONRPCMessage) => void;
|
|
14
|
+
/**
|
|
15
|
+
* SdkControlServerTransport - bridges MCP servers to CLI via control messages.
|
|
16
|
+
*
|
|
17
|
+
* This transport implements the MCP Transport interface and forwards all
|
|
18
|
+
* messages through a callback function that wraps them in control_request
|
|
19
|
+
* messages for the CLI.
|
|
20
|
+
*/
|
|
21
|
+
export declare class SdkControlServerTransport implements Transport {
|
|
22
|
+
private sendMcpMessage;
|
|
23
|
+
private isClosed;
|
|
24
|
+
onclose?: () => void;
|
|
25
|
+
onerror?: (error: Error) => void;
|
|
26
|
+
onmessage?: (message: McpJSONRPCMessage) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Create a new SDK Control Server Transport.
|
|
29
|
+
*
|
|
30
|
+
* @param sendMcpMessage - Callback function to forward MCP messages to CLI
|
|
31
|
+
*/
|
|
32
|
+
constructor(sendMcpMessage: SendMcpMessageCallback);
|
|
33
|
+
/**
|
|
34
|
+
* Start the transport.
|
|
35
|
+
* No-op since connection is already established via stdio.
|
|
36
|
+
*/
|
|
37
|
+
start(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Send a message to the CLI via control_request.
|
|
40
|
+
*
|
|
41
|
+
* @param message - The JSON-RPC message to send
|
|
42
|
+
*/
|
|
43
|
+
send(message: McpJSONRPCMessage): Promise<void>;
|
|
44
|
+
/**
|
|
45
|
+
* Close the transport.
|
|
46
|
+
*/
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Check if the transport is closed.
|
|
50
|
+
*/
|
|
51
|
+
get closed(): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Handle incoming message from CLI.
|
|
54
|
+
* This method should be called when the CLI sends a message to this server.
|
|
55
|
+
*
|
|
56
|
+
* @param message - The JSON-RPC message from CLI
|
|
57
|
+
*/
|
|
58
|
+
handleIncomingMessage(message: McpJSONRPCMessage): void;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=sdk-control-server-transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-control-server-transport.d.ts","sourceRoot":"","sources":["../../src/mcp/sdk-control-server-transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,IAAI,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAG9F,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAElC;;GAEG;AACH,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAE1E;;;;;;GAMG;AACH,qBAAa,yBAA0B,YAAW,SAAS;IACvD,OAAO,CAAC,cAAc,CAAyB;IAC/C,OAAO,CAAC,QAAQ,CAAS;IAGzB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEjD;;;;OAIG;gBACS,cAAc,EAAE,sBAAsB;IAIlD;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5B;;;;OAIG;IACG,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAQrD;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ5B;;OAEG;IACH,IAAI,MAAM,IAAI,OAAO,CAEpB;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI;CAM1D"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK Control Server Transport
|
|
4
|
+
*
|
|
5
|
+
* Custom transport implementation that bridges SDK MCP servers to CLI process.
|
|
6
|
+
* This transport forwards MCP messages through the control protocol.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SdkControlServerTransport = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* SdkControlServerTransport - bridges MCP servers to CLI via control messages.
|
|
12
|
+
*
|
|
13
|
+
* This transport implements the MCP Transport interface and forwards all
|
|
14
|
+
* messages through a callback function that wraps them in control_request
|
|
15
|
+
* messages for the CLI.
|
|
16
|
+
*/
|
|
17
|
+
class SdkControlServerTransport {
|
|
18
|
+
/**
|
|
19
|
+
* Create a new SDK Control Server Transport.
|
|
20
|
+
*
|
|
21
|
+
* @param sendMcpMessage - Callback function to forward MCP messages to CLI
|
|
22
|
+
*/
|
|
23
|
+
constructor(sendMcpMessage) {
|
|
24
|
+
this.isClosed = false;
|
|
25
|
+
this.sendMcpMessage = sendMcpMessage;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Start the transport.
|
|
29
|
+
* No-op since connection is already established via stdio.
|
|
30
|
+
*/
|
|
31
|
+
async start() {
|
|
32
|
+
// No-op: connection is already established via stdio
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Send a message to the CLI via control_request.
|
|
36
|
+
*
|
|
37
|
+
* @param message - The JSON-RPC message to send
|
|
38
|
+
*/
|
|
39
|
+
async send(message) {
|
|
40
|
+
if (this.isClosed) {
|
|
41
|
+
throw new Error('Transport is closed');
|
|
42
|
+
}
|
|
43
|
+
// Forward message to CLI via control_request
|
|
44
|
+
this.sendMcpMessage(message);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Close the transport.
|
|
48
|
+
*/
|
|
49
|
+
async close() {
|
|
50
|
+
var _a;
|
|
51
|
+
if (this.isClosed) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.isClosed = true;
|
|
55
|
+
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if the transport is closed.
|
|
59
|
+
*/
|
|
60
|
+
get closed() {
|
|
61
|
+
return this.isClosed;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Handle incoming message from CLI.
|
|
65
|
+
* This method should be called when the CLI sends a message to this server.
|
|
66
|
+
*
|
|
67
|
+
* @param message - The JSON-RPC message from CLI
|
|
68
|
+
*/
|
|
69
|
+
handleIncomingMessage(message) {
|
|
70
|
+
var _a;
|
|
71
|
+
if (this.isClosed) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
(_a = this.onmessage) === null || _a === void 0 ? void 0 : _a.call(this, message);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.SdkControlServerTransport = SdkControlServerTransport;
|
|
78
|
+
//# sourceMappingURL=sdk-control-server-transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk-control-server-transport.js","sourceRoot":"","sources":["../../src/mcp/sdk-control-server-transport.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAaH;;;;;;GAMG;AACH,MAAa,yBAAyB;IASlC;;;;OAIG;IACH,YAAY,cAAsC;QAZ1C,aAAQ,GAAG,KAAK,CAAC;QAarB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,KAAK;QACP,qDAAqD;IACzD,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,IAAI,CAAC,OAA0B;QACjC,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC3C,CAAC;QACD,6CAA6C;QAC7C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,KAAK;;QACP,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,OAAO;QACX,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,MAAA,IAAI,CAAC,OAAO,oDAAI,CAAC;IACrB,CAAC;IAED;;OAEG;IACH,IAAI,MAAM;QACN,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACH,qBAAqB,CAAC,OAA0B;;QAC5C,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAChB,OAAO;QACX,CAAC;QACD,MAAA,IAAI,CAAC,SAAS,qDAAG,OAAO,CAAC,CAAC;IAC9B,CAAC;CACJ;AArED,8DAqEC"}
|
package/lib/query.d.ts
CHANGED
|
@@ -20,6 +20,10 @@ export declare class Query implements AsyncGenerator<Message, void> {
|
|
|
20
20
|
private abortController;
|
|
21
21
|
private hookCallbacks;
|
|
22
22
|
private iterator;
|
|
23
|
+
private sdkMcpTransports;
|
|
24
|
+
private sdkMcpServerInstances;
|
|
25
|
+
private pendingMcpResponses;
|
|
26
|
+
private sdkMcpServerNames;
|
|
23
27
|
constructor(prompt: string | AsyncIterable<UserMessage>, options?: Options | undefined);
|
|
24
28
|
[Symbol.asyncIterator](): AsyncGenerator<Message, void>;
|
|
25
29
|
next(): Promise<IteratorResult<Message, void>>;
|
|
@@ -43,5 +47,30 @@ export declare class Query implements AsyncGenerator<Message, void> {
|
|
|
43
47
|
private registeredHooks?;
|
|
44
48
|
private registerHooks;
|
|
45
49
|
private buildHooksConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Extract SDK MCP servers from the mcpServers config.
|
|
52
|
+
* SDK servers are identified by having type: 'sdk'.
|
|
53
|
+
*/
|
|
54
|
+
private extractMcpServers;
|
|
55
|
+
/**
|
|
56
|
+
* Connect an SDK MCP server.
|
|
57
|
+
*/
|
|
58
|
+
private connectSdkMcpServer;
|
|
59
|
+
/**
|
|
60
|
+
* Send an MCP message from server to CLI.
|
|
61
|
+
*/
|
|
62
|
+
private sendMcpServerMessageToCli;
|
|
63
|
+
/**
|
|
64
|
+
* Handle MCP message control request from CLI.
|
|
65
|
+
*/
|
|
66
|
+
private handleMcpMessageRequest;
|
|
67
|
+
/**
|
|
68
|
+
* Handle MCP request and wait for response from MCP server.
|
|
69
|
+
*/
|
|
70
|
+
private handleMcpControlRequest;
|
|
71
|
+
/**
|
|
72
|
+
* Cleanup all resources.
|
|
73
|
+
*/
|
|
74
|
+
private cleanup;
|
|
46
75
|
}
|
|
47
76
|
//# sourceMappingURL=query.d.ts.map
|