okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
311926416
main
1"""serve/test_tool_name_mcp_member.py - #5281: a namespaced MCP tool called by its last segment is that tool. 2 3Seen live (Qwen3.8-Flash-Next Q2_0 under DeepSeek Harness, stream): the request declared `mcp__assets__get_asset_info` and 4`mcp__assets__get_maintenance_plan`; the model wrote `<function=get_asset_info>` and `<function=get_maintenance_plan>`. Neither name was 5declared, so each block went back in `content` as XML, the harness got `stop` and the lookups never ran. The member after the last `__` 6is the tool when exactly one declared tool ends that way; a declared name always wins, and two tools with the same ending are not guessed. 7 8python -m unittest serve.test_tool_name_mcp_member -v 9""" 10import sys 11import unittest 12from pathlib import Path 13 14sys .path .insert (0 ,str (Path (__file__ ).resolve ().parents [1 ])) 15 16from serve .frontend import OutputParser # noqa: E402 17 18def tool (name ,prop = "id" ): 19return {"name" :name ,"parameters" : {"properties" : {prop : {"type" :"integer" }}}} 20 21TOOLS = [tool ("read_skill_resource" ,"path" ),tool ("mcp__assets__get_asset_info" ),tool ("mcp__assets__get_maintenance_plan" )] 22 23 24def call (name ,arg = "id" ,value = "101" ): 25return f"<tool_call>\n<function= { name } >\n<parameter= { arg } >\n { value } \n</parameter>\n</function>\n</tool_call>" 26 27 28def run (text ,tools = TOOLS ,stream_tools = True ,step = 5 ,recover = True ): 29p = OutputParser (thinking = False ,tools = tools ,stream_tools = stream_tools ,recover = recover ,declared_only = True ) 30evs = [] 31for i in range (0 ,len (text ),step ): 32evs += p .feed (text [i :i + step ]) 33evs += p .finish ("stop" ) 34return evs 35 36 37def calls (evs ): 38return [(e .call .name ,e .call .arguments )for e in evs if e .kind == "tool_call" ] 39 40 41class McpMember (unittest .TestCase ): 42def test_the_last_segment_is_the_tool (self ): 43for stream in (False ,True ): 44for step in (1 ,5 ,1000 ): 45evs = run (call ("get_asset_info" )+ "\n" + call ("get_maintenance_plan" ),stream_tools = stream ,step = step ) 46self .assertEqual (calls (evs ), [("mcp__assets__get_asset_info" , {"id" :101 }), 47 ("mcp__assets__get_maintenance_plan" , {"id" :101 })], (stream ,step )) 48self .assertFalse ([e for e in evs if e .kind == "content" and e .text .strip ()]) 49 50def test_the_full_name_is_unchanged (self ): 51self .assertEqual (calls (run (call ("mcp__assets__get_asset_info" ))), [("mcp__assets__get_asset_info" , {"id" :101 })]) 52 53def test_two_tools_with_the_same_ending_are_not_guessed (self ): 54tools = [tool ("mcp__a__search" ),tool ("mcp__b__search" )] 55evs = run (call ("search" ),tools ) 56self .assertEqual (calls (evs ), []) 57self .assertIn ("<function=search>" ,"" .join (e .text or "" for e in evs if e .kind == "content" )) 58 59def test_a_declared_name_wins (self ): 60tools = [tool ("get_asset_info" ),tool ("mcp__assets__get_asset_info" )] 61self .assertEqual (calls (run (call ("get_asset_info" ),tools )), [("get_asset_info" , {"id" :101 })]) 62 63def test_an_unrelated_name_stays_text (self ): 64evs = run (call ("get_asset" )) 65self .assertEqual (calls (evs ), []) 66 67def test_the_dotted_member_rule_is_unchanged (self ): 68tools = [tool ("mcp__fs.write_file" ,"path" )] 69self .assertEqual (calls (run (call ("write_file" ,"path" ,"x" ),tools )), [("mcp__fs.write_file" , {"path" :"x" })]) 70 71 72if __name__ == "__main__" : 73unittest .main ()