Skip to content

Commit e9d8bf5

Browse files
committed
Fix bug checking if client is Visual Studio Code
1 parent faf0047 commit e9d8bf5

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

reboot/mcp/servicers/session.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
replace_whole_floats_with_ints,
3232
)
3333
from reboot.protobuf import as_dict, from_model
34+
from rebootdev.aio.backoff import Backoff
3435

3536
logger = get_logger(__name__)
3637

@@ -233,16 +234,33 @@ async def send_and_receive():
233234
related_request_id=related_request_id,
234235
)
235236

236-
async def is_visual_studio_code():
237-
response = await self.ref().per_workflow(
238-
"Check if client is Visual Studio Code",
239-
).get(context)
240-
assert response.HasField("client_info")
241-
if response.HasField("client_info"):
242-
return response.client_info.name == "Visual Studio Code"
243-
return False
237+
async def check_is_vscode():
238+
backoff = Backoff(max_backoff_seconds=2)
239+
while True:
240+
response = await self.ref().always().get(
241+
context
242+
)
243+
if not response.HasField("client_info"):
244+
await backoff()
245+
continue
246+
# Technically `name` is required but
247+
# at least the MCP SDK doesn't
248+
# validate it via Pydantic, but Visual
249+
# Studio Code always seems to include
250+
# its name, so if we don't have a name
251+
# it is not Visual Studio Code.
252+
if response.client_info.HasField("name"):
253+
return response.client_info.name == "Visual Studio Code"
254+
return False
255+
256+
is_vscode = await at_least_once(
257+
"Check if client is Visual Studio Code",
258+
context,
259+
check_is_vscode,
260+
type=bool,
261+
)
244262

245-
if await is_visual_studio_code():
263+
if is_vscode:
246264
# For Visual Studio Code, also store the
247265
# _outgoing_ message, i.e., event, on the
248266
# aggregated stream.

0 commit comments

Comments
 (0)