MCPcopy
hub / github.com/CopilotKit/CopilotKit / executeWildcardTool

Method executeWildcardTool

packages/core/src/core/run-handler.ts:661–791  ·  view source on GitHub ↗

* Execute a wildcard tool. * Wildcard tools receive args wrapped as `{toolName, args}`, which differs from * specific tools, so this method keeps its own arg-wrapping logic rather than * delegating to `executeToolHandler`.

(
    wildcardTool: FrontendTool<any>,
    toolCall: ToolCall,
    message: Message,
    agent: AbstractAgent,
    agentId: string,
  )

Source from the content-addressed store, hash-verified

659 * delegating to `executeToolHandler`.
660 */
661 private async executeWildcardTool(
662 wildcardTool: FrontendTool<any>,
663 toolCall: ToolCall,
664 message: Message,
665 agent: AbstractAgent,
666 agentId: string,
667 ): Promise<boolean> {
668 // Check if wildcard tool is constrained to a specific agent
669 if (wildcardTool?.agentId && wildcardTool.agentId !== agent.agentId) {
670 // Wildcard tool is not available for this agent, skip it
671 return false;
672 }
673
674 let toolCallResult = "";
675 let errorMessage: string | undefined;
676
677 if (wildcardTool?.handler) {
678 let parsedArgs: unknown;
679 try {
680 parsedArgs = parseToolArguments(
681 toolCall.function.arguments,
682 toolCall.function.name,
683 );
684 } catch (error) {
685 const parseError =
686 error instanceof Error ? error : new Error(String(error));
687 errorMessage = parseError.message;
688 await this._internal.emitError({
689 error: parseError,
690 code: CopilotKitCoreErrorCode.TOOL_ARGUMENT_PARSE_FAILED,
691 context: {
692 agentId: agentId,
693 toolCallId: toolCall.id,
694 toolName: toolCall.function.name,
695 rawArguments: toolCall.function.arguments,
696 toolType: "wildcard",
697 messageId: message.id,
698 },
699 });
700 }
701
702 const wildcardArgs = {
703 toolName: toolCall.function.name,
704 args: parsedArgs,
705 };
706
707 await this._internal.notifySubscribers(
708 (subscriber) =>
709 subscriber.onToolExecutionStart?.({
710 copilotkit: this.core,
711 toolCallId: toolCall.id,
712 agentId: agentId,
713 toolName: toolCall.function.name,
714 args: wildcardArgs,
715 }),
716 "Subscriber onToolExecutionStart error:",
717 );
718

Callers 1

processAgentResultMethod · 0.95

Calls 5

randomUUIDFunction · 0.90
parseToolArgumentsFunction · 0.85
emitErrorMethod · 0.65
notifySubscribersMethod · 0.65
handlerMethod · 0.65

Tested by

no test coverage detected