Skip to content

Commit a5b3f45

Browse files
Replace loguru during tui
1 parent d988b76 commit a5b3f45

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "open-edison"
3-
version = "0.1.53"
3+
version = "0.1.54"
44
description = "Open-source MCP security, aggregation, and monitoring. Single-user, self-hosted MCP proxy."
55
readme = "README.md"
66
authors = [

src/mcp_importer/api.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from fastmcp import Client as FastMCPClient
99
from fastmcp import FastMCP
1010
from fastmcp.client.auth.oauth import FileTokenStorage
11-
from loguru import logger as log
11+
import questionary
12+
from loguru import logger as log # kept for non-TUI contexts; printing used in TUI flows
1213

1314
from src.config import Config, MCPServerConfig, get_config_json_path
1415
from src.mcp_importer import paths as _paths
@@ -169,9 +170,9 @@ async def _verify_async() -> bool: # noqa: C901
169170
and no_tokens
170171
and not has_inline_headers
171172
):
172-
log.info(
173-
"Skipping verification for remote server '{}' pending OAuth",
174-
server.name,
173+
questionary.print(
174+
f"Skipping verification for remote server '{server.name}' pending OAuth",
175+
style="bold fg:ansiyellow",
175176
)
176177
return True
177178
except Exception:
@@ -249,16 +250,20 @@ async def _list_tools_only() -> Any:
249250
return ping_succeeded
250251
except TimeoutError:
251252
if ping_succeeded:
252-
log.warning(
253-
f"Ping received from '{server.name}' but shutting down client timed out. Marking as success."
253+
questionary.print(
254+
f"Ping received from '{server.name}' but shutdown timed out (treating as success)",
255+
style="bold fg:ansiyellow",
254256
)
255257
else:
256-
log.error(
257-
f"MCP remote verification timed out (more than {connection_timeout}s) for '{server.name}', marking as failure."
258+
questionary.print(
259+
f"Verification timed out (> {connection_timeout}s) for '{server.name}'",
260+
style="bold fg:ansired",
258261
)
259262
return ping_succeeded
260263
except Exception as e: # noqa: BLE001
261-
log.error("MCP remote verification failed for '{}': {}", server.name, e)
264+
questionary.print(
265+
f"Verification failed for '{server.name}': {e}", style="bold fg:ansired"
266+
)
262267
return False
263268

264269
# Local/stdio servers: mount via proxy and perform a single light operation (tools only)
@@ -286,7 +291,9 @@ async def _list_tools_only() -> Any:
286291
await asyncio.wait_for(_list_tools_only(), timeout=30.0)
287292
return True
288293
except Exception as e:
289-
log.error("MCP verification failed for '{}': {}", server.name, e)
294+
questionary.print(
295+
f"Verification failed for '{server.name}': {e}", style="bold fg:ansired"
296+
)
290297
return False
291298
finally:
292299
for obj in (host_local, proxy_local):

src/setup_tui/main.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import asyncio
33

44
import questionary
5+
from loguru import logger as log
56

7+
import src.oauth_manager as oauth_mod
68
from src.config import MCPServerConfig
79
from src.mcp_importer.api import (
810
CLIENT,
@@ -170,6 +172,35 @@ def show_manual_setup_screen() -> None:
170172

171173
def run(*, dry_run: bool = False, skip_oauth: bool = False) -> None:
172174
"""Run the complete setup process."""
175+
# Suppress loguru output for a cleaner TUI experience
176+
import contextlib
177+
178+
with contextlib.suppress(Exception):
179+
log.remove()
180+
181+
# Route oauth_manager's log calls to questionary for TUI output
182+
class _TuiLogger:
183+
def _fmt(self, msg: object, *args: object) -> str:
184+
try:
185+
if isinstance(msg, str) and args:
186+
return msg.format(*args)
187+
except Exception:
188+
pass
189+
return str(msg)
190+
191+
def info(self, msg: object, *args: object, **kwargs: object) -> None:
192+
questionary.print(self._fmt(msg, *args), style="fg:ansiblue")
193+
194+
def debug(self, msg: object, *args: object, **kwargs: object) -> None:
195+
questionary.print(self._fmt(msg, *args), style="fg:ansiblack")
196+
197+
def warning(self, msg: object, *args: object, **kwargs: object) -> None:
198+
questionary.print(self._fmt(msg, *args), style="bold fg:ansiyellow")
199+
200+
def error(self, msg: object, *args: object, **kwargs: object) -> None:
201+
questionary.print(self._fmt(msg, *args), style="bold fg:ansired")
202+
203+
oauth_mod.log = _TuiLogger() # type: ignore[attr-defined]
173204
show_welcome_screen(dry_run=dry_run)
174205
# Additional setup steps will be added here
175206

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)