Skip to content

fix: mcp version check#311

Merged
akitaSummer merged 2 commits intoeggjs:masterfrom
akitaSummer:fix/mcp-node-version
May 1, 2025
Merged

fix: mcp version check#311
akitaSummer merged 2 commits intoeggjs:masterfrom
akitaSummer:fix/mcp-node-version

Conversation

@akitaSummer
Copy link
Contributor

@akitaSummer akitaSummer commented Apr 30, 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

  • Refactor
    • Updated internal logic to use the Node.js runtime version for certain feature checks, improving compatibility handling.
    • Improved context handling for proxy operations to ensure more accurate and localized processing.

@coderabbitai
Copy link

coderabbitai bot commented Apr 30, 2025

Walkthrough

This change updates the conditional logic for registering the MCP controller and connecting to the stateless stream transport in the application lifecycle. Instead of checking for the presence of this.app.mcpProxy, the code now checks if the Node.js major version is 18 or higher. Additionally, the SSE proxy handler in the MCP proxy plugin now constructs a new EggContext for each request and passes it to pre-proxy hooks, rather than using a potentially global or reused context. No changes were made to public or exported entity signatures.

Changes

File(s) Change Summary
plugin/controller/app.ts Replaced all checks on this.app.mcpProxy with a check on Node.js major version (>= 18) for MCP controller registration and stateless stream transport connection.
plugin/mcp-proxy/index.ts Modified SSE proxy handler to create a new EggContext for each request and pass it to pre-proxy hooks, instead of using app.currentContext.

Sequence Diagram(s)

sequenceDiagram
    participant NodeRuntime
    participant App
    participant MCPControllerRegister
    participant MCPProxyHook
    participant EggContext

    NodeRuntime->>App: Start (check Node.js version)
    App->>App: If majorVersion >= 18
    App->>MCPControllerRegister: Register controller and middleware
    App->>MCPControllerRegister: Connect stateless stream transport (async)
    MCPProxyHook->>EggContext: Create new context for each request
    MCPProxyHook->>MCPControllerRegister: Call preProxy hooks with new context
Loading

Possibly related PRs

  • eggjs/tegg#309: Adds stateless MCP server and transport initialization in the same lifecycle methods affected by this PR.
  • eggjs/tegg#310: Introduces the willReady lifecycle method and makes the stateless stream transport connection asynchronous, modifying the same area as this PR.

Poem

In burrows deep where Node runs free,
The code now checks its pedigree—
Eighteen or up? Then onward hop,
Register streams, let nothing stop!
With fresh new contexts, rabbits cheer,
For cleaner hooks and code this year.
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

plugin/mcp-proxy/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-eggache".

(The package "eslint-plugin-eggache" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-eggache@latest --save-dev

The plugin "eslint-plugin-eggache" was referenced from the config file in ".eslintrc » eslint-config-egg/typescript » ./index.js".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

🧹 Nitpick comments (1)
plugin/controller/app.ts (1)

66-91: Version-based conditional replaces property check

The code now uses Node.js version (>=18) as a condition rather than checking for this.app.mcpProxy. This makes the requirement more explicit and direct, which is a good improvement.

However, for better maintainability, consider extracting this magic number into a named constant.

 const majorVersion = parseInt(process.versions.node.split('.')[0], 10);
+const MCP_REQUIRED_NODE_VERSION = 18;

 // ...

-if (majorVersion >= 18) {
+if (majorVersion >= MCP_REQUIRED_NODE_VERSION) {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 25d3db0 and 8e74716.

📒 Files selected for processing (1)
  • plugin/controller/app.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Runner-ubuntu (20)
  • GitHub Check: Runner-ubuntu (22)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Runner-macos (18)
  • GitHub Check: Runner-macos (20)
  • GitHub Check: Analyze (typescript)
  • GitHub Check: Runner-macos (16)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
plugin/controller/app.ts (2)

20-20: Good approach for extracting Node.js major version

The code extracts the major version number from Node.js runtime version string and converts it to an integer. This is a simple and effective approach.


117-119: Consistent version check approach

Using the same Node.js version check here maintains consistency with the earlier condition. This is good for code maintainability.

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: 1

🧹 Nitpick comments (4)
change_tag.sh (4)

1-1: Use a portable shebang for Bash

Recommend switching to #!/usr/bin/env bash to improve portability across environments where Bash may not reside at /bin/bash.

Diff:

-#!/bin/bash
+#!/usr/bin/env bash

3-4: Parameterize version and tag variables

Hardcoding TARGET_VERSION and TAG requires editing the script for each release. Consider accepting them as command-line arguments or environment variables, for example:

TARGET_VERSION="${1:-3.53.0}"
TAG="${2:-latest}"

This allows invoking the script like:

./change_tag.sh 3.54.0 beta

21-29: Consistent language and logging for missing package name

Error messages and comments mix English and Chinese. For clarity in a global codebase, pick one language. For example:

-      echo "错误: $project_dir 中未找到有效的 package.json name 字段"
+      echo "Error: no valid 'name' field in $project_dir/package.json"

32-42: Track failures and proper exit status

Currently, errors are logged but the script always exits with code 0. Consider:

  1. Enabling strict mode:
    set -euo pipefail
  2. Accumulating failures to exit non-zero if any tagging operation fails:
+# Enable strict mode at the top
+set -euo pipefail
+
+FAILURE=0
...
       if ! npm dist-tag add "$package_name@$TARGET_VERSION" "$TAG"; then
         echo "Failed to update tag in $project_dir"
+        FAILURE=1
       fi
...
 done
 echo "All done!"
+exit $FAILURE

This ensures downstream automation can detect failures correctly.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e74716 and eec2589.

📒 Files selected for processing (1)
  • change_tag.sh (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Analyze (typescript)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Runner-ubuntu (22)
  • GitHub Check: Runner-ubuntu (20)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Runner-macos (18)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Runner-macos (16)
  • GitHub Check: Runner-macos (20)
🔇 Additional comments (1)
change_tag.sh (1)

6-7: Directory list declaration looks good

The DIRS array clearly enumerates the intended directories and requires no changes.

@akitaSummer akitaSummer force-pushed the fix/mcp-node-version branch from eec2589 to 4325e39 Compare May 1, 2025 11:42
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: 0

🧹 Nitpick comments (1)
plugin/mcp-proxy/index.ts (1)

62-72: Improved context isolation for pre-proxy hooks.

This change properly isolates the context for each request by creating a new EggContext instance instead of potentially reusing a global context. This is a good practice that prevents potential data leakage between requests and aligns with the PR's focus on fixing MCP version check behavior.

Consider exploring if there's a way to avoid the TypeScript ignore comments by properly typing the app or using a safer pattern for assigning the request and response classes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eec2589 and 4325e39.

📒 Files selected for processing (1)
  • plugin/mcp-proxy/index.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Runner-ubuntu (20)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Analyze (typescript)
  • GitHub Check: Runner-macos (20)
  • GitHub Check: Runner-ubuntu (22)
  • GitHub Check: Runner-macos (18)
  • GitHub Check: Runner-macos (16)

Copy link
Contributor

@killagu killagu left a comment

Choose a reason for hiding this comment

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

LGTM

@akitaSummer akitaSummer merged commit 7f16c9c into eggjs:master May 1, 2025
13 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Aug 6, 2025
4 tasks
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