@@ -106,8 +106,7 @@ def post(url, payload, timeout, session_id=None):
106106 return (responses [- 1 ] if responses else None ), response_session_id
107107
108108
109- def rpc (method , params , rpc_id , deadline , session_id = None ,
110- url = MCP_URL_DEFAULT ):
109+ def rpc (method , params , rpc_id , deadline , session_id = None , url = None ):
111110 """Issue one JSON-RPC request within the shared time budget.
112111
113112 ``session_id`` is threaded into the Mcp-Session-Id header on every
@@ -116,6 +115,8 @@ def rpc(method, params, rpc_id, deadline, session_id=None,
116115 is the canonical case), the returned id is propagated so the caller
117116 threads it into every subsequent request on the same session.
118117 """
118+ if url is None :
119+ url = MCP_URL
119120 remaining = deadline - time .monotonic ()
120121 if remaining <= 0.05 :
121122 raise TimeoutError ("time budget exhausted" )
@@ -136,9 +137,10 @@ def rpc(method, params, rpc_id, deadline, session_id=None,
136137 return None , next_session_id
137138
138139
139- def notify_initialized (deadline , session_id = None ,
140- url = MCP_URL_DEFAULT ):
140+ def notify_initialized (deadline , session_id = None , url = None ):
141141 """Best-effort notifications/initialized; stateless servers reply 202/empty."""
142+ if url is None :
143+ url = MCP_URL
142144 remaining = deadline - time .monotonic ()
143145 if remaining <= 0.05 :
144146 return session_id
@@ -171,14 +173,16 @@ def extract_context(result):
171173 return ""
172174
173175
174- def session_context (repo , workspace , deadline , mcp_url = MCP_URL_DEFAULT ):
176+ def session_context (repo , workspace , deadline , mcp_url = None ):
175177 """initialize -> initialized -> tools/call engraphis_session(action=start).
176178
177179 The Mcp-Session-Id returned by initialize is threaded into every
178180 subsequent request so a stateful transport (e.g. the dashboard /mcp
179181 endpoint) keeps the connection open and recognises the tool call as
180182 part of the same session.
181183 """
184+ if mcp_url is None :
185+ mcp_url = MCP_URL
182186 _ , session_id = rpc (
183187 "initialize" ,
184188 {
@@ -243,9 +247,9 @@ def build_additional_context(context, workspace, max_context_chars=None):
243247
244248
245249def main ():
246- mcp_url = os .environ .get ("ENGRAPHIS_MCP_URL" ) or MCP_URL_DEFAULT
247- budget_seconds = _env_float ("ENGRAPHIS_HOOK_BUDGET_S" , BUDGET_SECONDS_DEFAULT )
248- max_context_chars = _env_int ("ENGRAPHIS_HOOK_MAX_CHARS" , MAX_CONTEXT_CHARS_DEFAULT )
250+ mcp_url = os .environ .get ("ENGRAPHIS_MCP_URL" ) or MCP_URL
251+ budget_seconds = _env_float ("ENGRAPHIS_HOOK_BUDGET_S" , BUDGET_SECONDS )
252+ max_context_chars = _env_int ("ENGRAPHIS_HOOK_MAX_CHARS" , MAX_CONTEXT_CHARS )
249253 deadline = time .monotonic () + budget_seconds
250254 try :
251255 payload = json .loads (sys .stdin .read () or "{}" )
0 commit comments