Synchronous convenience wrapper (used by `mcp-cli` entry-point and tests). Spins up its own event-loop when necessary.
(
async_command: Callable[..., Any],
config_file: str,
servers: list[str],
*,
extra_params: dict[str, Any | None],
)
| 224 | |
| 225 | |
| 226 | def run_command_sync( |
| 227 | async_command: Callable[..., Any], |
| 228 | config_file: str, |
| 229 | servers: list[str], |
| 230 | *, |
| 231 | extra_params: dict[str, Any | None], |
| 232 | ) -> Any: |
| 233 | """ |
| 234 | Synchronous convenience wrapper (used by `mcp-cli` entry-point and tests). |
| 235 | |
| 236 | Spins up its own event-loop when necessary. |
| 237 | """ |
| 238 | try: |
| 239 | loop = asyncio.get_running_loop() |
| 240 | except RuntimeError: |
| 241 | loop = asyncio.new_event_loop() |
| 242 | asyncio.set_event_loop(loop) |
| 243 | |
| 244 | return loop.run_until_complete( |
| 245 | run_command( |
| 246 | async_command, |
| 247 | config_file=config_file, |
| 248 | servers=servers, |
| 249 | extra_params=extra_params, |
| 250 | ) |
| 251 | ) |
| 252 | |
| 253 | |
| 254 | # --------------------------------------------------------------------------- # |