Skip to content

Commit 2cfa9cd

Browse files
authored
Merge pull request #60 from nickpending/feature/mcp-quiet-mode-logging
feat: respect --quiet flag in MCP client logging
2 parents 0b25afd + 051058f commit 2cfa9cd

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
@@ -44,16 +44,38 @@ def __init__(self, name: str, server: Configuration.MCPServer, working_dir: path
4444
self._exit_stack = AsyncExitStack()
4545
self._tools: list[Tool] = []
4646
self._client_context: t.Any = None
47+
# Check if this MCP server should run in quiet mode
48+
self._is_quiet = "--quiet" in (server.args or [])
4749

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

5880
@asynccontextmanager
5981
async def _safe_stdio_context(

0 commit comments

Comments
 (0)