Skip to content

fix: add ping config#364

Merged
killagu merged 1 commit intomasterfrom
fiz/ping_check
Nov 20, 2025
Merged

fix: add ping config#364
killagu merged 1 commit intomasterfrom
fiz/ping_check

Conversation

@akitaSummer
Copy link
Contributor

@akitaSummer akitaSummer commented Nov 20, 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

    • Added configurable ping controls for SSE and stream server connections, allowing per-server and global-level configuration.
  • Bug Fixes

    • Improved error handling for server ping operations to prevent connection disruptions and ensure proper cleanup.

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

@coderabbitai
Copy link

coderabbitai bot commented Nov 20, 2025

Walkthrough

This PR adds per-transport ping control flags (ssePingEnabled and streamPingEnabled) to MCPConfig, enabling selective enabling/disabling of server pings for SSE and stream protocols, with guards and error handling around ping invocations in MCPControllerRegister.

Changes

Cohort / File(s) Summary
MCP Configuration & Control
plugin/controller/lib/impl/mcp/MCPConfig.ts, plugin/controller/lib/impl/mcp/MCPControllerRegister.ts
Added optional ssePingEnabled and streamPingEnabled configuration options to MCPConfig with per-name getter support; guarded all mcpServerPing invocations with feature flags; wrapped periodic ping logic in try/catch/finally for error handling and guaranteed cleanup.
Test Configuration
plugin/controller/test/fixtures/apps/mcp-app/config/config.default.js
Added default configuration flags ssePingEnabled: true and streamPingEnabled: true under mcp settings.

Sequence Diagram

sequenceDiagram
    participant Init as MCP Initialization
    participant Config as MCPConfig
    participant Register as MCPControllerRegister
    participant Server as MCP Server

    Init->>Config: getStreamPingEnabled(name)?
    Config-->>Init: returns config flag
    
    rect rgba(100, 200, 150, 0.1)
    note over Register: New Guard Logic
    Init->>Register: check if ping enabled
    alt Ping Enabled
        Register->>Register: setup ping interval
        loop Periodic Ping
            rect rgba(100, 150, 200, 0.1)
            note over Register: Error Handling
            Register->>Server: ping()
            alt Success
                Server-->>Register: pong
            else Failure
                Server-->>Register: error
                Register->>Register: log warning
            end
            Register->>Register: cleanup in finally
            end
        end
    else Ping Disabled
        Register->>Register: skip ping setup
    end
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

  • Straightforward configuration additions with standard getter patterns
  • Guard logic follows a consistent, repetitive pattern across ping invocations
  • Error handling uses standard try/catch/finally pattern
  • No complex interdependencies or state management changes

Possibly related PRs

  • Fix/mcp server ping #360: Adds ping timers and per-name interval settings to MCP server ping behavior, complementing this PR's per-transport enable flags and guards.
  • feat: add mcp stateless #309: Modifies MCPConfig and MCPControllerRegister introducing centralized configuration, affecting the same components modified here.
  • fix: multi mcp client #357: Refactors per-server registration and MCP session lifecycle in MCPControllerRegister, overlapping with the same file modified in this PR.

Suggested reviewers

  • killagu

Poem

🐰 A ping here, a ping there,
But now we choose with care,
SSE and stream so bright,
Toggle flags left and right,
Error-safe with try/finally's might!

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'fix: add ping config' is vague and generic. While it mentions 'ping config', it does not specify what the ping configuration actually does or which components are affected by these changes. Consider a more descriptive title like 'fix: add per-server ping configuration controls for SSE and stream' to clarify the scope and purpose of the changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fiz/ping_check

Tip

📝 Customizable high-level summaries are now available in beta!

You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.

  • Provide your own instructions using the high_level_summary_instructions setting.
  • Format the summary however you like (bullet lists, tables, multi-section layouts, contributor stats, etc.).
  • Use high_level_summary_in_walkthrough to move the summary from the description to the walkthrough section.

Example instruction:

"Divide the high-level summary into five sections:

  1. 📝 Description — Summarize the main change in 50–60 words, explaining what was done.
  2. 📓 References — List relevant issues, discussions, documentation, or related PRs.
  3. 📦 Dependencies & Requirements — Mention any new/updated dependencies, environment variable changes, or configuration updates.
  4. 📊 Contributor Summary — Include a Markdown table showing contributions:
    | Contributor | Lines Added | Lines Removed | Files Changed |
  5. ✔️ Additional Notes — Add any extra reviewer context.
    Keep each section concise (under 200 words) and use bullet or numbered lists for clarity."

Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later.


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 new configuration parameters to enable or disable pinging for Server-Sent Events (SSE) and general stream connections within the mcp module. It refactors the ping initiation logic to respect these new settings, providing granular control over connection health checks. Additionally, it enhances the stability of the ping mechanism by incorporating error handling, preventing potential disruptions from failed ping attempts.

Highlights

  • Configurable Pinging: Introduced new configuration options (ssePingEnabled, streamPingEnabled) to control whether pinging is active for Server-Sent Events (SSE) and general stream connections.
  • Conditional Pinging: Modified the pinging logic to only initiate pings for SSE and stream connections if the corresponding ssePingEnabled or streamPingEnabled configuration is set to true.
  • Improved Ping Robustness: Added error handling for the server.ping() operation, logging warnings on failure and ensuring cleanup logic always executes.
  • Test Configuration Update: Updated the default test application configuration to enable both SSE and stream pinging, ensuring the new features are tested.
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.

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 configuration options to enable or disable pinging for SSE and stream connections, which is a useful feature for managing connection health. The implementation is generally sound, but I have identified a couple of areas for improvement. Specifically, there's a design issue in MCPConfig.ts where per-server configurations do not fall back to the global configuration, making it less intuitive. I've also suggested a minor enhancement to logging in MCPControllerRegister.ts to provide more context for easier debugging. Overall, good work on adding this functionality.

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

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3e944e8 and f25418b.

📒 Files selected for processing (3)
  • plugin/controller/lib/impl/mcp/MCPConfig.ts (4 hunks)
  • plugin/controller/lib/impl/mcp/MCPControllerRegister.ts (3 hunks)
  • plugin/controller/test/fixtures/apps/mcp-app/config/config.default.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
plugin/controller/lib/impl/mcp/MCPConfig.ts (2)
plugin/controller/test/fixtures/apps/mcp-app/config/config.default.js (1)
  • config (8-38)
plugin/controller/config/config.default.ts (1)
  • config (3-15)
⏰ 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). (8)
  • GitHub Check: Runner-macos (20)
  • GitHub Check: Runner-ubuntu (20)
  • GitHub Check: Runner-macos (16)
  • GitHub Check: Runner-ubuntu (16)
  • GitHub Check: Runner-ubuntu (18)
  • GitHub Check: Runner-macos (18)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (typescript)
🔇 Additional comments (3)
plugin/controller/test/fixtures/apps/mcp-app/config/config.default.js (1)

11-12: LGTM! Test configuration aligns with new ping control flags.

The addition of ssePingEnabled and streamPingEnabled flags to the test fixture configuration properly exercises the new per-transport ping control functionality.

plugin/controller/lib/impl/mcp/MCPControllerRegister.ts (2)

347-349: LGTM! Ping invocations properly gated by feature flags.

The conditional execution of mcpServerPing based on getStreamPingEnabled(name) and getSsePingEnabled(name) correctly implements per-transport ping control, preventing unnecessary network calls when pings are disabled.

Also applies to: 501-503


672-683: LGTM! Robust error handling for ping operations.

Wrapping server.ping() in try/catch/finally ensures:

  • Ping failures are logged without crashing the interval
  • Duration-based cleanup (clearing the interval) always executes regardless of ping outcome

This is a solid improvement for reliability.

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

@killagu killagu merged commit c2757fc into master Nov 20, 2025
12 checks passed
@killagu killagu deleted the fiz/ping_check branch November 20, 2025 14:59
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