Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 133
fix: address remaining code review issues from PR #39#43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -29,6 +29,12 @@ export namespace MCP { | ||
| const log = Log.create({ service: "mcp" }) | ||
| const DEFAULT_TIMEOUT = 30_000 | ||
| const registeredMcpTools = new Set<string>() | ||
| export function isMcpTool(name: string): boolean { | ||
| return registeredMcpTools.has(name) | ||
| } | ||
| export const Resource = z | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: Much better than the | ||
| .object({ | ||
| name: z.string(), | ||
| @@ -215,7 +221,7 @@ export namespace MCP { | ||
| // Helper function to fetch prompts for a specific client | ||
| async function fetchPromptsForClient(clientName: string, client: Client) { | ||
| const prompts = await client.listPrompts().catch((e) => { | ||
| const prompts = await withTimeout(client.listPrompts(), DEFAULT_TIMEOUT).catch((e) => { | ||
| log.error("failed to get prompts", { clientName, error: e.message }) | ||
| return undefined | ||
| }) | ||
| @@ -237,7 +243,7 @@ export namespace MCP { | ||
| } | ||
| async function fetchResourcesForClient(clientName: string, client: Client) { | ||
| const resources = await client.listResources().catch((e) => { | ||
| const resources = await withTimeout(client.listResources(), DEFAULT_TIMEOUT).catch((e) => { | ||
| log.error("failed to get prompts", { clientName, error: e.message }) | ||
| return undefined | ||
| }) | ||
| @@ -683,6 +689,7 @@ export namespace MCP { | ||
| }), | ||
| ) | ||
| registeredMcpTools.clear() | ||
| for (const { clientName, client, toolsResult } of toolsResults) { | ||
| if (!toolsResult) continue | ||
| const mcpConfig = config[clientName] | ||
| @@ -691,7 +698,9 @@ export namespace MCP { | ||
| for (const mcpTool of toolsResult.tools) { | ||
| const sanitizedClientName = clientName.replace(/[^a-zA-Z0-9_-]/g, "_") | ||
| const sanitizedToolName = mcpTool.name.replace(/[^a-zA-Z0-9_-]/g, "_") | ||
| result[sanitizedClientName + "_" + sanitizedToolName] = await convertMcpTool(mcpTool, client, timeout) | ||
| const toolName = sanitizedClientName + "_" + sanitizedToolName | ||
| registeredMcpTools.add(toolName) | ||
| result[toolName] = await convertMcpTool(mcpTool, client, timeout) | ||
| } | ||
| } | ||
| return result | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
praise: Replacing the
new Promise(async ...)anti-pattern with a clean.then()chain is the right fix. The explicit error on undefined template prevents silent blank prompts.