Skip to content

reusable mcp client#1646

Merged
pelikhan merged 5 commits intodevfrom
resuble-client
Jun 25, 2025
Merged

reusable mcp client#1646
pelikhan merged 5 commits intodevfrom
resuble-client

Conversation

@pelikhan
Copy link
Copy Markdown
Member

No description provided.

@pelikhan pelikhan changed the base branch from main to dev June 25, 2025 15:24
@github-actions
Copy link
Copy Markdown
Contributor

Investigator report

Context collection

  • run id: 15880479772
  • failed job
  • last successful run not found

AI Analysis

The failure is due to numerous TypeScript errors (TS2304: Cannot find name ...) during the compilation (tsc -p .) of the packages/vscode workspace.

Root Cause

Type names such as ChatTurnGenerationContext, DiagnosticSeverity, VectorIndexOptions, WorkspaceFile, PromptParameters, and many others, are not found by the TypeScript compiler within both the packages/core/src/*.ts files and packages/vscode/src/*.ts files.

Example error:

../core/src/agent.ts(166,56): error TS2304: Cannot find name 'ChatTurnGenerationContext'.

This occurs for dozens of types across many files, indicating that these types (interfaces, type aliases, enums, etc.) are missing from the current compilation context.

Code Responsible

Sample excerpt of a typical failed reference:

// likely in packages/core/src/agent.ts
function foo(context: ChatTurnGenerationContext) { ... }

But ChatTurnGenerationContext is not defined or imported.

This pattern is repeated for a long list of type names, e.g.

  • DiagnosticSeverity (in annotations.ts, state.ts)
  • WorkspaceFile, WorkspaceFileWithScore, WorkspaceFileIndex (in multiple files)
  • PromptParameters (in docsnotebook.ts, state.ts)
  • Many others.

Immediate Cause

  • These types are either:
    1. Not defined within the files themselves, and
    2. Not imported from any other module/package,
    3. Or the relevant file containing their definitions is not included/found in the TypeScript project, or the path to types was changed/removed.

This is a type resolution/import problem: TypeScript cannot see these type definitions in scope.


Potential Fix

Solution: Ensure that all missing types:

  • are correctly declared in the codebase,
  • are correctly exported from the file/module where they are declared,
  • and are correctly imported where referenced.

Typical patch: Add missing imports for all referenced types in each problem file.

If these types were moved to a dedicated types/common file/module, ensure the imports are updated.


Example Fix for a File

Suppose ChatTurnGenerationContext is now exported from a file core/src/types.ts. In agent.ts:

import type { ChatTurnGenerationContext } from "./types"; // or correct path

You must apply this process for every missing type in each affected file.


Next Steps

  1. Locate where these types are now defined.
  2. Update all files that reference these types to import them from the correct module.
  3. Ensure all relevant type files are included in the tsconfig.json paths.

If you want a concrete diff, let me know what type module or files now house these type definitions, or ask for a scan to locate (e.g. ChatTurnGenerationContext).

AI-generated content by gai may be incorrect. Use reactions to eval.

Added new type imports for better typing and code reliability.
})
.join("\n");
}
text = text || "";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactored toolResultContentToText function may return undefined if both res.text and res.content are missing or not strings, which could lead to runtime errors when calling .join("\n") on undefined. Please ensure text is always initialized as a string.

AI-generated content by pr-review-commit tool_result_content_to_text_logic may be incorrect. Use reactions to eval.

return res;
}

export class McpClientManager extends EventTarget implements AsyncDisposable {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patchInputSchema function uses structuredClone to copy the schema, but if the input is undefined or not an object, this will throw at runtime. Please add a guard to ensure inputSchema is defined and an object before cloning.

AI-generated content by pr-review-commit patch_input_schema_mutation may be incorrect. Use reactions to eval.

inputSchema: t.inputSchema as any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
inputSchema: patchInputSchema(t.inputSchema),
}) satisfies McpToolReference,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The patchInputSchema function deletes the $schema property, which may be required for some JSON schema consumers. Removing it could break downstream validation or tooling. Please confirm this is intentional and safe for all usages.

AI-generated content by pr-review-commit input_schema_patch_side_effect may be incorrect. Use reactions to eval.

const tools = await fs.listToolCallbacks();

await runPrompt((ctx) => {
for (const tool of tools) ctx.defTool(tools);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect usage in code sample: 'for (const tool of tools) ctx.defTool(tools);' should likely be 'ctx.defTool(tool);' to register each tool individually. This may confuse readers about correct usage.

AI-generated content by pr-docs-review-commit incorrect_tool_usage may be incorrect. Use reactions to eval.

@pelikhan pelikhan merged commit 6441f22 into dev Jun 25, 2025
12 of 13 checks passed
@pelikhan pelikhan deleted the resuble-client branch June 25, 2025 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant