MCPcopy
hub / github.com/IBM/AssetOpsBench / _run

Method _run

src/mcphub/__init__.py:94–129  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

92 return fut.result()
93
94 async def _run(self):
95 stack = AsyncExitStack()
96 sessions: Dict[str, ClientSession] = {}
97 stop_fut = None
98 try:
99 while True:
100 action, payload, fut = await self._queue.get()
101 if action == "stop":
102 stop_fut = fut
103 break
104 try:
105 if action == "open":
106 name, cmd, env = payload
107 params = StdioServerParameters(
108 command=cmd[0], args=cmd[1:], env=env
109 )
110 read, write = await stack.enter_async_context(
111 stdio_client(params)
112 )
113 session = await stack.enter_async_context(
114 ClientSession(read, write)
115 )
116 await session.initialize()
117 sessions[name] = session
118 _set(fut, None)
119 elif action == "list":
120 _set(fut, await sessions[payload].list_tools())
121 elif action == "call":
122 name, tool, args = payload
123 _set(fut, await sessions[name].call_tool(tool, args))
124 except Exception as exc:
125 _set(fut, exc, error=True)
126 finally:
127 await stack.aclose()
128 if stop_fut is not None:
129 _set(stop_fut, None)
130
131 def open(self, name, cmd, env):
132 self._submit("open", (name, cmd, env))

Callers 1

__init__Method · 0.95

Calls 4

_setFunction · 0.85
list_toolsMethod · 0.80
acloseMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected