Skip to content

Commit cf94019

Browse files
revert: revert cache impl (#221)
## Problem Unexpected timeout when calling mcp tools (second and beyond) ## Solution Removing the faulty cache implementation ## Rationale Revert
1 parent c9a1054 commit cf94019

File tree

2 files changed

+6
-160
lines changed

2 files changed

+6
-160
lines changed

lib/hermes/client/base.ex

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ defmodule Hermes.Client.Base do
66

77
import Peri
88

9-
alias Hermes.Client.Cache
109
alias Hermes.Client.Operation
1110
alias Hermes.Client.Request
1211
alias Hermes.Client.State
@@ -1110,8 +1109,6 @@ defmodule Hermes.Client.Base do
11101109
})
11111110
end
11121111

1113-
Cache.cleanup(state.client_info["name"])
1114-
11151112
state.transport.layer.shutdown(state.transport.name)
11161113
end
11171114

@@ -1178,15 +1175,15 @@ defmodule Hermes.Client.Base do
11781175
method: request.method
11791176
})
11801177

1181-
meta =
1182-
if is_map(error),
1183-
do: %{error_code: error["code"], error_message: error["message"]},
1184-
else: %{errors: Enum.map(error, &Peri.Error.error_to_map/1)}
1185-
11861178
Telemetry.execute(
11871179
Telemetry.event_client_error(),
11881180
%{duration: elapsed_ms, system_time: System.system_time()},
1189-
Map.merge(%{id: id, method: request.method}, meta)
1181+
%{
1182+
id: id,
1183+
method: request.method,
1184+
error_code: error["code"],
1185+
error_message: error["message"]
1186+
}
11901187
)
11911188
end
11921189

@@ -1225,44 +1222,6 @@ defmodule Hermes.Client.Base do
12251222
end
12261223
end
12271224

1228-
defp process_successful_response(%{method: "tools/call"} = request, result, id, state) do
1229-
response = Response.from_json_rpc(%{"result" => result, "id" => id})
1230-
response = %{response | method: request.method}
1231-
elapsed_ms = Request.elapsed_time(request)
1232-
1233-
client = state.client_info["name"]
1234-
structured = result["structuredContent"]
1235-
tool = request.params["name"]
1236-
validator = Cache.get_tool_validator(client, tool)
1237-
1238-
if is_map(structured) and is_function(validator, 1) do
1239-
case validator.(structured) do
1240-
{:ok, _} ->
1241-
GenServer.reply(request.from, {:ok, response})
1242-
1243-
{:error, errors} ->
1244-
log_error_response(request, id, elapsed_ms, errors)
1245-
1246-
GenServer.reply(
1247-
request.from,
1248-
{:error,
1249-
Error.protocol(:parse_error, %{
1250-
errors: errors,
1251-
tool: tool,
1252-
request_id: request.id,
1253-
request_params: request.params,
1254-
request_method: request.method
1255-
})}
1256-
)
1257-
end
1258-
else
1259-
log_success_response(request, id, elapsed_ms)
1260-
GenServer.reply(request.from, {:ok, response})
1261-
end
1262-
1263-
state
1264-
end
1265-
12661225
defp process_successful_response(request, result, id, state) do
12671226
response = Response.from_json_rpc(%{"result" => result, "id" => id})
12681227
response = %{response | method: request.method}
@@ -1273,13 +1232,6 @@ defmodule Hermes.Client.Base do
12731232
method = request.method
12741233
from = request.from
12751234

1276-
if method == "tools/list" do
1277-
tools = response.result["tools"]
1278-
client = state.client_info["name"]
1279-
Cache.clear_tool_validators(client)
1280-
Cache.put_tool_validators(client, tools)
1281-
end
1282-
12831235
if method == "ping",
12841236
do: GenServer.reply(from, :pong),
12851237
else: GenServer.reply(from, {:ok, response})

test/hermes/client/base_test.exs

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,112 +1378,6 @@ defmodule Hermes.Client.BaseTest do
13781378
describe "tool output schema validation caching" do
13791379
setup :initialized_client
13801380

1381-
test "validates tool call output when structuredContent is present", %{client: client} do
1382-
expect(Hermes.MockTransport, :send_message, fn _, message ->
1383-
decoded = JSON.decode!(message)
1384-
assert decoded["method"] == "tools/list"
1385-
:ok
1386-
end)
1387-
1388-
list_task = Task.async(fn -> Hermes.Client.Base.list_tools(client) end)
1389-
Process.sleep(50)
1390-
1391-
request_id = get_request_id(client, "tools/list")
1392-
1393-
tools = [
1394-
%{
1395-
"name" => "get_weather",
1396-
"outputSchema" => %{
1397-
"type" => "object",
1398-
"properties" => %{
1399-
"temperature" => %{"type" => "number"},
1400-
"conditions" => %{"type" => "string"}
1401-
},
1402-
"required" => ["temperature", "conditions"]
1403-
}
1404-
}
1405-
]
1406-
1407-
response = tools_list_response(request_id, tools)
1408-
send_response(client, response)
1409-
assert {:ok, _} = Task.await(list_task)
1410-
1411-
expect(Hermes.MockTransport, :send_message, fn _, message ->
1412-
decoded = JSON.decode!(message)
1413-
assert decoded["method"] == "tools/call"
1414-
assert decoded["params"]["name"] == "get_weather"
1415-
:ok
1416-
end)
1417-
1418-
call_task =
1419-
Task.async(fn ->
1420-
Hermes.Client.Base.call_tool(client, "get_weather", %{"location" => "NYC"})
1421-
end)
1422-
1423-
Process.sleep(50)
1424-
call_request_id = get_request_id(client, "tools/call")
1425-
1426-
valid_structured = %{
1427-
"temperature" => 72.5,
1428-
"conditions" => "sunny"
1429-
}
1430-
1431-
content = [
1432-
%{
1433-
"type" => "text",
1434-
"text" => "The weather in NYC is 72.5°F and sunny"
1435-
}
1436-
]
1437-
1438-
response = %{
1439-
"jsonrpc" => "2.0",
1440-
"id" => call_request_id,
1441-
"result" => %{
1442-
"content" => content,
1443-
"structuredContent" => valid_structured,
1444-
"isError" => false
1445-
}
1446-
}
1447-
1448-
send_response(client, response)
1449-
1450-
assert {:ok, response} = Task.await(call_task)
1451-
assert response.result["structuredContent"] == valid_structured
1452-
1453-
expect(Hermes.MockTransport, :send_message, fn _, _ -> :ok end)
1454-
1455-
invalid_task =
1456-
Task.async(fn ->
1457-
Hermes.Client.Base.call_tool(client, "get_weather", %{"location" => "LA"})
1458-
end)
1459-
1460-
Process.sleep(50)
1461-
invalid_request_id = get_request_id(client, "tools/call")
1462-
1463-
invalid_structured = %{
1464-
"temperature" => "not a number",
1465-
"conditions" => "cloudy"
1466-
}
1467-
1468-
invalid_response = %{
1469-
"jsonrpc" => "2.0",
1470-
"id" => invalid_request_id,
1471-
"result" => %{
1472-
"content" => content,
1473-
"structuredContent" => invalid_structured,
1474-
"isError" => false
1475-
}
1476-
}
1477-
1478-
send_response(client, invalid_response)
1479-
1480-
assert {:error, error} = Task.await(invalid_task)
1481-
assert error.reason == :parse_error
1482-
assert error.data[:tool] == "get_weather"
1483-
assert is_list(error.data[:errors])
1484-
assert length(error.data[:errors]) > 0
1485-
end
1486-
14871381
test "handles tools with complex outputSchema", %{client: client} do
14881382
expect(Hermes.MockTransport, :send_message, fn _, _ -> :ok end)
14891383

0 commit comments

Comments
 (0)