@copilotkit/runtime 1.8.7 → 1.8.8-next.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/CHANGELOG.md +15 -0
- package/dist/{chunk-TOZ7TDZQ.mjs → chunk-3UU33HF6.mjs} +2 -2
- package/dist/{chunk-D453SZIW.mjs → chunk-HBCCZQBE.mjs} +29 -19
- package/dist/chunk-HBCCZQBE.mjs.map +1 -0
- package/dist/{chunk-ZD6BIBVB.mjs → chunk-O4WMMGSX.mjs} +2 -2
- package/dist/{chunk-S2W2IABM.mjs → chunk-QF6GPOZV.mjs} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -4
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +28 -18
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +4 -4
- package/dist/lib/integrations/index.d.ts +2 -2
- package/dist/lib/integrations/index.js +1 -1
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +4 -4
- package/dist/lib/integrations/nest/index.d.ts +1 -1
- package/dist/lib/integrations/nest/index.js +1 -1
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +2 -2
- package/dist/lib/integrations/node-express/index.d.ts +1 -1
- package/dist/lib/integrations/node-express/index.js +1 -1
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +2 -2
- package/dist/lib/integrations/node-http/index.d.ts +1 -1
- package/dist/lib/integrations/node-http/index.js +1 -1
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +1 -1
- package/dist/{shared-350db43f.d.ts → shared-32a46e93.d.ts} +7 -6
- package/package.json +2 -2
- package/src/lib/runtime/copilot-runtime.ts +34 -24
- package/src/lib/runtime/mcp-tools-utils.ts +16 -5
- package/dist/chunk-D453SZIW.mjs.map +0 -1
- /package/dist/{chunk-TOZ7TDZQ.mjs.map → chunk-3UU33HF6.mjs.map} +0 -0
- /package/dist/{chunk-ZD6BIBVB.mjs.map → chunk-O4WMMGSX.mjs.map} +0 -0
- /package/dist/{chunk-S2W2IABM.mjs.map → chunk-QF6GPOZV.mjs.map} +0 -0
|
@@ -137,6 +137,7 @@ interface MCPTool {
|
|
|
137
137
|
parameters?: {
|
|
138
138
|
properties?: Record<string, any>;
|
|
139
139
|
required?: string[];
|
|
140
|
+
jsonSchema?: Record<string, any>;
|
|
140
141
|
};
|
|
141
142
|
};
|
|
142
143
|
/** The function to call to execute the tool on the MCP server. */
|
|
@@ -162,10 +163,10 @@ interface MCPEndpointConfig {
|
|
|
162
163
|
}
|
|
163
164
|
/**
|
|
164
165
|
* Extracts CopilotKit-compatible parameters from an MCP tool schema.
|
|
165
|
-
* @param
|
|
166
|
+
* @param toolOrSchema The schema object from an MCPTool or the full MCPTool object.
|
|
166
167
|
* @returns An array of Parameter objects.
|
|
167
168
|
*/
|
|
168
|
-
declare function extractParametersFromSchema(
|
|
169
|
+
declare function extractParametersFromSchema(toolOrSchema?: MCPTool | MCPTool["schema"]): Parameter[];
|
|
169
170
|
/**
|
|
170
171
|
* Converts a map of MCPTools into an array of CopilotKit Actions.
|
|
171
172
|
* @param mcpTools A record mapping tool names to MCPTool objects.
|
|
@@ -305,18 +306,18 @@ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
|
|
|
305
306
|
* Requires providing the `createMCPClient` function during instantiation.
|
|
306
307
|
* @experimental
|
|
307
308
|
*/
|
|
308
|
-
|
|
309
|
+
mcpServers?: MCPEndpointConfig[];
|
|
309
310
|
/**
|
|
310
311
|
* A function that creates an MCP client instance for a given endpoint configuration.
|
|
311
312
|
* This function is responsible for using the appropriate MCP client library
|
|
312
313
|
* (e.g., `@copilotkit/runtime`, `ai`) to establish a connection.
|
|
313
|
-
* Required if `
|
|
314
|
+
* Required if `mcpServers` is provided.
|
|
314
315
|
*
|
|
315
316
|
* ```typescript
|
|
316
317
|
* import { experimental_createMCPClient } from "ai"; // Import from vercel ai library
|
|
317
318
|
* // ...
|
|
318
319
|
* const runtime = new CopilotRuntime({
|
|
319
|
-
*
|
|
320
|
+
* mcpServers: [{ endpoint: "..." }],
|
|
320
321
|
* async createMCPClient(config) {
|
|
321
322
|
* return await experimental_createMCPClient({
|
|
322
323
|
* transport: {
|
|
@@ -343,7 +344,7 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
343
344
|
private delegateAgentProcessingToServiceAdapter;
|
|
344
345
|
private observability?;
|
|
345
346
|
private availableAgents;
|
|
346
|
-
private readonly
|
|
347
|
+
private readonly mcpServersConfig?;
|
|
347
348
|
private mcpActionCache;
|
|
348
349
|
private readonly createMCPClientImpl?;
|
|
349
350
|
constructor(params?: CopilotRuntimeConstructorParams<T>);
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"publishConfig": {
|
|
10
10
|
"access": "public"
|
|
11
11
|
},
|
|
12
|
-
"version": "1.8.
|
|
12
|
+
"version": "1.8.8-next.1",
|
|
13
13
|
"sideEffects": false,
|
|
14
14
|
"main": "./dist/index.js",
|
|
15
15
|
"module": "./dist/index.mjs",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"rxjs": "^7.8.1",
|
|
64
64
|
"type-graphql": "2.0.0-rc.1",
|
|
65
65
|
"zod": "^3.23.3",
|
|
66
|
-
"@copilotkit/shared": "1.8.
|
|
66
|
+
"@copilotkit/shared": "1.8.8-next.1"
|
|
67
67
|
},
|
|
68
68
|
"keywords": [
|
|
69
69
|
"copilotkit",
|
|
@@ -228,19 +228,19 @@ export interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []
|
|
|
228
228
|
* Requires providing the `createMCPClient` function during instantiation.
|
|
229
229
|
* @experimental
|
|
230
230
|
*/
|
|
231
|
-
|
|
231
|
+
mcpServers?: MCPEndpointConfig[];
|
|
232
232
|
|
|
233
233
|
/**
|
|
234
234
|
* A function that creates an MCP client instance for a given endpoint configuration.
|
|
235
235
|
* This function is responsible for using the appropriate MCP client library
|
|
236
236
|
* (e.g., `@copilotkit/runtime`, `ai`) to establish a connection.
|
|
237
|
-
* Required if `
|
|
237
|
+
* Required if `mcpServers` is provided.
|
|
238
238
|
*
|
|
239
239
|
* ```typescript
|
|
240
240
|
* import { experimental_createMCPClient } from "ai"; // Import from vercel ai library
|
|
241
241
|
* // ...
|
|
242
242
|
* const runtime = new CopilotRuntime({
|
|
243
|
-
*
|
|
243
|
+
* mcpServers: [{ endpoint: "..." }],
|
|
244
244
|
* async createMCPClient(config) {
|
|
245
245
|
* return await experimental_createMCPClient({
|
|
246
246
|
* transport: {
|
|
@@ -270,7 +270,7 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
270
270
|
private availableAgents: Pick<AgentWithEndpoint, "name" | "id">[];
|
|
271
271
|
|
|
272
272
|
// +++ MCP Properties +++
|
|
273
|
-
private readonly
|
|
273
|
+
private readonly mcpServersConfig?: MCPEndpointConfig[];
|
|
274
274
|
private mcpActionCache = new Map<string, Action<any>[]>();
|
|
275
275
|
// --- MCP Properties ---
|
|
276
276
|
|
|
@@ -303,18 +303,14 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
303
303
|
this.observability = params?.observability_c;
|
|
304
304
|
this.agents = params?.agents ?? {};
|
|
305
305
|
// +++ MCP Initialization +++
|
|
306
|
-
this.
|
|
306
|
+
this.mcpServersConfig = params?.mcpServers;
|
|
307
307
|
this.createMCPClientImpl = params?.createMCPClient;
|
|
308
308
|
|
|
309
|
-
// Validate: If
|
|
310
|
-
if (
|
|
311
|
-
this.mcpEndpointsConfig &&
|
|
312
|
-
this.mcpEndpointsConfig.length > 0 &&
|
|
313
|
-
!this.createMCPClientImpl
|
|
314
|
-
) {
|
|
309
|
+
// Validate: If mcpServers are provided, createMCPClient must also be provided
|
|
310
|
+
if (this.mcpServersConfig && this.mcpServersConfig.length > 0 && !this.createMCPClientImpl) {
|
|
315
311
|
throw new CopilotKitMisuseError({
|
|
316
312
|
message:
|
|
317
|
-
"MCP Integration Error: `
|
|
313
|
+
"MCP Integration Error: `mcpServers` were provided, but the `createMCPClient` function was not passed to the CopilotRuntime constructor. " +
|
|
318
314
|
"Please provide an implementation for `createMCPClient`.",
|
|
319
315
|
});
|
|
320
316
|
}
|
|
@@ -323,7 +319,7 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
323
319
|
if (
|
|
324
320
|
params?.actions &&
|
|
325
321
|
(params?.remoteEndpoints?.some((e) => e.type === EndpointType.LangGraphPlatform) ||
|
|
326
|
-
this.
|
|
322
|
+
this.mcpServersConfig?.length)
|
|
327
323
|
) {
|
|
328
324
|
console.warn(
|
|
329
325
|
"Local 'actions' defined in CopilotRuntime might not be available to remote agents (LangGraph, MCP). Consider defining actions closer to the agent implementation if needed.",
|
|
@@ -343,8 +339,16 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
|
|
|
343
339
|
return messages; // No MCP tools for this specific request
|
|
344
340
|
}
|
|
345
341
|
|
|
346
|
-
//
|
|
347
|
-
const
|
|
342
|
+
// Create a map to deduplicate tools by name (keeping the last one if duplicates exist)
|
|
343
|
+
const uniqueMcpTools = new Map<string, Action<any>>();
|
|
344
|
+
|
|
345
|
+
// Add all MCP tools to the map with their names as keys
|
|
346
|
+
mcpActionsForRequest.forEach((action) => {
|
|
347
|
+
uniqueMcpTools.set(action.name, action);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
// Format instructions from the unique tools map
|
|
351
|
+
const mcpToolInstructions = Array.from(uniqueMcpTools.values())
|
|
348
352
|
.map((action) => {
|
|
349
353
|
const paramsString =
|
|
350
354
|
action.parameters && action.parameters.length > 0
|
|
@@ -1110,19 +1114,29 @@ please use an LLM adapter instead.`,
|
|
|
1110
1114
|
const requestSpecificMCPActions: Action<any>[] = [];
|
|
1111
1115
|
if (this.createMCPClientImpl) {
|
|
1112
1116
|
// 1. Determine effective MCP endpoints for this request
|
|
1113
|
-
const baseEndpoints = this.
|
|
1114
|
-
// Assuming frontend passes config via properties.
|
|
1115
|
-
const requestEndpoints = (graphqlContext.properties?.
|
|
1117
|
+
const baseEndpoints = this.mcpServersConfig || [];
|
|
1118
|
+
// Assuming frontend passes config via properties.mcpServers
|
|
1119
|
+
const requestEndpoints = (graphqlContext.properties?.mcpServers ||
|
|
1120
|
+
graphqlContext.properties?.mcpEndpoints ||
|
|
1116
1121
|
[]) as MCPEndpointConfig[];
|
|
1117
1122
|
|
|
1118
1123
|
// Merge and deduplicate endpoints based on URL
|
|
1119
1124
|
const effectiveEndpointsMap = new Map<string, MCPEndpointConfig>();
|
|
1120
|
-
|
|
1125
|
+
|
|
1126
|
+
// First add base endpoints (from runtime configuration)
|
|
1127
|
+
[...baseEndpoints].forEach((ep) => {
|
|
1121
1128
|
if (ep && ep.endpoint) {
|
|
1122
|
-
// Basic validation
|
|
1123
1129
|
effectiveEndpointsMap.set(ep.endpoint, ep);
|
|
1124
1130
|
}
|
|
1125
1131
|
});
|
|
1132
|
+
|
|
1133
|
+
// Then add request endpoints (from frontend), which will override duplicates
|
|
1134
|
+
[...requestEndpoints].forEach((ep) => {
|
|
1135
|
+
if (ep && ep.endpoint) {
|
|
1136
|
+
effectiveEndpointsMap.set(ep.endpoint, ep);
|
|
1137
|
+
}
|
|
1138
|
+
});
|
|
1139
|
+
|
|
1126
1140
|
const effectiveEndpoints = Array.from(effectiveEndpointsMap.values());
|
|
1127
1141
|
|
|
1128
1142
|
// 2. Fetch/Cache actions for effective endpoints
|
|
@@ -1134,14 +1148,10 @@ please use an LLM adapter instead.`,
|
|
|
1134
1148
|
// Not cached, fetch now
|
|
1135
1149
|
let client: MCPClient | null = null;
|
|
1136
1150
|
try {
|
|
1137
|
-
console.log(`MCP: Cache miss. Fetching tools for endpoint: ${endpointUrl}`);
|
|
1138
1151
|
client = await this.createMCPClientImpl(config);
|
|
1139
1152
|
const tools = await client.tools();
|
|
1140
1153
|
actionsForEndpoint = convertMCPToolsToActions(tools, endpointUrl);
|
|
1141
1154
|
this.mcpActionCache.set(endpointUrl, actionsForEndpoint); // Store in cache
|
|
1142
|
-
console.log(
|
|
1143
|
-
`MCP: Fetched and cached ${actionsForEndpoint.length} tools for ${endpointUrl}`,
|
|
1144
|
-
);
|
|
1145
1155
|
} catch (error) {
|
|
1146
1156
|
console.error(
|
|
1147
1157
|
`MCP: Failed to fetch tools from endpoint ${endpointUrl}. Skipping. Error:`,
|
|
@@ -10,6 +10,7 @@ export interface MCPTool {
|
|
|
10
10
|
parameters?: {
|
|
11
11
|
properties?: Record<string, any>;
|
|
12
12
|
required?: string[];
|
|
13
|
+
jsonSchema?: Record<string, any>;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
/** The function to call to execute the tool on the MCP server. */
|
|
@@ -36,13 +37,23 @@ export interface MCPEndpointConfig {
|
|
|
36
37
|
|
|
37
38
|
/**
|
|
38
39
|
* Extracts CopilotKit-compatible parameters from an MCP tool schema.
|
|
39
|
-
* @param
|
|
40
|
+
* @param toolOrSchema The schema object from an MCPTool or the full MCPTool object.
|
|
40
41
|
* @returns An array of Parameter objects.
|
|
41
42
|
*/
|
|
42
|
-
export function extractParametersFromSchema(
|
|
43
|
+
export function extractParametersFromSchema(
|
|
44
|
+
toolOrSchema?: MCPTool | MCPTool["schema"],
|
|
45
|
+
): Parameter[] {
|
|
43
46
|
const parameters: Parameter[] = [];
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
|
|
48
|
+
// Handle either full tool object or just schema
|
|
49
|
+
const schema =
|
|
50
|
+
"schema" in (toolOrSchema || {})
|
|
51
|
+
? (toolOrSchema as MCPTool).schema
|
|
52
|
+
: (toolOrSchema as MCPTool["schema"]);
|
|
53
|
+
|
|
54
|
+
const toolParameters = schema?.parameters || schema?.parameters?.jsonSchema;
|
|
55
|
+
const properties = toolParameters?.properties;
|
|
56
|
+
const requiredParams = new Set(toolParameters?.required || []);
|
|
46
57
|
|
|
47
58
|
if (!properties) {
|
|
48
59
|
return parameters;
|
|
@@ -80,7 +91,7 @@ export function convertMCPToolsToActions(
|
|
|
80
91
|
const actions: Action<any>[] = [];
|
|
81
92
|
|
|
82
93
|
for (const [toolName, tool] of Object.entries(mcpTools)) {
|
|
83
|
-
const parameters = extractParametersFromSchema(tool
|
|
94
|
+
const parameters = extractParametersFromSchema(tool);
|
|
84
95
|
|
|
85
96
|
const handler = async (params: any): Promise<any> => {
|
|
86
97
|
try {
|