Skip to content

The agent that grows with you

fix(mcp): identify hermes-agent in the MCP handshake clientInfo

yulunz8cfc4ddfe8b5
diff --git a/tests/tools/test_mcp_tool.py b/tests/tools/test_mcp_tool.py
index 2e9800fa29f..713984787f4 100644
--- a/tests/tools/test_mcp_tool.py
+++ b/tests/tools/test_mcp_tool.py
@@ -2548,6 +2548,23 @@ class TestMetricsTracking:
assert cap.tools is None
assert "tools" not in payload
+ def test_session_kwargs_carry_hermes_client_identity(self):
+ """ClientSession kwargs identify hermes-agent at its shipped version, not the SDK default."""
+ from tools.mcp_tool import MCPServerTask, _ensure_mcp_sdk
+ if not _ensure_mcp_sdk():
+ pytest.skip("mcp SDK not installed")
+ from hermes_cli import __version__ as hermes_version
+ kwargs = MCPServerTask("identity_test")._session_kwargs()
+ assert kwargs["client_info"].name == "hermes-agent"
+ assert kwargs["client_info"].version == hermes_version
+
+ def test_session_kwargs_omit_client_info_without_sdk_type(self, monkeypatch):
+ """SDK builds without mcp.types.Implementation get no client_info key (no NameError)."""
+ from tools import mcp_tool_transport
+ monkeypatch.setattr(mcp_tool_transport, "_hermes_client_info", lambda: None)
+ from tools.mcp_tool import MCPServerTask
+ assert "client_info" not in MCPServerTask("no_type_test")._session_kwargs()
+
# ---------------------------------------------------------------------------
# 14. MCPServerTask integration
# ---------------------------------------------------------------------------
diff --git a/tools/mcp_tool_transport.py b/tools/mcp_tool_transport.py
index a35f529e839..c847a0aadb1 100644
--- a/tools/mcp_tool_transport.py
+++ b/tools/mcp_tool_transport.py
@@ -27,6 +27,18 @@ _PROBE_INITIALIZE_BODY = ( # JSON-RPC ``initialize`` body for the content-type
'"capabilities":{},"clientInfo":{"name":"hermes-probe","version":"0.1"}}}')
+def _hermes_client_info():
+ """``Implementation(name="hermes-agent", version=<shipped version>)`` for the MCP handshake, or
+ ``None`` on SDK builds without the type. Without this, servers that key behavior or logs on
+ ``clientInfo`` see the SDK default ("mcp"/"0.1.0") instead of who is actually connecting."""
+ try:
+ from mcp.types import Implementation
+ except ImportError:
+ return None
+ from hermes_cli import __version__ as hermes_version
+ return Implementation(name="hermes-agent", version=hermes_version)
+
+
def _content_type_base(resp) -> str:
"""``content-type`` header of *resp* without parameters, lowercased."""
return resp.headers.get("content-type", "").split(";")[0].strip().lower()
@@ -167,7 +179,7 @@ class MCPServerTransportMixin:
return caps is None or getattr(caps, "tools", None) is not None
def _session_kwargs(self) -> dict:
- """ClientSession kwargs: sampling, elicitation, notification + logging callbacks."""
+ """ClientSession kwargs: client identity, sampling, elicitation, notification + logging callbacks."""
kwargs = {}
for handler in (self._sampling, self._elicitation):
if handler:
@@ -176,6 +188,9 @@ class MCPServerTransportMixin:
kwargs["message_handler"] = self._make_message_handler()
if _core._MCP_LOGGING_CALLBACK_SUPPORTED:
kwargs["logging_callback"] = self._make_logging_callback()
+ client_info = _hermes_client_info()
+ if client_info is not None and _core._client_session_accepts("client_info"):
+ kwargs["client_info"] = client_info
return kwargs
async def _negotiate_session(self, session, connect_timeout: float):