Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,16 @@ export async function connectToServer(
transport = createStdioTransport(config);

// Capture stderr for debugging - attach BEFORE connect
// Always stream stderr immediately so auth prompts are visible
const stderrStream = transport.stderr;
if (stderrStream) {
stderrStream.on('data', (chunk: Buffer) => {
const text = chunk.toString();
stderrChunks.push(text);
// Always stream stderr immediately so users can see auth prompts
process.stderr.write(`[${serverName}] ${text}`);

// Only forward live stderr in debug mode to avoid noisy token burn.
if (process.env.MCP_DEBUG) {
process.stderr.write(`[${serverName}] ${text}`);
}
});
}
}
Expand All @@ -268,15 +270,8 @@ export async function connectToServer(
throw error;
}

// For successful connections, forward stderr to console
if (!isHttpServer(config)) {
const stderrStream = (transport as StdioClientTransport).stderr;
if (stderrStream) {
stderrStream.on('data', (chunk: Buffer) => {
process.stderr.write(chunk);
});
}
}
// For successful connections, stderr has already been captured above.
// It is only forwarded live when MCP_DEBUG is enabled.

return {
client,
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ function parseArgs(args: string[]): ParsedArgs {
result.command = 'version';
return result;

case '--debug':
process.env.MCP_DEBUG = '1';
break;

case '-d':
case '--with-descriptions':
result.withDescriptions = true;
Expand Down Expand Up @@ -367,6 +371,7 @@ Options:
-v, --version Show version number
-d, --with-descriptions Include tool descriptions
-c, --config <path> Path to mcp_servers.json config file
--debug Show MCP server stderr/debug output

Output:
mcp-cli/info/grep Human-readable text to stdout
Expand All @@ -385,6 +390,7 @@ Examples:
Environment Variables:
MCP_NO_DAEMON=1 Disable connection caching (force fresh connections)
MCP_DAEMON_TIMEOUT=N Set daemon idle timeout in seconds (default: 60)
MCP_DEBUG=1 Show MCP server stderr/debug output

Config File:
The CLI looks for mcp_servers.json in:
Expand Down