Skip to content

fix ToolServerBase transport param#20

Open
waiil wants to merge 1 commit into
tonyzorin:mainfrom
waiil:feature/fix-transport-param
Open

fix ToolServerBase transport param#20
waiil wants to merge 1 commit into
tonyzorin:mainfrom
waiil:feature/fix-transport-param

Conversation

@waiil
Copy link
Copy Markdown
Contributor

@waiil waiil commented Sep 2, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improves server startup reliability by adapting to different MCP implementations, preventing failures when the transport option isn’t supported.
  • Chores
    • Adds a compatibility/fallback path for environments lacking the latest SDK features to ensure seamless operation.
    • Keeps public API surface unchanged and preserves existing runtime behavior for supported setups.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Sep 2, 2025

Walkthrough

Adds import-time detection for whether ToolServerBase accepts a transport kwarg and updates YouTrackMCPServer initialization to include transport only when supported; initialization now also retries without transport if ToolServerBase raises a TypeError referencing transport.

Changes

Cohort / File(s) Summary
Server compatibility shim
youtrack_mcp/server.py
Adds module-level feature-detection for ToolServerBase transport parameter via signature inspection with safe fallback; conditional import between mcp_sdk and legacy mcp.server.fastmcp; builds server_kwargs without transport by default, inserts transport only when supported, and retries initialization without transport on TypeError mentioning transport.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant App as Application
  participant Mod as youtrack_mcp.server
  participant SDK as mcp_sdk.ToolServerBase
  participant FMC as mcp.server.fastmcp.ToolServerBase

  Note over Mod: Import time detection
  Mod->>SDK: try import ToolServerBase (preferred)
  alt mcp_sdk present and inspected ok
    Mod->>Mod: _TOOLSERVER_ACCEPTS_TRANSPORT = true
  else fallback or error
    Mod->>FMC: import legacy ToolServerBase
    Mod->>Mod: _TOOLSERVER_ACCEPTS_TRANSPORT = false
  end

  Note over App,Mod: YouTrackMCPServer.__init__
  App->>Mod: instantiate YouTrackMCPServer(transport=?)
  Mod->>Mod: build server_kwargs (transport included only if flag true)
  Mod->>SDK: ToolServerBase(**server_kwargs)
  alt TypeError mentioning "transport"
    Mod->>Mod: remove transport from server_kwargs
    Mod->>SDK: ToolServerBase(**server_kwargs)  -- retry without transport
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I twitch my whiskers, check the roads—one signed, one old and worn,
I carry transport if it fits, else tuck it tight and dawn.
Two doorways, same warm burrow, I hop with gentle cheer,
Compatibility in paw-steps, backward-safe and clear. 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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
Copy Markdown

@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 (2)
youtrack_mcp/server.py (2)

13-23: Harden detection: introspect ToolServerBase.init for 'transport' instead of assuming by package name

Package presence ≠ signature guarantee. Use inspect.signature to check for a 'transport' kwarg after selecting the class; this avoids breakage across mcp_sdk/FastMCP versions.

 try:
-    # Try importing from mcp_sdk (new package name)
-    from mcp_sdk.server import ToolServerBase
-
-    _TOOLSERVER_ACCEPTS_TRANSPORT = True
+    # Try importing from mcp_sdk (new package name)
+    from mcp_sdk.server import ToolServerBase
 except ImportError:
     # Fall back to mcp (old package name)
     from mcp.server.fastmcp import FastMCP as ToolServerBase
 
-    _TOOLSERVER_ACCEPTS_TRANSPORT = False
+
+# Determine if ToolServerBase.__init__ accepts a 'transport' kwarg
+try:
+    _TOOLSERVER_ACCEPTS_TRANSPORT = (
+        "transport" in inspect.signature(ToolServerBase.__init__).parameters
+    )
+except Exception:
+    _TOOLSERVER_ACCEPTS_TRANSPORT = False

If you keep the heuristic, please verify against the versions you ship with:

  • mcp_sdk ToolServerBase.init has 'transport' kwarg
  • mcp.server.fastmcp.FastMCP.init does not

56-67: De-duplicate instantiation and optionally add a call-time fallback

Build kwargs once and add 'transport' conditionally; optionally guard with a TypeError fallback for maximum resilience.

-        if _TOOLSERVER_ACCEPTS_TRANSPORT:
-            self.server = ToolServerBase(
-                name=config.MCP_SERVER_NAME,
-                instructions=config.MCP_SERVER_DESCRIPTION,
-                transport=transport,
-            )
-        else:
-            # Legacy FastMCP does not accept 'transport'
-            self.server = ToolServerBase(
-                name=config.MCP_SERVER_NAME,
-                instructions=config.MCP_SERVER_DESCRIPTION,
-            )
+        server_kwargs = {
+            "name": config.MCP_SERVER_NAME,
+            "instructions": config.MCP_SERVER_DESCRIPTION,
+        }
+        if _TOOLSERVER_ACCEPTS_TRANSPORT:
+            server_kwargs["transport"] = transport
+
+        # Simple path
+        try:
+            self.server = ToolServerBase(**server_kwargs)
+        except TypeError as e:
+            # Safety net if detection was wrong or runtime changes
+            if "transport" in server_kwargs and "transport" in str(e):
+                server_kwargs.pop("transport", None)
+                self.server = ToolServerBase(**server_kwargs)
+            else:
+                raise
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 37089ac and 64689af.

📒 Files selected for processing (1)
  • youtrack_mcp/server.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
youtrack_mcp/server.py (1)
src/bin/youtrack-mcp.js (1)
  • server (95-95)

@waiil waiil force-pushed the feature/fix-transport-param branch from 64689af to 3e6d76a Compare September 2, 2025 10:11
Copy link
Copy Markdown

@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)
youtrack_mcp/server.py (1)

20-27: Narrow exception; detect VAR_KEYWORD to avoid false negatives.

Catching Exception trips Ruff BLE001 and can hide real errors. Also consider accepting transport when init has **kwargs.

-# Determine if ToolServerBase.__init__ accepts a 'transport' kwarg
-try:
-    _TOOLSERVER_ACCEPTS_TRANSPORT = (
-        "transport" in inspect.signature(ToolServerBase.__init__).parameters
-    )
-except Exception:
-    _TOOLSERVER_ACCEPTS_TRANSPORT = False
+# Determine if ToolServerBase.__init__ accepts a 'transport' kwarg
+try:
+    init_params = inspect.signature(ToolServerBase.__init__).parameters
+    _TOOLSERVER_ACCEPTS_TRANSPORT = (
+        "transport" in init_params
+        or any(p.kind == inspect.Parameter.VAR_KEYWORD for p in init_params.values())
+    )
+except (ValueError, TypeError):
+    _TOOLSERVER_ACCEPTS_TRANSPORT = False
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 64689af and 3e6d76a.

📒 Files selected for processing (1)
  • youtrack_mcp/server.py (2 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
youtrack_mcp/server.py

25-25: Do not catch blind exception: Exception

(BLE001)

🔇 Additional comments (1)
youtrack_mcp/server.py (1)

58-74: Verify symmetric transport fallback and add logging
Sandbox imports of ToolServerBase couldn’t be introspected, so please confirm in your runtime that:

  • When detection misses a required transport, you retry by copying server_kwargs, adding transport, and logging a warning.
  • When detection falsely includes transport, you retry by copying server_kwargs, removing transport, and logging a warning.
    Ensure you never mutate the original server_kwargs map.

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