Skip to content

Realtime Agent Using function_call Instead of mcp_call for Hosted MCP Tools #585

Description

@mpbacklund

Describe the bug

When using a hosted MCP server, realtime agents will occasionally attempt to perform a function_call instead of an mcp_call when invoking a tool from that server.

For example, I have a hosted MCP tool called metrics_get_data. When I try to invoke it, the following error occurs:

Error handling function call $t: Tool metrics_get_data not found

Inspecting the agent’s history shows that the tool was called as a function_call:

{
  "arguments": "{\"metricID\":\"iz270IOmPBgHJLwjKPdtX\"}",
  "itemId": "item_CRIzUATkoCK37YdpjH6b4",
  "name": "metrics_get_data",
  "output": null,
  "status": "in_progress",
  "type": "function_call"
}

However, metrics_get_data exists in the MCP tools list, not in the function tools list - yet the agent treats it as a function call.

Tool Lists (Sanitized)

MCP Tools

[
  { "name": "metrics_list" },
  { "name": "get_current_user" },
  { "name": "metrics_get_data" },
  { "name": "documentation_search" },
  ...
]

Function Tools

[
  { "type": "function", "name": "browserCreateHyperlink" },
  { "type": "function", "name": "browserNavigateToPage" },
  ...
]

Even though metrics_get_data clearly belongs in the MCP tool list, the agent’s request type is incorrectly set to function_call.

Debug Information

  • Agents SDK version: 0.1.9
  • Runtime environment: Node.js 18.17.1

Steps to Reproduce

  1. Set up a hosted MCP server with several tools.
  2. Provide that server to a realtime agent as shown below:
const agent = new RealtimeAgent({
  name: 'Cora AI Assistant',
  instructions: `You are an AI assistant. You have MCP tools and function tools available to you. Your available MCP tools are get_orders, create_order, ...`,
  tools: [
    hostedMcpTool({
      serverLabel: 'mcp',
      serverUrl: environment.mcpURL,
      requireApproval: 'never'
    }),
    // additional function tools here
  ],
});
  1. Optionally, include a list of the available MCP tools in the system prompt.
  2. Attempt to invoke an MCP tool (e.g., metrics_get_data).

In my testing, this error occurs roughly 50% of the time when MCP tools are listed in the system prompt. If tools are not listed in the system prompt the error does not happen as often, but still often enough to render our agent unreliable at best.

Expected Behavior

The realtime agent should correctly recognize and invoke tools based on their type:

MCP toolsmcp_call

Function toolsfunction_call

metrics_get_data should trigger an mcp_call, not a function_call.****

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions