Overview

When an LLM returns tool calls in its response, ModRouter does not automatically execute them. Instead, your application explicitly calls the tool execution API, giving you full control over:
  • Which tool calls to execute
  • User approval workflows
  • Security validation
  • Audit logging
The basic flow is: Chat Request → Review Tool Calls → Execute Tools → Continue Conversation.

Authentication

The /v1/mcp/tool/execute endpoint uses the same authentication as other inference endpoints like /v1/chat/completions: Virtual keys and authentication are independent layers that work together. For details on how to use virtual keys with authentication, see Authentication and virtual keys.

End-to-End Example

Step 1: Send Chat Request

Response with tool calls:
Tool names are prefixed with the MCP client name (e.g., filesystem_list_directory). This ensures uniqueness across multiple MCP clients.

Step 2: Execute the Tool

The request body matches the tool call object from the response:
Tool result response:

Step 3: Continue the Conversation

Assemble the full conversation history and continue:
Final response:

Response Formats

ModRouter supports two API formats for tool execution:

Chat Format (Default)

Use ?format=chat or omit the parameter:
Request:
Response:

Responses Format

Use ?format=responses for the Responses API format:
Request:
Response:

Multiple Tool Calls

LLMs often request multiple tools in a single response. Execute them in sequence or parallel:

Error Handling

Tool execution can fail for various reasons:
Gateway error responses:

Copy-Pastable Responses

Tool execution responses are designed to be directly appended to your conversation history:
The response includes:
  • Correct role field ("tool")
  • Matching tool_call_id for correlation
  • Properly formatted content

Next Steps

Agent Mode

Enable autonomous tool execution with auto-approval

Tool Filtering

Control which tools are available per request