@@ -126,7 +126,9 @@ def _handle_post() -> Response:
126126 )
127127 elif not session_id :
128128 return Response (
129- json .dumps ({"error" : "Missing session ID. Send an initialize request first." }),
129+ json .dumps (
130+ {"error" : "Missing session ID. Send an initialize request first." }
131+ ),
130132 content_type = "application/json" ,
131133 status = 400 ,
132134 )
@@ -175,35 +177,6 @@ def _handle_delete() -> Response:
175177 )
176178
177179
178- _STALE_SESSION_WARNING = (
179- "[Warning: your session was not recognised"
180- " — the app may have restarted."
181- " Please call tools/list to refresh your tool list."
182- " Please ask the user to reconnect to the MCP server.]"
183- )
184-
185-
186- def _inject_warning (response_data : dict [str , Any ], warning : str ) -> None :
187- """Append a warning to a JSON-RPC response dict.
188-
189- For successful ``tools/call`` responses the warning is added as an
190- extra text content block so the agent sees it alongside the result.
191- For error responses the warning is appended to the error message.
192- Other responses (tools/list, resources/*) are left unchanged — the
193- JSON-RPC spec forbids extra top-level keys.
194- """
195- # tools/call success: result has a "content" list
196- result = response_data .get ("result" )
197- if isinstance (result , dict ) and isinstance (result .get ("content" ), list ):
198- result ["content" ].append ({"type" : "text" , "text" : warning })
199- return
200-
201- # Error response
202- error = response_data .get ("error" )
203- if isinstance (error , dict ) and "message" in error :
204- error ["message" ] += " " + warning
205-
206-
207180def _handle_initialize () -> InitializeResult :
208181 return InitializeResult (
209182 protocolVersion = LATEST_PROTOCOL_VERSION ,
0 commit comments