Skip to content
Open
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
43 changes: 20 additions & 23 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,12 @@ export async function connectToServer(
} else {
transport = createStdioTransport(config);

// Capture stderr for debugging - attach BEFORE connect
// Always stream stderr immediately so auth prompts are visible
// Capture stderr before connect so failed startups can surface
// helpful diagnostics without streaming server noise by default.
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}`);
stderrChunks.push(chunk.toString());
});
}
}
Expand All @@ -268,16 +265,6 @@ 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);
});
}
}

return {
client,
close: async () => {
Expand Down Expand Up @@ -328,16 +315,26 @@ function createStdioTransport(config: StdioServerConfig): StdioClientTransport {
}

/**
* List all tools from a connected client with retry logic
* List all tools from a connected client with retry logic and pagination support
*/
export async function listTools(client: Client): Promise<ToolInfo[]> {
return withRetry(async () => {
const result = await client.listTools();
return result.tools.map((tool: Tool) => ({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema as Record<string, unknown>,
}));
const allTools: ToolInfo[] = [];
let cursor: string | undefined;

do {
const result = await client.listTools(cursor ? { cursor } : undefined);
allTools.push(
...result.tools.map((tool: Tool) => ({
name: tool.name,
description: tool.description,
inputSchema: tool.inputSchema as Record<string, unknown>,
})),
);
cursor = result.nextCursor as string | undefined;
} while (cursor);

return allTools;
}, 'list tools');
}

Expand Down