Skip to content

Conversation

@akitaSummer
Copy link
Contributor

@akitaSummer akitaSummer commented Dec 29, 2025

Checklist
  • npm test passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)
Description of change

Summary by CodeRabbit

  • New Features

    • Structured graph tools support plus new endpoints exposing structured tool metadata and LangChain tools.
  • Dependencies

    • Added runtime libraries to enable LangChain/MCP integrations.
  • Tests

    • New tests validating structured tool behavior and LangChain tool integration.
  • Enhancements

    • Middleware now also records raw HTTP header data for tracing.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 29, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

📝 Walkthrough

Walkthrough

Adds a type-level alias for structured graph tools, stores graph-tool metadata in a static map, registers DynamicStructuredTool prototypes at load time, integrates LangChain MCP adapters into the MCP client, and adds controller endpoints/tests and minor middleware/test adjustments. (50 words)

Changes

Cohort / File(s) Summary
Core types & metadata
core/langchain-decorator/src/decorator/GraphTool.ts, core/langchain-decorator/src/util/GraphToolInfoUtil.ts
Adds IGraphStructuredTool<T> type alias; introduces GraphToolInfoUtil.graphToolMap, updates setGraphToolMetadata to populate it, and adds getAllGraphToolMetadata().
MCP client runtime
core/mcp-client/package.json, core/mcp-client/src/HttpMCPClient.ts
Adds dependency @langchain/mcp-adapters; HttpMCPClient now holds clientInfo: Implementation and exposes async getLangChainTool() using loadMcpTools.
Graph load & prototype creation
plugin/langchain/package.json, plugin/langchain/lib/graph/GraphLoadUnitHook.ts
Adds zod dependency; GraphLoadUnitHook gains tools: Map<...> initialized from GraphToolInfoUtil, implements createStructuredTool() and registers DynamicStructuredTool prototypes during preCreate.
LangChain test fixture & test
plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts, plugin/langchain/test/llm.test.ts
Controller injects structuredFooTool: IGraphStructuredTool<FooTool> and adds /structured endpoint; new test asserts structured tool response shape.
MCP-client test fixture & test
plugin/mcp-client/test/fixtures/apps/mcpclient/app/modules/bar/controller/AppController.ts, plugin/mcp-client/test/mcpclient.test.ts
Adds /hello-langchain-tools endpoint that calls mcpClient.getLangChainTool() and returns tools (name/description/schema); test validates tool list and schema.
Middleware change
plugin/controller/test/fixtures/apps/mcp-app/app/middleware/tracelog.js
Middleware now also pushes 'trace' and 'middleware' into ctx.req.rawHeaders in addition to setting ctx.req.headers.
Test adjustment
plugin/controller/test/http/request.test.ts
Replaced it.only with it inside a Node-version gated block.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant GraphLoadUnitHook
    participant GraphToolInfoUtil
    participant DIContainer as EggContainerFactory
    participant ProtoFactory as EggPrototypeCreatorFactory
    participant PrototypeRegistry

    Client->>GraphLoadUnitHook: preCreate/init
    GraphLoadUnitHook->>GraphToolInfoUtil: getAllGraphToolMetadata()
    GraphToolInfoUtil-->>GraphLoadUnitHook: Map<Class, IGraphToolMetadata>
    loop per graph tool metadata
        GraphLoadUnitHook->>DIContainer: load target tool instance
        GraphLoadUnitHook->>GraphLoadUnitHook: createStructuredTool(clazz, toolMeta)
        GraphLoadUnitHook->>ProtoFactory: build proto descriptor for DynamicStructuredTool
        ProtoFactory-->>PrototypeRegistry: register Singleton proto
    end
    PrototypeRegistry-->>Client: structured tool prototypes available
Loading
sequenceDiagram
    participant Caller
    participant HttpMCPClient
    participant MCPAdapter as `@langchain/mcp-adapters`
    participant SchemaBuilder
    participant Response

    Caller->>HttpMCPClient: getLangChainTool()
    HttpMCPClient->>MCPAdapter: loadMcpTools(clientInfo)
    MCPAdapter->>MCPAdapter: enumerate MCP tools
    loop for each tool
        MCPAdapter->>SchemaBuilder: build tool schema/metadata
        SchemaBuilder-->>MCPAdapter: tool + schema
    end
    MCPAdapter-->>HttpMCPClient: Array<DynamicStructuredTool>
    HttpMCPClient-->>Response: format tools with name, description, schema
    Response-->>Caller: HTTP 200 + tool list
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • killagu
  • gxkl

Poem

🐰 I hopped through code with a curious twitch,

tools and schemas stitched in a stitch,
Graphs now speak with structured tune,
MCP whispers under the moon,
Hop—tools registered, ready to switch ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add structured tool' directly aligns with the main changeset objective of introducing structured tool support across the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8ad4572 and 6c423f8.

📒 Files selected for processing (2)
  • plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts
  • plugin/langchain/test/llm.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugin/langchain/test/llm.test.ts
🧰 Additional context used
🧬 Code graph analysis (1)
plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts (2)
core/langchain-decorator/src/decorator/GraphTool.ts (1)
  • IGraphStructuredTool (31-31)
core/controller-decorator/src/decorator/http/HTTPMethod.ts (1)
  • HTTPMethod (7-23)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Runner-ubuntu (20)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Runner-macos (20)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Runner-macos (18)
  • GitHub Check: Runner-macos (16)
🔇 Additional comments (3)
plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts (3)

7-7: LGTM!

The import additions properly support the structured tool integration. Both imports are utilized in the new code.

Also applies to: 10-10


27-28: LGTM!

The injectable property follows the established pattern used by other dependencies in this controller. The type annotation correctly leverages the IGraphStructuredTool type alias with FooTool as the type parameter.


66-72: No action required. The structured() endpoint correctly accesses name and description properties from structuredFooTool. Both properties are publicly exposed in DynamicStructuredTool from langchain@1.1.2, and the implementation is valid.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @akitaSummer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces comprehensive support for structured tools within the system, primarily by integrating LangChain's DynamicStructuredTool capabilities. It centralizes the management of graph tool metadata, enables the HttpMCPClient to load LangChain-compatible tools, and dynamically registers these tools during the application's load unit lifecycle. The changes ensure that graph tools can be seamlessly exposed and utilized as structured tools, complete with schema validation provided by Zod, and are validated through new test cases and API endpoints.

Highlights

  • Structured Tool Type Definition: Introduced IGraphStructuredTool for better type safety and clarity when working with dynamic structured tools.
  • Centralized Graph Tool Metadata: GraphToolInfoUtil now maintains a static map of all registered graph tool metadata, enabling easier retrieval and management.
  • LangChain MCP Adapters Integration: The mcp-client now includes @langchain/mcp-adapters as a dependency, facilitating interaction with LangChain tools.
  • HttpMCPClient LangChain Tool Loading: HttpMCPClient has been enhanced with a getLangChainTool method to load and expose LangChain tools from the Model Context Protocol.
  • Dynamic Structured Tool Creation: The GraphLoadUnitHook now dynamically creates and registers DynamicStructuredTool instances based on IGraphTool definitions during the application lifecycle, making graph tools available as structured tools.
  • Zod Schema Integration: Added zod dependency to plugin/langchain to support schema validation for structured tools.
  • New Test Endpoints: New HTTP endpoints and corresponding tests were added to plugin/langchain and plugin/mcp-client to verify the functionality of structured tools and LangChain tool loading.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@socket-security
Copy link

socket-security bot commented Dec 29, 2025

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for structured tools, integrating them with the existing graph and MCP client infrastructure. The changes include adding a new IGraphStructuredTool type, updating GraphToolInfoUtil to cache tool metadata, and implementing a GraphLoadUnitHook to dynamically create and register structured tools as singleton prototypes. The MCP client is also updated to load LangChain tools. My review focuses on improving type safety, code clarity, and addressing a potentially incorrect dependency import.

import assert from 'node:assert';
import { EggContainerFactory } from '@eggjs/tegg-runtime';
import { DynamicStructuredTool } from 'langchain';
import * as z from 'zod/v4';
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The import from zod/v4 is highly unusual. The latest major version of the public zod package is v3, and it does not provide a v4 entry point. While the package.json specifies "zod": "^4.0.0", this version does not exist on the public npm registry, suggesting a private fork or a typo. This can cause confusion and build issues for other developers. Please change the import to import * as z from 'zod'; and adjust the dependency version if this is a mistake. If it's intentional, please add a comment explaining the reason for this specific import path.

await this.connect(this.#transport, this.options.requestOptions);
}
async getLangChainTool() {
return await loadMcpTools(this.clientInfo.name, this as any, {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The use of this as any bypasses TypeScript's type checking and can hide underlying type incompatibility issues. The HttpMCPClient class extends Client, which is likely the type expected by loadMcpTools. If there is a type mismatch causing this cast to be necessary, it should be addressed directly to ensure type safety and prevent potential runtime errors. Please either fix the type incompatibility or add a comment explaining why this cast is unavoidable.

Comment on lines +60 to +61
const toolMetadata = GraphToolInfoUtil.getGraphToolMetadata((toolsObj.proto as unknown as EggPrototypeWithClazz).clazz!);
const ToolDetail = MCPInfoUtil.getMCPToolArgsIndex((toolsObj.proto as unknown as EggPrototypeWithClazz).clazz!, 'execute');
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The expression (toolsObj.proto as unknown as EggPrototypeWithClazz).clazz! is repeated and uses multiple unsafe type assertions (as unknown as, !). This reduces code readability and introduces a risk of runtime errors if clazz is not present on the prototype. It would be safer and clearer to extract the class into a variable with a proper null check before using it.

        const toolClazz = (toolsObj.proto as EggPrototypeWithClazz).clazz;
        if (!toolClazz) {
          throw new Error(`Could not find class for prototype '${toolsObj.proto.name}'`);
        }
        const toolMetadata = GraphToolInfoUtil.getGraphToolMetadata(toolClazz);
        const ToolDetail = MCPInfoUtil.getMCPToolArgsIndex(toolClazz, 'execute');

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Nitpick comments (5)
core/mcp-client/src/HttpMCPClient.ts (1)

34-34: Add documentation for the new field.

The clientInfo field is publicly exposed but lacks documentation explaining its purpose and usage.

📝 Suggested documentation
+  /**
+   * Client implementation metadata used for MCP protocol identification.
+   */
   clientInfo: Implementation;
core/langchain-decorator/src/decorator/GraphTool.ts (1)

31-31: Consider adding documentation for the type alias.

The new IGraphStructuredTool type alias would benefit from JSDoc explaining its purpose and usage, especially since it involves complex type manipulation.

📝 Suggested documentation
+/**
+ * Extracts a DynamicStructuredTool type from a graph tool implementation,
+ * deriving the schema type from the tool's execute method parameters.
+ * @template T - The graph tool type extending IGraphTool
+ */
 export type IGraphStructuredTool<T extends IGraphTool> = DynamicStructuredTool<Parameters<T['execute']>[0]>;
core/langchain-decorator/src/util/GraphToolInfoUtil.ts (2)

7-7: Consider lifecycle management for the static Map.

The static graphToolMap is a mutable global state that persists for the application lifetime. Consider:

  1. Whether this map needs cleanup/reset capability (e.g., for testing)
  2. Potential memory implications if tools are dynamically loaded/unloaded
  3. Thread safety if the application runs in a concurrent context

If cleanup is needed, consider adding:

static clearGraphToolMetadata(): void {
  GraphToolInfoUtil.graphToolMap.clear();
}

17-19: Add documentation for the new method.

The getAllGraphToolMetadata method lacks documentation explaining its purpose, return value, and when it should be used.

📝 Suggested documentation
+  /**
+   * Retrieves all registered graph tool metadata.
+   * @returns Map of class constructors to their graph tool metadata
+   */
   static getAllGraphToolMetadata(): Map<EggProtoImplClass, IGraphToolMetadata> {
     return GraphToolInfoUtil.graphToolMap;
   }
plugin/langchain/lib/graph/GraphLoadUnitHook.ts (1)

69-69: Consider documenting the Object.setPrototypeOf pattern.

Using Object.setPrototypeOf(this, tool) to replace the instance's prototype is an advanced technique that effectively makes the StructuredTool instance behave as a DynamicStructuredTool. While this works, it's unconventional and may be surprising to maintainers. Consider adding a brief comment explaining why this approach is used instead of composition or delegation.

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8c089b and 709f639.

📒 Files selected for processing (11)
  • core/langchain-decorator/src/decorator/GraphTool.ts
  • core/langchain-decorator/src/util/GraphToolInfoUtil.ts
  • core/mcp-client/package.json
  • core/mcp-client/src/HttpMCPClient.ts
  • plugin/controller/test/http/request.test.ts
  • plugin/langchain/lib/graph/GraphLoadUnitHook.ts
  • plugin/langchain/package.json
  • plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts
  • plugin/langchain/test/llm.test.ts
  • plugin/mcp-client/test/fixtures/apps/mcpclient/app/modules/bar/controller/AppController.ts
  • plugin/mcp-client/test/mcpclient.test.ts
🧰 Additional context used
🧬 Code graph analysis (6)
core/langchain-decorator/src/util/GraphToolInfoUtil.ts (4)
core/types/core-decorator/model/EggPrototypeInfo.ts (1)
  • EggProtoImplClass (5-5)
core/langchain-decorator/src/model/GraphToolMetadata.ts (1)
  • IGraphToolMetadata (3-7)
core/core-decorator/src/util/MetadataUtil.ts (1)
  • MetadataUtil (5-97)
core/langchain-decorator/src/type/metadataKey.ts (1)
  • GRAPH_TOOL_METADATA (1-1)
plugin/langchain/test/llm.test.ts (1)
benchmark/http/app/router.js (1)
  • app (4-4)
plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts (2)
core/langchain-decorator/src/decorator/GraphTool.ts (1)
  • IGraphStructuredTool (31-31)
core/controller-decorator/src/decorator/http/HTTPMethod.ts (1)
  • HTTPMethod (7-23)
plugin/mcp-client/test/mcpclient.test.ts (1)
benchmark/http/app/router.js (1)
  • app (4-4)
plugin/mcp-client/test/fixtures/apps/mcpclient/app/modules/bar/controller/AppController.ts (1)
core/controller-decorator/src/decorator/http/HTTPMethod.ts (1)
  • HTTPMethod (7-23)
plugin/langchain/lib/graph/GraphLoadUnitHook.ts (8)
core/langchain-decorator/src/model/GraphMetadata.ts (1)
  • IGraphMetadata (4-8)
core/langchain-decorator/src/model/GraphToolMetadata.ts (1)
  • IGraphToolMetadata (3-7)
core/langchain-decorator/src/util/GraphInfoUtil.ts (1)
  • GraphInfoUtil (6-21)
core/langchain-decorator/src/util/GraphToolInfoUtil.ts (1)
  • GraphToolInfoUtil (6-20)
core/metadata/src/model/ProtoDescriptorHelper.ts (2)
  • clazz (90-132)
  • ProtoDescriptorHelper (21-181)
core/metadata/src/model/ProtoDescriptor/ClassProtoDescriptor.ts (1)
  • ClassProtoDescriptor (10-38)
core/metadata/src/factory/EggPrototypeCreatorFactory.ts (1)
  • EggPrototypeCreatorFactory (13-115)
core/runtime/src/factory/EggContainerFactory.ts (1)
  • EggContainerFactory (18-88)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Runner-macos (20)
  • GitHub Check: Runner-ubuntu (20)
  • GitHub Check: Runner-macos (16)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Runner-macos (18)
🔇 Additional comments (14)
plugin/controller/test/http/request.test.ts (1)

33-33: LGTM! Correctly removed exclusive test.

Removing it.only ensures this test runs as part of the full suite rather than in isolation, which is the correct behavior for production code.

plugin/mcp-client/test/mcpclient.test.ts (1)

140-169: LGTM! Well-structured test for LangChain tools integration.

The test correctly validates the new /mcpclient/hello-langchain-tools endpoint, checking both the response structure (length and tools array) and the tool schema format.

plugin/langchain/test/llm.test.ts (1)

80-111: LGTM! Comprehensive test for structured tool schema.

The test validates the structured tool endpoint with proper zod metadata verification, including the vendor/version standard fields and nested schema structure.

plugin/langchain/package.json (1)

78-78: Zod v4 usage appears compatible with current codebase patterns.

While Zod v4 does introduce breaking changes (stricter int() validation, stricter UUID validation, unified error API, and changed default value logic), the codebase uses only minimal Zod features: basic schema types (z.string(), z.number(), z.object()) with .describe() and .default() modifiers. No usage of .int(), .uuid(), custom error handling, or Zod parsing methods (parse/validate/safe) was found. The current schema definitions are compatible with v4.

plugin/mcp-client/test/fixtures/apps/mcpclient/app/modules/bar/controller/AppController.ts (1)

67-81: LGTM!

The new /hello-langchain-tools endpoint is well-structured for testing purposes. It correctly fetches LangChain tools via getLangChainTool() and maps them to a clean response containing the essential metadata (name, description, schema).

plugin/langchain/test/fixtures/apps/langchain/app/modules/bar/controller/AppController.ts (4)

7-7: LGTM!

Import correctly updated to include IGraphStructuredTool for the new structured tool typing.


10-10: LGTM!

Import updated to include FooTool type needed for the generic parameter of IGraphStructuredTool<FooTool>.


27-28: LGTM!

The structured tool injection follows the existing pattern in the controller. The IGraphStructuredTool<FooTool> type provides proper type inference for the injected tool.


66-73: LGTM!

The /structured endpoint correctly exposes the structured tool's metadata for testing purposes.

plugin/langchain/lib/graph/GraphLoadUnitHook.ts (5)

1-1: LGTM!

Import updates correctly bring in LifecyclePostInject, MCPInfoUtil, and SingletonProto needed for the structured tool implementation.


12-16: LGTM!

Imports correctly updated to include the necessary types and utilities for structured tool creation. The zod/v4 import aligns with Zod 4 usage patterns.


22-22: LGTM!

New tools map property follows the same pattern as the existing clazzMap for graph metadata.


27-27: LGTM!

Initialization of tools map mirrors the existing pattern for clazzMap.


42-51: LGTM!

The tool processing logic correctly creates structured tool prototypes when tool metadata is found. The pattern mirrors the existing graph metadata processing above it.

},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.23.0",
"@langchain/mcp-adapters": "^1.0.0",
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🌐 Web query:

@langchain/mcp-adapters npm package version 1.0.0

💡 Result:

I checked the package on official npm and CDN sources. The npm package @langchain/mcp-adapters is published (current visible npm release listed as 0.6.0 on npmjs.com) and the LangChain docs recommend installing @langchain/mcp-adapters. I could not find an official npm release page showing a 1.0.0 tag; jsDelivr shows higher CDN versions (e.g., 1.1.1) which may reflect mirrored/packaged builds rather than the npm registry listing. Sources: [npmjs package page][1], [LangChain docs][2], [jsDelivr version listing][3].

If you want, I can fetch the npm registry metadata directly to list all published versions.

Sources:
[1] https://www.npmjs.com/package/%40langchain/mcp-adapters
[2] https://docs.langchain.com/oss/javascript/langchain/mcp
[3] https://www.jsdelivr.com/package/npm/%40langchain/mcp-adapters


Fix version constraint: @langchain/mcp-adapters version 1.0.0 does not exist on npm.

The latest published version on npm registry is 0.6.0. The current constraint ^1.0.0 will fail during installation. Update to a published version (e.g., ^0.6.0 or later if available).

🤖 Prompt for AI Agents
In core/mcp-client/package.json around line 40, the dependency version for
"@langchain/mcp-adapters" is set to "^1.0.0" which does not exist on npm; change
the version to a published release (for example "^0.6.0" or the latest
available) in the dependencies list so installations succeed, then run npm
install (or yarn) and update lockfile if present.

Comment on lines +119 to +125
async getLangChainTool() {
return await loadMcpTools(this.clientInfo.name, this as any, {
throwOnLoadError: true,
prefixToolNameWithServerName: false,
additionalToolNamePrefix: '',
});
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# First, find where loadMcpTools is defined and its signature
rg -n 'export.*loadMcpTools|function loadMcpTools|const loadMcpTools' --type=ts --type=tsx -A 15

Repository: eggjs/tegg

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Find all usages of getLangChainTool
rg -n 'getLangChainTool' --type=ts --type=tsx -B 2 -A 2

Repository: eggjs/tegg

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Check the HttpMCPClient class definition and see what interface it implements
rg -n 'class HttpMCPClient|interface.*HttpMCPClient' --type=ts --type=tsx -A 20

Repository: eggjs/tegg

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Look for the interface that loadMcpTools expects
rg -n 'MCPClient|MCPClientI' --type=ts --type=tsx | head -30

Repository: eggjs/tegg

Length of output: 81


🏁 Script executed:

#!/bin/bash
# Find where loadMcpTools is defined and its signature
rg -n 'export.*loadMcpTools|function loadMcpTools|const loadMcpTools' --type=ts -A 15

Repository: eggjs/tegg

Length of output: 36


🏁 Script executed:

#!/bin/bash
# Find all usages of getLangChainTool
rg -n 'getLangChainTool' --type=ts -B 2 -A 2

Repository: eggjs/tegg

Length of output: 1063


🏁 Script executed:

#!/bin/bash
# Check the HttpMCPClient class definition
rg -n 'class HttpMCPClient' --type=ts -A 30

Repository: eggjs/tegg

Length of output: 3642


🏁 Script executed:

#!/bin/bash
# Search for MCPClient interface definitions
rg -n 'interface.*MCPClient|type.*MCPClient' --type=ts | head -20

Repository: eggjs/tegg

Length of output: 141


🏁 Script executed:

#!/bin/bash
# Find the loadMcpTools function definition
fd -t f -e ts . | xargs grep -l 'loadMcpTools' | head -10

Repository: eggjs/tegg

Length of output: 192


🏁 Script executed:

#!/bin/bash
# Get the full file path and context around loadMcpTools definition
rg -n 'loadMcpTools' --type=ts -B 5 -A 20 | head -100

Repository: eggjs/tegg

Length of output: 9429


🏁 Script executed:

#!/bin/bash
# Check what Client base class HttpMCPClient extends
rg -n "from.*Client|import.*Client" core/mcp-client/src/HttpMCPClient.ts

Repository: eggjs/tegg

Length of output: 385


🏁 Script executed:

#!/bin/bash
# Check the return value of loadMcpTools in the usage
cat core/mcp-client/src/HttpMCPClient.ts | head -130 | tail -20

Repository: eggjs/tegg

Length of output: 624


🏁 Script executed:

#!/bin/bash
# Check package.json to see the version of @langchain/mcp-adapters
find . -name "package.json" -type f | xargs grep -l "mcp-adapters" 2>/dev/null

Repository: eggjs/tegg

Length of output: 116


🏁 Script executed:

#!/bin/bash
# Look at the actual usage in test files to understand the return type better
cat plugin/mcp-client/test/fixtures/apps/mcpclient/app/modules/bar/controller/AppController.ts | head -80 | tail -20

Repository: eggjs/tegg

Length of output: 510


🏁 Script executed:

#!/bin/bash
# Check if there are any type definitions or imports related to MCPClient interface
rg -n "MCPClient|interface.*Client" --type=ts core/mcp-client/src/ -A 5 | head -50

Repository: eggjs/tegg

Length of output: 4012


🏁 Script executed:

#!/bin/bash
# Verify the complete file at HttpMCPClient.ts to ensure we see the full context
wc -l core/mcp-client/src/HttpMCPClient.ts

Repository: eggjs/tegg

Length of output: 94


🏁 Script executed:

#!/bin/bash
# Check if there are any other callers of getLangChainTool besides the one in AppController
rg -n 'getLangChainTool' --type=ts

Repository: eggjs/tegg

Length of output: 276


Rename method and remove type bypass to improve naming consistency and type safety.

Three issues need to be addressed:

  1. Naming inconsistency: Method is named getLangChainTool (singular) but returns an array of tools, confirmed by the test usage that calls .length and .map() on the result. Rename to getLangChainTools.

  2. Type safety bypass: Line 120 uses this as any, circumventing TypeScript's type checking. Remove the cast to rely on proper type compatibility.

  3. Missing documentation: Add JSDoc to explain the return type and behavior.

The method has one caller in plugin/mcp-client/test/fixtures/apps/mcpclient/app/modules/bar/controller/AppController.ts:72 that will need updating when renamed.

🤖 Prompt for AI Agents
In core/mcp-client/src/HttpMCPClient.ts around lines 119 to 125, rename the
method from getLangChainTool to getLangChainTools (plural) because it returns an
array of tools, remove the unsafe cast "this as any" so the call uses the proper
typed this (adjust the HttpMCPClient/loader types if necessary to satisfy
TypeScript), and add a concise JSDoc above the method describing that it returns
Promise<Array<...>> of loaded MCP tools and the options used; also update the
sole caller at
plugin/mcp-client/test/fixtures/apps/mcpclient/app/modules/bar/controller/AppController.ts:72
to call getLangChainTools().

Comment on lines +55 to 77
createStructuredTool(clazz: EggProtoImplClass, toolMeta: IGraphToolMetadata) {
class StructuredTool {
@LifecyclePostInject()
async init() {
const toolsObj = await EggContainerFactory.getOrCreateEggObjectFromClazz(clazz);
const toolMetadata = GraphToolInfoUtil.getGraphToolMetadata((toolsObj.proto as unknown as EggPrototypeWithClazz).clazz!);
const ToolDetail = MCPInfoUtil.getMCPToolArgsIndex((toolsObj.proto as unknown as EggPrototypeWithClazz).clazz!, 'execute');
if (toolMetadata && ToolDetail) {
const tool = new DynamicStructuredTool({
description: toolMetadata.description,
name: toolMetadata.toolName,
func: (toolsObj.obj as unknown as IGraphTool<any>).execute.bind(toolsObj.obj),
schema: z.object(ToolDetail.argsSchema) as any,
});
Object.setPrototypeOf(this, tool);
} else {
throw new Error(`graph tool ${toolMeta.name ?? clazz.name} not found`);
}
}
}
SingletonProto({ name: `structured${toolMeta.name ?? clazz.name}`, accessLevel: AccessLevel.PUBLIC })(StructuredTool);
return StructuredTool;
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Inconsistent property access: toolMeta.name vs toolMeta.toolName.

Based on the IGraphToolMetadata interface (from the relevant code snippets), the property is toolName, not name. Lines 71 and 75 use toolMeta.name which may be undefined or incorrect.

🔎 Proposed fix
         } else {
-          throw new Error(`graph tool ${toolMeta.name ?? clazz.name} not found`);
+          throw new Error(`graph tool ${toolMeta.toolName ?? clazz.name} not found`);
         }
       }
     }
-    SingletonProto({ name: `structured${toolMeta.name ?? clazz.name}`, accessLevel: AccessLevel.PUBLIC })(StructuredTool);
+    SingletonProto({ name: `structured${toolMeta.toolName ?? clazz.name}`, accessLevel: AccessLevel.PUBLIC })(StructuredTool);
     return StructuredTool;
🤖 Prompt for AI Agents
In plugin/langchain/lib/graph/GraphLoadUnitHook.ts around lines 55 to 77, the
code inconsistently accesses toolMeta.name but the IGraphToolMetadata uses
toolName; replace both occurrences of toolMeta.name with toolMeta.toolName
(keeping the existing fallback to clazz.name) so the error message and
SingletonProto name use the correct metadata property.

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.

2 participants