@@ -582,29 +582,8 @@ def test_mcp_server_module_entrypoint_runs_stdio_handshake(tmp_path):
582582
583583
584584def test_mcp_server_module_entrypoint_serves_first_tool_call (tmp_path ):
585- payload = "\n " .join ([
586- json .dumps ({
587- "jsonrpc" : "2.0" ,
588- "id" : 1 ,
589- "method" : "initialize" ,
590- "params" : {
591- "protocolVersion" : "2024-11-05" ,
592- "capabilities" : {},
593- "clientInfo" : {"name" : "first-tool-test" , "version" : "1" },
594- },
595- }),
596- json .dumps ({"jsonrpc" : "2.0" , "method" : "notifications/initialized" , "params" : {}}),
597- json .dumps ({
598- "jsonrpc" : "2.0" ,
599- "id" : 2 ,
600- "method" : "tools/call" ,
601- "params" : {
602- "name" : "engraphis_recall_context" ,
603- "arguments" : {"query" : "startup" , "workspace" : "default" , "token_budget" : 64 },
604- },
605- }),
606- "" ,
607- ])
585+ from scripts .smoke_installed_product import _Mcp
586+
608587 env = os .environ .copy ()
609588 env .update ({
610589 "ENGRAPHIS_DB_PATH" : str (tmp_path / "stdio-first-tool.db" ),
@@ -616,22 +595,15 @@ def test_mcp_server_module_entrypoint_serves_first_tool_call(tmp_path):
616595 "ENGRAPHIS_MCP_PRELOAD_EMBEDDER" : "auto" ,
617596 })
618597
619- result = subprocess .run (
620- [sys .executable , "-m" , "engraphis.mcp_server" ],
621- cwd = ROOT ,
622- env = env ,
623- input = payload ,
624- text = True ,
625- capture_output = True ,
626- timeout = 15 ,
627- check = False ,
628- )
629-
630- assert result .returncode == 0 , result .stderr
631- responses = [json .loads (line ) for line in result .stdout .splitlines () if line .strip ()]
632- by_id = {response ["id" ]: response for response in responses if "id" in response }
633- assert by_id [1 ]["result" ]["serverInfo" ]["name" ] == "engraphis_mcp"
634- assert by_id [2 ]["result" ]["content" ]
598+ # EOF cancels in-flight requests in the MCP SDK. Keep stdin open until the
599+ # response arrives, as a real client does, and retain bounded shutdown.
600+ with _Mcp ([sys .executable , "-m" , "engraphis.mcp_server" ], env , ROOT , 15 ) as client :
601+ result = client .request ("tools/call" , {
602+ "name" : "engraphis_recall_context" ,
603+ "arguments" : {"query" : "startup" , "workspace" : "default" , "token_budget" : 64 },
604+ })
605+ assert not result .get ("isError" )
606+ assert result ["content" ]
635607
636608
637609def test_classic_mcp_entrypoint_preserves_historical_server_identity (tmp_path ):
0 commit comments