Skip to content

The agent that grows with you

fix(mcp): warn about unknown tool_costs keys only on live discovery

Teknium4792107db881
diff --git a/tests/tools/test_mcp_tool_costs.py b/tests/tools/test_mcp_tool_costs.py
index 8faa3e773f7..90fe09b153a 100644
--- a/tests/tools/test_mcp_tool_costs.py
+++ b/tests/tools/test_mcp_tool_costs.py
@@ -176,8 +176,10 @@ def test_declarations_validate_translate_and_survive_a_native_trust_override(tmp
def test_a_chat_keeps_its_total_across_a_rotation_and_each_cron_run_has_its_own(session, caplog):
from cron.scheduler import _CronRunScope
from gateway.session_context import clear_session_vars, set_session_vars
- with caplog.at_level("WARNING", logger="tools.mcp_tool"):
- _register(dict(COSTED, tool_costs={**COSTED["tool_costs"], "mcp_srv_typo": 3}))
+ config = dict(COSTED, tool_costs={**COSTED["tool_costs"], "mcp_srv_typo": 3})
+ _register(config)
+ with caplog.at_level("WARNING", logger="tools.mcp_tool"): # live discovery sees the full tool list
+ registration._warn_unknown_cost_keys("srv", "srv", ["paid_render", "batch", "free_status"])
assert "mcp_srv_typo" in caplog.text # a key the server does not offer is named, never silently dropped
for _ in range(2):
_call("paid_render", chat="parent")
diff --git a/tools/mcp_tool_registration.py b/tools/mcp_tool_registration.py
index d8991f9a02d..862a6964aa2 100644
--- a/tools/mcp_tool_registration.py
+++ b/tools/mcp_tool_registration.py
@@ -82,10 +82,11 @@ def _record_tool_trust_metadata(server_name: str, config: dict, tools: list[Any]
_record_cost_policy(server_name, config, key)
hints = _core._tool_read_only_hints.setdefault(key, {})
hints.update({t.name: _annotation_read_only_hint(t) for t in tools if getattr(t, "name", None)})
- _warn_unknown_cost_keys(server_name, key, [t.name for t in tools if getattr(t, "name", None)])
def _warn_unknown_cost_keys(server_name: str, key, tool_names: list[str]) -> None:
+ """Live discovery only: the schema cache omits tools the user's include/exclude filter dropped, so a valid
+ cost for a filtered tool would read as unknown there."""
from tools.mcp_tool_costs import unknown_cost_keys
if unknown := unknown_cost_keys(_core._server_cost_policies.get(key), tool_names):
logger.warning("MCP server '%s': tool_costs names %s, which the server does not offer, so those calls "
@@ -430,6 +431,7 @@ def _register_server_tools(name: str, server: "MCPServerTask", config: dict) ->
should_register = _make_tool_filter(name, config)
key = _server_key_for_task(server)
_record_tool_trust_metadata(name, config, server._tools, key)
+ _warn_unknown_cost_keys(name, key, [t.name for t in server._tools if getattr(t, "name", None)])
candidates = _tool_candidates(name, server._tools, should_register, server.tool_timeout)
candidates += _utility_candidates(name, _select_utility_schemas(name, server, config), server.tool_timeout)
# Judged by the connection's owner scope (the ``(scope, name)`` key the registration below