Verify visible hello MCP run and add shared control lease
This commit is contained in:
@@ -6,6 +6,7 @@ import argparse
|
||||
from functools import wraps
|
||||
import os
|
||||
import sys
|
||||
import threading
|
||||
from typing import Any
|
||||
|
||||
from sdbg.mcp_adapter import McpSession
|
||||
@@ -102,6 +103,16 @@ def make_server(client: McpSession):
|
||||
"""Продолжить CPU; событие остановки читать через recent_events."""
|
||||
return client.continue_execution()
|
||||
|
||||
@tool()
|
||||
def claim_control() -> dict[str, Any]:
|
||||
"""Захватить управление CPU, если оно свободно; конфликт возвращает текущего владельца."""
|
||||
return client.claim_control()
|
||||
|
||||
@tool()
|
||||
def release_control() -> dict[str, Any]:
|
||||
"""Освободить своё управление CPU для VS Code или другого MCP-клиента."""
|
||||
return client.release_control()
|
||||
|
||||
@tool()
|
||||
def pause_execution() -> dict[str, Any]:
|
||||
"""Остановить CPU и вернуть текущую C-позицию."""
|
||||
@@ -128,8 +139,20 @@ def main() -> int:
|
||||
if not args.socket:
|
||||
parser.error('укажите --socket или SDBG_SOCKET')
|
||||
client = McpSession(args.socket)
|
||||
heartbeat_stop = threading.Event()
|
||||
heartbeat = None
|
||||
try:
|
||||
client.status() # Не публикуем инструменты для отсутствующей сессии.
|
||||
def renew_control():
|
||||
while not heartbeat_stop.wait(10):
|
||||
try:
|
||||
client.renew_control()
|
||||
except (SessionError, OSError):
|
||||
# Без lease обновлять нечего; следующая мутация захватит его.
|
||||
pass
|
||||
heartbeat = threading.Thread(target=renew_control, name='sdbg-mcp-heartbeat',
|
||||
daemon=True)
|
||||
heartbeat.start()
|
||||
server = make_server(client)
|
||||
server.run(transport='stdio')
|
||||
return 0
|
||||
@@ -137,6 +160,13 @@ def main() -> int:
|
||||
print('sdbg-mcp: ' + str(error), file=sys.stderr)
|
||||
return 1
|
||||
finally:
|
||||
heartbeat_stop.set()
|
||||
if heartbeat is not None:
|
||||
heartbeat.join(timeout=1)
|
||||
try:
|
||||
client.release_control()
|
||||
except (SessionError, OSError):
|
||||
pass
|
||||
try:
|
||||
client.clear_owned_breakpoints()
|
||||
except (SessionError, OSError):
|
||||
|
||||
Reference in New Issue
Block a user