Skip to content

Conversation

@amotl
Copy link
Member

@amotl amotl commented Jul 18, 2025

About

Supporting Dependabot on updating to higher releases of FastMCP.

Details

  • Calling tools now returns a FunctionTool object instance
  • PermissionError -> ToolError

References

@coderabbitai
Copy link

coderabbitai bot commented Jul 18, 2025

Walkthrough

The changes update dependency constraints for FastMCP, adjust how the port parameter is passed to the MCP server, refactor tests to use asynchronous FastMCP client calls, enhance test configuration with new pytest options and dependencies, and improve test reliability with timeouts. The changelog and test assertions were updated accordingly.

Changes

File(s) Change Summary
CHANGES.md Updated changelog with entries for port propagation change and FastMCP 2.9 support.
cratedb_mcp/cli.py Refactored to pass the port directly to mcp.run() only for "sse" or "streamable-http" transports.
pyproject.toml Allowed FastMCP versions up to 2.9, added/updated pytest dependencies, and configured pytest options (asyncio, timeouts, env vars).
tests/test_cli.py Updated assertions to check run_mock is called with transport and port as arguments; removed checks on global port setting.
tests/test_examples.py Added a pytest timeout marker to the test_mcptools function.
tests/test_mcp.py Refactored tests to use async FastMCP client, added async/sync helper functions, changed error handling to expect ToolError, and updated all tool invocations.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Suite
    participant Client as FastMCP Client
    participant MCP as MCP Server

    Test->>Client: call_tool(name, args)
    activate Client
    Client->>MCP: send tool call request
    activate MCP
    MCP-->>Client: return response/error
    deactivate MCP
    Client-->>Test: return result/raise ToolError
    deactivate Client
Loading

Possibly related PRs

Suggested reviewers

  • surister
  • kneth

Poem

In the warren where the code does hop,
Port numbers now take a streamlined stop.
FastMCP bounds have grown anew,
Async tests are hopping through!
With pytest timeouts set just right,
The rabbits code by day and night.
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7851922 and f6e7aeb.

📒 Files selected for processing (6)
  • CHANGES.md (1 hunks)
  • cratedb_mcp/cli.py (1 hunks)
  • pyproject.toml (3 hunks)
  • tests/test_cli.py (1 hunks)
  • tests/test_examples.py (1 hunks)
  • tests/test_mcp.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (6)
  • CHANGES.md
  • tests/test_examples.py
  • cratedb_mcp/cli.py
  • tests/test_cli.py
  • pyproject.toml
  • tests/test_mcp.py
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fastmcp-upgrade

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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 explain this code block.
    • @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 explain its main purpose.
    • @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 auto-generate unit tests to generate unit tests for 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: 1

🧹 Nitpick comments (1)
tests/test_mcp.py (1)

12-16: Unused fixture: Consider removing or utilizing the session-scoped client.

The client fixture is defined but never used. The helper functions create new client instances instead of reusing this fixture. Either utilize this fixture in the helper functions for better performance, or remove it if not needed.

If you want to utilize the fixture, refactor the helper functions:

-async def query_async(sql: str) -> dict:
-    async with Client(transport=FastMCPTransport(mcp)) as client:
-        response = await client.call_tool("query_sql", {"query": sql})
-        return json.loads(response[0].text)
+async def query_async(client, sql: str) -> dict:
+    response = await client.call_tool("query_sql", {"query": sql})
+    return json.loads(response[0].text)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0e04071 and 18cd64a.

📒 Files selected for processing (6)
  • CHANGES.md (1 hunks)
  • cratedb_mcp/cli.py (1 hunks)
  • pyproject.toml (3 hunks)
  • tests/test_cli.py (2 hunks)
  • tests/test_examples.py (1 hunks)
  • tests/test_mcp.py (1 hunks)
🧰 Additional context used
🧠 Learnings (5)
📓 Common learnings
Learnt from: amotl
PR: crate/cratedb-mcp#24
File: pyproject.toml:76-76
Timestamp: 2025-05-17T16:02:09.342Z
Learning: For the cratedb-mcp project, FastMCP pre-2.0 releases provide the same API surface needed by the application, so a lower bound on the FastMCP dependency is not necessary.
Learnt from: amotl
PR: crate/cratedb-mcp#17
File: CHANGES.md:5-5
Timestamp: 2025-05-16T13:35:04.487Z
Learning: For the cratedb-mcp repository, version numbers and release dates in CHANGES.md are updated by a dedicated "Release vX.Y.Z" commit as part of the release process, not during documentation preparation PRs.
cratedb_mcp/cli.py (2)
Learnt from: amotl
PR: crate/cratedb-mcp#17
File: CHANGES.md:5-5
Timestamp: 2025-05-16T13:35:04.487Z
Learning: For the cratedb-mcp repository, version numbers and release dates in CHANGES.md are updated by a dedicated "Release vX.Y.Z" commit as part of the release process, not during documentation preparation PRs.
Learnt from: amotl
PR: crate/cratedb-mcp#24
File: pyproject.toml:76-76
Timestamp: 2025-05-17T16:02:09.342Z
Learning: For the cratedb-mcp project, FastMCP pre-2.0 releases provide the same API surface needed by the application, so a lower bound on the FastMCP dependency is not necessary.
CHANGES.md (3)
Learnt from: amotl
PR: crate/cratedb-mcp#17
File: CHANGES.md:5-5
Timestamp: 2025-05-16T13:35:04.487Z
Learning: For the cratedb-mcp repository, version numbers and release dates in CHANGES.md are updated by a dedicated "Release vX.Y.Z" commit as part of the release process, not during documentation preparation PRs.
Learnt from: amotl
PR: crate/cratedb-mcp#24
File: pyproject.toml:76-76
Timestamp: 2025-05-17T16:02:09.342Z
Learning: For the cratedb-mcp project, FastMCP pre-2.0 releases provide the same API surface needed by the application, so a lower bound on the FastMCP dependency is not necessary.
Learnt from: amotl
PR: crate/cratedb-mcp#0
File: :0-0
Timestamp: 2025-05-17T14:55:23.400Z
Learning: In the cratedb-mcp repository, the `backlog.md` document is intended as a functional planning document that doesn't need to adhere to strict formatting standards. Avoid pointing out formatting or layout shortcomings in this file during reviews.
pyproject.toml (2)
Learnt from: amotl
PR: crate/cratedb-mcp#24
File: pyproject.toml:76-76
Timestamp: 2025-05-17T16:02:09.342Z
Learning: For the cratedb-mcp project, FastMCP pre-2.0 releases provide the same API surface needed by the application, so a lower bound on the FastMCP dependency is not necessary.
Learnt from: amotl
PR: crate/cratedb-mcp#17
File: CHANGES.md:5-5
Timestamp: 2025-05-16T13:35:04.487Z
Learning: For the cratedb-mcp repository, version numbers and release dates in CHANGES.md are updated by a dedicated "Release vX.Y.Z" commit as part of the release process, not during documentation preparation PRs.
tests/test_mcp.py (3)
Learnt from: amotl
PR: crate/cratedb-mcp#17
File: CHANGES.md:5-5
Timestamp: 2025-05-16T13:35:04.487Z
Learning: For the cratedb-mcp repository, version numbers and release dates in CHANGES.md are updated by a dedicated "Release vX.Y.Z" commit as part of the release process, not during documentation preparation PRs.
Learnt from: amotl
PR: crate/cratedb-mcp#24
File: pyproject.toml:76-76
Timestamp: 2025-05-17T16:02:09.342Z
Learning: For the cratedb-mcp project, FastMCP pre-2.0 releases provide the same API surface needed by the application, so a lower bound on the FastMCP dependency is not necessary.
Learnt from: amotl
PR: crate/cratedb-mcp#0
File: :0-0
Timestamp: 2025-05-17T14:55:23.400Z
Learning: In the cratedb-mcp repository, the `backlog.md` document is intended as a functional planning document that doesn't need to adhere to strict formatting standards. Avoid pointing out formatting or layout shortcomings in this file during reviews.
🔇 Additional comments (10)
cratedb_mcp/cli.py (1)

49-49: Clean refactoring: Port configuration consolidated into run call.

The change from setting mcp.settings.port separately to passing port directly as a keyword argument to mcp.run() improves code clarity and follows the updated FastMCP API pattern. This consolidation eliminates the need for separate settings assignment.

pyproject.toml (3)

77-77: FastMCP dependency update aligns with PR objectives.

The updated constraint >=2,<2.10 successfully allows FastMCP 2.9 as intended. The upper bound provides protection against potential breaking changes in 2.10+ while maintaining compatibility with the target version.


91-95: Test infrastructure enhancements support asynchronous testing.

The addition of pytest-asyncio, pytest-env, and pytest-timeout dependencies provides the necessary infrastructure for testing asynchronous FastMCP functionality and improves test reliability with timeout controls.


153-162: Comprehensive pytest configuration for async testing and environment control.

The new pytest configuration appropriately enables:

  • Automatic asyncio mode with session-scoped fixtures
  • Global 3-second timeout for test reliability
  • FastMCP-specific test environment variables

This configuration aligns well with the FastMCP 2.9 update and asynchronous testing patterns.

CHANGES.md (1)

4-5: Changelog entries accurately document the changes.

The two new entries clearly document the key changes in this PR:

  1. The port parameter refactoring in the CLI
  2. The FastMCP 2.9 dependency update

The entries are concise and follow the established changelog format.

tests/test_examples.py (1)

7-7: Test timeout marker improves reliability.

The 10-second pytest timeout marker provides appropriate per-test timeout control, complementing the global timeout settings in pyproject.toml. The timeout is reasonable given the test runs an external script with a 15-second subprocess timeout.

tests/test_cli.py (2)

81-81: Test assertion correctly verifies the new port handling approach.

The updated assertion mock.call("stdio", port=8000) properly verifies that the mocked run_async method is called with the port as a keyword argument, reflecting the CLI refactoring.


102-102: Test assertion correctly verifies custom port parameter handling.

The updated assertion mock.call("streamable-http", port=65535) properly verifies that custom port values are passed correctly as keyword arguments to the mocked run_async method.

tests/test_mcp.py (2)

1-10: LGTM! Import changes support the async refactor.

The new imports properly support the transition from direct function calls to asynchronous MCP client calls. The addition of ToolError aligns with the standardized error handling approach.


40-99: LGTM! Test functions properly updated for async MCP client.

The test functions have been correctly refactored to:

  • Use the new call_tool and query wrappers instead of direct function calls
  • Handle ToolError exceptions appropriately (replacing ValueError/PermissionError)
  • Decode JSON responses where needed using the decode_json parameter

The refactor maintains the same test logic while properly integrating with the FastMCP client interface.

@amotl amotl force-pushed the fastmcp-upgrade branch from 18cd64a to 7851922 Compare July 18, 2025 16:36
@amotl amotl requested review from WalBeh, kneth and surister July 18, 2025 16:36
@amotl amotl marked this pull request as ready for review July 18, 2025 16:38
- Calling tools now returns a `FunctionTool` object instance
- PermissionError -> ToolError
- Add more `pytest` utilities from FastMCP testing best practises
@amotl
Copy link
Member Author

amotl commented Jul 19, 2025

This patch has been made partly obsolete by GH-52.

@amotl amotl marked this pull request as draft July 19, 2025 14:59
Copy link
Member

@kneth kneth left a comment

Choose a reason for hiding this comment

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

LGTM

@amotl
Copy link
Member Author

amotl commented Jul 21, 2025

@kneth: This patch is outdated. GH-52 is part of a brighter future without needing to turn the whole test suite upside down.

@amotl
Copy link
Member Author

amotl commented Jul 21, 2025

GH-48 has been refreshed, queuing up for merging, so this patch is effectively obsolete now.

@amotl amotl closed this Jul 21, 2025
@amotl amotl deleted the fastmcp-upgrade branch July 21, 2025 15:05
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.

3 participants