Skip to content

Commit 051058f

Browse files
committed
feat: respect --quiet flag in MCP client logging
- Add _is_quiet property to MCP Client class - Suppress INFO/DEBUG logs when MCP server runs with --quiet - Still show ERROR/WARNING logs in quiet mode - Parse nerve-style log formats for proper log levels - Improves UX when orchestrating multiple MCP agents This change allows cleaner output when using MCP servers in orchestration scenarios, while preserving important error information.
1 parent cc17f91 commit 051058f

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

nerve/tools/mcp/client.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,38 @@ def __init__(self, name: str, server: Configuration.MCPServer, working_dir: path
4242
self._exit_stack = AsyncExitStack()
4343
self._tools: list[Tool] = []
4444
self._client_context: t.Any = None
45+
# Check if this MCP server should run in quiet mode
46+
self._is_quiet = "--quiet" in (server.args or [])
4547

4648
async def _logging_callback(
4749
self,
4850
params: mcp_types.LoggingMessageNotificationParams,
4951
) -> None:
5052
line = str(params.data)
51-
# parts = line.split("]", 2)
52-
# line = parts[1].strip() if len(parts) > 1 else line # remove timestamp
53-
# line = line.replace(str(params.level).upper(), "").strip() # remove level
54-
getattr(logger, str(params.level))(f"<{self.name}> {line}")
53+
54+
# In quiet mode, suppress verbose output but still show errors/warnings
55+
if self._is_quiet:
56+
# Parse the actual log level from nerve-formatted log lines
57+
if "] ERROR " in line or "] WARNING " in line:
58+
# Show errors and warnings even in quiet mode
59+
pass
60+
elif "] INFO " in line or "] DEBUG " in line or "🧠" in line or "📊" in line or "🛠️" in line:
61+
# Suppress informational logs and tool output in quiet mode
62+
return
63+
else:
64+
# For unstructured output (like tool results), suppress in quiet mode
65+
return
66+
67+
# Determine appropriate log level based on content
68+
if "] ERROR " in line:
69+
logger.error(f"<{self.name}> {line}")
70+
elif "] WARNING " in line:
71+
logger.warning(f"<{self.name}> {line}")
72+
elif "] INFO " in line:
73+
logger.info(f"<{self.name}> {line}")
74+
else:
75+
# Default to the level provided by MCP protocol
76+
getattr(logger, str(params.level))(f"<{self.name}> {line}")
5577

5678
@asynccontextmanager
5779
async def _safe_stdio_context(

0 commit comments

Comments
 (0)