@copilotkit/runtime 1.8.7-next.0 → 1.8.8-next.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 (37) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-RU5CS42E.mjs → chunk-5TUGSSSM.mjs} +2 -2
  3. package/dist/{chunk-CWPYW7XE.mjs → chunk-62XKONGF.mjs} +2 -2
  4. package/dist/{chunk-JSV26III.mjs → chunk-XXKM3PJL.mjs} +22 -14
  5. package/dist/chunk-XXKM3PJL.mjs.map +1 -0
  6. package/dist/{chunk-BXJZ5GEO.mjs → chunk-YM7JEVJF.mjs} +2 -2
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +21 -13
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +4 -4
  11. package/dist/lib/index.d.ts +1 -1
  12. package/dist/lib/index.js +21 -13
  13. package/dist/lib/index.js.map +1 -1
  14. package/dist/lib/index.mjs +4 -4
  15. package/dist/lib/integrations/index.d.ts +2 -2
  16. package/dist/lib/integrations/index.js +1 -1
  17. package/dist/lib/integrations/index.js.map +1 -1
  18. package/dist/lib/integrations/index.mjs +4 -4
  19. package/dist/lib/integrations/nest/index.d.ts +1 -1
  20. package/dist/lib/integrations/nest/index.js +1 -1
  21. package/dist/lib/integrations/nest/index.js.map +1 -1
  22. package/dist/lib/integrations/nest/index.mjs +2 -2
  23. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  24. package/dist/lib/integrations/node-express/index.js +1 -1
  25. package/dist/lib/integrations/node-express/index.js.map +1 -1
  26. package/dist/lib/integrations/node-express/index.mjs +2 -2
  27. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  28. package/dist/lib/integrations/node-http/index.js +1 -1
  29. package/dist/lib/integrations/node-http/index.js.map +1 -1
  30. package/dist/lib/integrations/node-http/index.mjs +1 -1
  31. package/dist/{shared-350db43f.d.ts → shared-e61e0ebb.d.ts} +4 -4
  32. package/package.json +2 -2
  33. package/src/lib/runtime/copilot-runtime.ts +34 -24
  34. package/dist/chunk-JSV26III.mjs.map +0 -1
  35. /package/dist/{chunk-RU5CS42E.mjs.map → chunk-5TUGSSSM.mjs.map} +0 -0
  36. /package/dist/{chunk-CWPYW7XE.mjs.map → chunk-62XKONGF.mjs.map} +0 -0
  37. /package/dist/{chunk-BXJZ5GEO.mjs.map → chunk-YM7JEVJF.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint
3
- } from "../../../chunk-JSV26III.mjs";
3
+ } from "../../../chunk-XXKM3PJL.mjs";
4
4
  import "../../../chunk-EY6RUVB7.mjs";
5
5
  import "../../../chunk-5BIEM2UU.mjs";
6
6
  import "../../../chunk-SHBDMA63.mjs";
@@ -305,18 +305,18 @@ interface CopilotRuntimeConstructorParams<T extends Parameter[] | [] = []> {
305
305
  * Requires providing the `createMCPClient` function during instantiation.
306
306
  * @experimental
307
307
  */
308
- mcpEndpoints?: MCPEndpointConfig[];
308
+ mcpServers?: MCPEndpointConfig[];
309
309
  /**
310
310
  * A function that creates an MCP client instance for a given endpoint configuration.
311
311
  * This function is responsible for using the appropriate MCP client library
312
312
  * (e.g., `@copilotkit/runtime`, `ai`) to establish a connection.
313
- * Required if `mcpEndpoints` is provided.
313
+ * Required if `mcpServers` is provided.
314
314
  *
315
315
  * ```typescript
316
316
  * import { experimental_createMCPClient } from "ai"; // Import from vercel ai library
317
317
  * // ...
318
318
  * const runtime = new CopilotRuntime({
319
- * mcpEndpoints: [{ endpoint: "..." }],
319
+ * mcpServers: [{ endpoint: "..." }],
320
320
  * async createMCPClient(config) {
321
321
  * return await experimental_createMCPClient({
322
322
  * transport: {
@@ -343,7 +343,7 @@ declare class CopilotRuntime<const T extends Parameter[] | [] = []> {
343
343
  private delegateAgentProcessingToServiceAdapter;
344
344
  private observability?;
345
345
  private availableAgents;
346
- private readonly mcpEndpointsConfig?;
346
+ private readonly mcpServersConfig?;
347
347
  private mcpActionCache;
348
348
  private readonly createMCPClientImpl?;
349
349
  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.7-next.0",
12
+ "version": "1.8.8-next.0",
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.7-next.0"
66
+ "@copilotkit/shared": "1.8.8-next.0"
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
- mcpEndpoints?: MCPEndpointConfig[];
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 `mcpEndpoints` is provided.
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
- * mcpEndpoints: [{ endpoint: "..." }],
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 mcpEndpointsConfig?: MCPEndpointConfig[];
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.mcpEndpointsConfig = params?.mcpEndpoints;
306
+ this.mcpServersConfig = params?.mcpServers;
307
307
  this.createMCPClientImpl = params?.createMCPClient;
308
308
 
309
- // Validate: If mcpEndpoints are provided, createMCPClient must also be provided
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: `mcpEndpoints` were provided, but the `createMCPClient` function was not passed to the CopilotRuntime constructor. " +
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.mcpEndpointsConfig?.length)
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
- // Filter only MCP actions and format instructions
347
- const mcpToolInstructions = mcpActionsForRequest
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.mcpEndpointsConfig || [];
1114
- // Assuming frontend passes config via properties.mcpEndpoints
1115
- const requestEndpoints = (graphqlContext.properties?.mcpEndpoints ||
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
- [...baseEndpoints, ...requestEndpoints].forEach((ep) => {
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:`,