Hey LiveKit team, I'm seeing an issue where the ag...
# agents
p
Hey LiveKit team, I'm seeing an issue where the agent is reporting a failure to the user, but the tool calls are actually succeeding. The logs show McpError: Timed out for my Google Calendar tools, but the calendar events were still created successfully.
Copy code
2025-11-05 18:39:31,128 - INFO __main__ - User said: I'm in Pacific Time Zone. Can we do today like 3 PM Pacific? 
2025-11-05 18:39:35,668 - ERROR livekit.agents - exception occurred while executing tool {"function": "google_calendar_find_busy_periods_in_calendar", "speech_id": "speech_ca8bfa26bc34"}
Traceback (most recent call last):
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/anyio/streams/memory.py", line 111, in receive
    return self.receive_nowait()
           ~~~~~~~~~~~~~~~~~~~^^
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/anyio/streams/memory.py", line 106, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/anyio/_core/_tasks.py", line 120, in fail_after
    yield cancel_scope
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/mcp/shared/session.py", line 272, in send_request
    response_or_error = await response_stream_reader.receive()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/anyio/streams/memory.py", line 119, in receive
    await receive_event.wait()
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 1783, in wait
    await self._event.wait()
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/asyncio/locks.py", line 213, in wait
    await fut
asyncio.exceptions.CancelledError: Cancelled via cancel scope 115e1a690; reason: deadline exceeded

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/mcp/shared/session.py", line 271, in send_request
    with anyio.fail_after(timeout):
         ~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/contextlib.py", line 162, in __exit__
    self.gen.throw(value)
    ~~~~~~~~~~~~~~^^^^^^^
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/anyio/_core/_tasks.py", line 123, in fail_after
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/livekit/agents/voice/generation.py", line 526, in _traceable_fnc_tool
    val = await function_callable()
          ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/livekit/agents/llm/mcp.py", line 100, in _tool_called
    tool_result = await self._client.call_tool(name, raw_arguments)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/mcp/client/session.py", line 279, in call_tool
    result = await self.send_request(
             ^^^^^^^^^^^^^^^^^^^^^^^^
    ...11 lines...
    )
    ^
  File "/Users/umair/.pyenv/versions/3.13.2/lib/python3.13/site-packages/mcp/shared/session.py", line 274, in send_request
    raise McpError(
    ...8 lines...
    )
mcp.shared.exceptions.McpError: Timed out while waiting for response to ClientRequest. Waited 5.0 seconds.
any help? @icy-policeman-64898 @refined-appointment-81829 this is my code where I tried putting in a timeout in mcp_servers within AgentSession but still ran into this error: mcp_servers=[mcp.MCPServerHTTP(mcp_url, timeout=30.0)],
r
The
timeout
parameter controls HTTP-level timeouts (connection, read/write), while
client_session_timeout_seconds
controls how long the MCP protocol waits for tool execution responses. Both parameters are shown in the Shopify example, where they use
timeout=30
and
client_session_timeout_seconds=10
. shopify.py:93-97 For Google Calendar operations, you'll likely want both values set to 30 seconds or higher to accommodate slower API responses.
p
Thank you so much. I wasn't aware of the client_session_timeout_seconds parameter.