MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / __init__

Method __init__

src/mcp_client/client.py:48–83  ·  view source on GitHub ↗
(
        self,
        url: str = None,
        tool_config_fp: str = None,
        *,
        session_id: Optional[str] = None,
        trace_path: Optional[str] = None,
        replay_trace_path: Optional[str] = None,
        connect: bool = True,
    )

Source from the content-addressed store, hash-verified

46 """
47
48 def __init__(
49 self,
50 url: str = None,
51 tool_config_fp: str = None,
52 *,
53 session_id: Optional[str] = None,
54 trace_path: Optional[str] = None,
55 replay_trace_path: Optional[str] = None,
56 connect: bool = True,
57 ):
58 hostname = os.getenv("MCP_HOSTNAME") or "localhost"
59 port = os.getenv("MCP_PORT") or 7002
60 basepath = os.getenv("MCP_BASEPATH") or "/mcp"
61 self.server_url = url or f"http://{hostname}:{port}{basepath}"
62 self._client: Client | None = None
63 self._session_id: Optional[str] = session_id
64
65 # Durable execution: tool-level trace/replay
66 self._trace_path: Optional[str] = trace_path
67 self._trace_lock = threading.Lock()
68 self._trace_seq = 0
69 self._replay_events: Optional[List[Dict[str, Any]]] = None
70 self._replay_idx = 0
71 self._replay_lock = threading.Lock()
72 if replay_trace_path:
73 self.enable_replay(replay_trace_path)
74
75 # Thread lock for thread-safe access to the event loop
76 # This is necessary because event loops are not thread-safe
77 self._loop_lock = threading.Lock()
78 self._loop: Optional[asyncio.AbstractEventLoop] = None
79
80 if connect:
81 self._loop = asyncio.new_event_loop()
82 asyncio.set_event_loop(self._loop)
83 self._loop.run_until_complete(self._init_client())
84
85 def _update_session_id_from_transport(self) -> None:
86 """

Callers

nothing calls this directly

Calls 2

enable_replayMethod · 0.95
_init_clientMethod · 0.95

Tested by

no test coverage detected