Skip to content

perf(mcp): skip HTTP preflight probe on reconnect #40366

@huzhongx

Description

@huzhongx

Problem

MCPServerTask.run() performs a content-type preflight probe (_preflight_content_type) before every HTTP MCP connection — including reconnects. For remote MCP servers (e.g. beta.miaozhao.com/mcp), this adds 1-3 seconds of redundant round trips on every reconnect cycle.

Observed with a remote waw MCP server:

15:34:58  reload.mcp received
15:35:00  job-posting (stdio) ready         ~0.7s
15:35:01  chrome (stdio) ready              ~1.0s
15:35:05  waw HTTP protocol negotiated      ~7s  (includes preflight HEAD 405 + GET 406)
15:35:10  waw list_tools completed           +5s
          Total: ~14s — exceeds waw-web BFF timeout of 13.7s

The preflight sends HEAD (returns 405) then GET (returns 406) — ~3s of network RTTs that provide no actionable information on reconnect since the URL was already validated on first connect.

Fix

Skip preflight when self._ready.is_set() — the server has connected successfully before, so the URL is known-good.

-            if config.get("transport") != "sse":
+            if config.get("transport") != "sse" and not self._ready.is_set():
  • First connection: preflight runs as before (URL validation preserved)
  • Reconnect: preflight skipped, saves 1-3 RTTs per cycle

File: tools/mcp_tool.py, line ~1803 in _run_http call site within run().

Environment

  • Hermes Agent main branch (commit c8e80cd0b)
  • Remote HTTP MCP server with RTT ~700ms (HEAD 405, GET 406)
  • MCP keepalive triggers reconnect every ~3 minutes on connection drop

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havetool/mcpMCP client and OAuthtype/perfPerformance improvement or optimization

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions