@copilotkit/runtime 1.8.8-next.1 → 1.8.9-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 (39) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/{chunk-3UU33HF6.mjs → chunk-AFJ3VQB4.mjs} +2 -2
  3. package/dist/{chunk-QF6GPOZV.mjs → chunk-HEKLYCFM.mjs} +2 -2
  4. package/dist/{chunk-HBCCZQBE.mjs → chunk-LFB4PE32.mjs} +64 -6
  5. package/dist/chunk-LFB4PE32.mjs.map +1 -0
  6. package/dist/{chunk-O4WMMGSX.mjs → chunk-TPDMN2N7.mjs} +2 -2
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +64 -5
  9. package/dist/index.js.map +1 -1
  10. package/dist/index.mjs +6 -4
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/lib/index.d.ts +1 -1
  13. package/dist/lib/index.js +64 -5
  14. package/dist/lib/index.js.map +1 -1
  15. package/dist/lib/index.mjs +6 -4
  16. package/dist/lib/integrations/index.d.ts +2 -2
  17. package/dist/lib/integrations/index.js +1 -1
  18. package/dist/lib/integrations/index.js.map +1 -1
  19. package/dist/lib/integrations/index.mjs +4 -4
  20. package/dist/lib/integrations/nest/index.d.ts +1 -1
  21. package/dist/lib/integrations/nest/index.js +1 -1
  22. package/dist/lib/integrations/nest/index.js.map +1 -1
  23. package/dist/lib/integrations/nest/index.mjs +2 -2
  24. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  25. package/dist/lib/integrations/node-express/index.js +1 -1
  26. package/dist/lib/integrations/node-express/index.js.map +1 -1
  27. package/dist/lib/integrations/node-express/index.mjs +2 -2
  28. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  29. package/dist/lib/integrations/node-http/index.js +1 -1
  30. package/dist/lib/integrations/node-http/index.js.map +1 -1
  31. package/dist/lib/integrations/node-http/index.mjs +1 -1
  32. package/dist/{shared-32a46e93.d.ts → shared-df478d34.d.ts} +6 -1
  33. package/package.json +2 -2
  34. package/src/lib/runtime/copilot-runtime.ts +32 -12
  35. package/src/lib/runtime/mcp-tools-utils.ts +60 -0
  36. package/dist/chunk-HBCCZQBE.mjs.map +0 -1
  37. /package/dist/{chunk-3UU33HF6.mjs.map → chunk-AFJ3VQB4.mjs.map} +0 -0
  38. /package/dist/{chunk-QF6GPOZV.mjs.map → chunk-HEKLYCFM.mjs.map} +0 -0
  39. /package/dist/{chunk-O4WMMGSX.mjs.map → chunk-TPDMN2N7.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint
3
- } from "../../../chunk-HBCCZQBE.mjs";
3
+ } from "../../../chunk-LFB4PE32.mjs";
4
4
  import "../../../chunk-EY6RUVB7.mjs";
5
5
  import "../../../chunk-5BIEM2UU.mjs";
6
6
  import "../../../chunk-SHBDMA63.mjs";
@@ -174,6 +174,11 @@ declare function extractParametersFromSchema(toolOrSchema?: MCPTool | MCPTool["s
174
174
  * @returns An array of Action<any> objects.
175
175
  */
176
176
  declare function convertMCPToolsToActions(mcpTools: Record<string, MCPTool>, mcpEndpoint: string): Action<any>[];
177
+ /**
178
+ * Generate better instructions for using MCP tools
179
+ * This is used to enhance the system prompt with tool documentation
180
+ */
181
+ declare function generateMcpToolInstructions(toolsMap: Record<string, MCPTool>): string;
177
182
 
178
183
  /**
179
184
  * <Callout type="info">
@@ -402,4 +407,4 @@ type CommonConfig = {
402
407
  };
403
408
  declare function getCommonConfig(options: CreateCopilotRuntimeServerOptions): CommonConfig;
404
409
 
405
- export { CopilotRequestContextProperties as C, GraphQLContext as G, LogLevel as L, MCPTool as M, addCustomHeaderPlugin as a, CreateCopilotRuntimeServerOptions as b, createContext as c, buildSchema as d, CommonConfig as e, CopilotRuntimeLogger as f, getCommonConfig as g, createLogger as h, CopilotRuntimeRequest as i, CopilotRuntimeConstructorParams as j, CopilotRuntime as k, flattenToolCallsNoDuplicates as l, copilotKitEndpoint as m, langGraphPlatformEndpoint as n, MCPClient as o, MCPEndpointConfig as p, extractParametersFromSchema as q, resolveEndpointType as r, convertMCPToolsToActions as s };
410
+ export { CopilotRequestContextProperties as C, GraphQLContext as G, LogLevel as L, MCPTool as M, addCustomHeaderPlugin as a, CreateCopilotRuntimeServerOptions as b, createContext as c, buildSchema as d, CommonConfig as e, CopilotRuntimeLogger as f, getCommonConfig as g, createLogger as h, CopilotRuntimeRequest as i, CopilotRuntimeConstructorParams as j, CopilotRuntime as k, flattenToolCallsNoDuplicates as l, copilotKitEndpoint as m, langGraphPlatformEndpoint as n, MCPClient as o, MCPEndpointConfig as p, extractParametersFromSchema as q, resolveEndpointType as r, convertMCPToolsToActions as s, generateMcpToolInstructions as t };
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.8.8-next.1",
12
+ "version": "1.8.9-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.8-next.1"
66
+ "@copilotkit/shared": "1.8.9-next.0"
67
67
  },
68
68
  "keywords": [
69
69
  "copilotkit",
@@ -71,7 +71,13 @@ import { AbstractAgent } from "@agentwire/client";
71
71
  import { MessageRole } from "../../graphql/types/enums";
72
72
 
73
73
  // +++ MCP Imports +++
74
- import { MCPClient, MCPEndpointConfig, convertMCPToolsToActions } from "./mcp-tools-utils";
74
+ import {
75
+ MCPClient,
76
+ MCPEndpointConfig,
77
+ MCPTool,
78
+ convertMCPToolsToActions,
79
+ generateMcpToolInstructions,
80
+ } from "./mcp-tools-utils";
75
81
  // Define the function type alias here or import if defined elsewhere
76
82
  type CreateMCPClientFunction = (config: MCPEndpointConfig) => Promise<MCPClient>;
77
83
  // --- MCP Imports ---
@@ -348,17 +354,31 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
348
354
  });
349
355
 
350
356
  // Format instructions from the unique tools map
351
- const mcpToolInstructions = Array.from(uniqueMcpTools.values())
352
- .map((action) => {
353
- const paramsString =
354
- action.parameters && action.parameters.length > 0
355
- ? ` Parameters: ${action.parameters
356
- .map((p) => `${p.name}${p.required ? "*" : ""}(${p.type})`)
357
- .join(", ")}`
358
- : "";
359
- return `- ${action.name}:${paramsString} ${action.description || ""}`;
360
- })
361
- .join("\n");
357
+ // Convert Action objects to MCPTool format for the instruction generator
358
+ const toolsMap: Record<string, MCPTool> = {};
359
+ Array.from(uniqueMcpTools.values()).forEach((action) => {
360
+ toolsMap[action.name] = {
361
+ description: action.description || "",
362
+ schema: action.parameters
363
+ ? {
364
+ parameters: {
365
+ properties: action.parameters.reduce(
366
+ (acc, p) => ({
367
+ ...acc,
368
+ [p.name]: { type: p.type, description: p.description },
369
+ }),
370
+ {},
371
+ ),
372
+ required: action.parameters.filter((p) => p.required).map((p) => p.name),
373
+ },
374
+ }
375
+ : {},
376
+ execute: async () => ({}), // Placeholder, not used for instructions
377
+ };
378
+ });
379
+
380
+ // Generate instructions using the exported helper
381
+ const mcpToolInstructions = generateMcpToolInstructions(toolsMap);
362
382
 
363
383
  if (!mcpToolInstructions) {
364
384
  return messages; // No MCP tools to describe
@@ -126,3 +126,63 @@ export function convertMCPToolsToActions(
126
126
 
127
127
  return actions;
128
128
  }
129
+
130
+ /**
131
+ * Generate better instructions for using MCP tools
132
+ * This is used to enhance the system prompt with tool documentation
133
+ */
134
+ export function generateMcpToolInstructions(toolsMap: Record<string, MCPTool>): string {
135
+ if (!toolsMap || Object.keys(toolsMap).length === 0) {
136
+ return "";
137
+ }
138
+
139
+ const toolEntries = Object.entries(toolsMap);
140
+
141
+ // Generate documentation for each tool
142
+ const toolsDoc = toolEntries
143
+ .map(([name, tool]) => {
144
+ // Extract schema information if available
145
+ let paramsDoc = " No parameters required";
146
+
147
+ try {
148
+ if (tool.schema && typeof tool.schema === "object") {
149
+ const schema = tool.schema as any;
150
+
151
+ // Extract parameters from JSON Schema
152
+ if (schema.properties) {
153
+ const requiredParams = schema.required || [];
154
+
155
+ // Build parameter documentation from properties
156
+ const paramsList = Object.entries(schema.properties).map(([paramName, propSchema]) => {
157
+ const propDetails = propSchema as any;
158
+ const requiredMark = requiredParams.includes(paramName) ? "*" : "";
159
+ const typeInfo = propDetails.type || "any";
160
+ const description = propDetails.description ? ` - ${propDetails.description}` : "";
161
+
162
+ return ` - ${paramName}${requiredMark} (${typeInfo})${description}`;
163
+ });
164
+
165
+ if (paramsList.length > 0) {
166
+ paramsDoc = paramsList.join("\n");
167
+ }
168
+ }
169
+ }
170
+ } catch (e) {
171
+ console.error(`Error parsing schema for tool ${name}:`, e);
172
+ }
173
+
174
+ return `- ${name}: ${tool.description || ""}
175
+ ${paramsDoc}`;
176
+ })
177
+ .join("\n\n");
178
+
179
+ return `You have access to the following external tools provided by Model Context Protocol (MCP) servers:
180
+
181
+ ${toolsDoc}
182
+
183
+ When using these tools:
184
+ 1. Only provide valid parameters according to their type requirements
185
+ 2. Required parameters are marked with *
186
+ 3. Format API calls correctly with the expected parameter structure
187
+ 4. Always check tool responses to determine your next action`;
188
+ }