Skip to content

Feat/fast mcp settings #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 7, 2025
Merged

Feat/fast mcp settings #361

merged 3 commits into from
Aug 7, 2025

Conversation

rholinshead
Copy link
Member

@rholinshead rholinshead commented Aug 6, 2025

Description

A recent regression in mcp's FastMCP integration (fixed in modelcontextprotocol/python-sdk#1244) can be mitigated by allowing users to pass in explicit FastMCP settings through create_mcp_server_for_app, rather than relying on environment variables that may or may not be used. Additionally, this allows for dynamic configuration of mcp app servers rather than having to rely on the environment variable being set.

Changes

  • Update create_mcp_server_for_app to support a settings dict (note, FastMCP Settings type is not exported so we would need to redefine a subset if we wanted something typed).
  • Update basic mcp_agent_server asyncio example to support custom settings via --custom-fastmcp-settings flag

Testing

Run with and without the flag set and ensure proper settings in the server, e.g.

uv run client.py
INFO:__main__:Creating MCP server for basic_agent_server
INFO:__main__:Registered workflows:
INFO:__main__:  - BasicAgentWorkflow
INFO:__main__:  - ParallelWorkflow
INFO:__main__:MCP Server settings: debug=False log_level='INFO' host='127.0.0.1' port=8000 mount_path='/' sse_path='/sse' message_path='/messages/' streamable_http_path='/mcp' json_response=False stateless_http=False warn_on_duplicate_resources=True warn_on_duplicate_tools=True warn_on_duplicate_prompts=True dependencies=[] lifespan=<function create_mcp_server_for_app.<locals>.app_specific_lifespan at 0x12a171510> auth=None transport_security=None
uv run client.py --custom-fastmcp-settings
INFO:__main__:Creating MCP server for basic_agent_server
INFO:__main__:Registered workflows:
INFO:__main__:  - BasicAgentWorkflow
INFO:__main__:  - ParallelWorkflow
INFO:__main__:MCP Server settings: debug=True log_level='DEBUG' host='localhost' port=8001 mount_path='/' sse_path='/sse' message_path='/messages/' streamable_http_path='/mcp' json_response=False stateless_http=False warn_on_duplicate_resources=True warn_on_duplicate_tools=True warn_on_duplicate_prompts=True dependencies=[] lifespan=<function create_mcp_server_for_app.<locals>.app_specific_lifespan at 0x124a71510> auth=None transport_security=None

Summary by CodeRabbit

  • New Features
    • Added support for custom FastMCP server settings via a command-line flag when running the example server and client.
  • Documentation
    • Updated README with instructions and examples for using the new custom FastMCP settings flag when starting the server and client.

Copy link

coderabbitai bot commented Aug 6, 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

The changes introduce support for custom FastMCP server settings in the MCP agent server asyncio example. Command-line flags and argument parsing are added to both the server and client scripts, allowing users to optionally enable custom settings. The server creation utility is updated to accept and apply these settings, and documentation is revised accordingly.

Changes

Cohort / File(s) Change Summary
Documentation Update
examples/mcp_agent_server/asyncio/README.md
README updated to clarify optional use of custom FastMCP settings and enhanced instructions for running server/client with new flag.
Server Script Enhancement
examples/mcp_agent_server/asyncio/basic_agent_server.py
Added command-line argument parsing with --custom-fastmcp-settings flag; server now supports custom FastMCP settings via this flag.
Client Script Enhancement
examples/mcp_agent_server/asyncio/client.py
Added command-line argument parsing and --custom-fastmcp-settings flag; client now launches server with appropriate settings based on flag.
Server Utility Update
src/mcp_agent/server/app_server.py
create_mcp_server_for_app updated to accept arbitrary keyword arguments for FastMCP server configuration; docstring and signature updated.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Client
    participant Server
    participant AppServerUtility

    User->>Client: Run client.py [--custom-fastmcp-settings]
    Client->>Server: Start basic_agent_server.py [with flag if set]
    Server->>AppServerUtility: create_mcp_server_for_app(app, settings)
    AppServerUtility->>Server: Returns FastMCP server instance (custom/default settings)
    Server->>User: Server starts with chosen settings
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • saqadri

Poem

A rabbit hopped to tweak the code,
Now servers flex with custom mode!
Flags and settings, clear and neat,
In docs and scripts, a tidy feat.
With every hop, the features grow—
Faster, smarter, off we go!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 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 353d724 and a67f7f0.

📒 Files selected for processing (2)
  • examples/mcp_agent_server/asyncio/basic_agent_server.py (3 hunks)
  • src/mcp_agent/server/app_server.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/mcp_agent/server/app_server.py
  • examples/mcp_agent_server/asyncio/basic_agent_server.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 feat/fast-mcp-settings

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.
    • Explain this complex logic.
    • 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 explain this code block.
  • 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.

Support

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

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

🧹 Nitpick comments (1)
src/mcp_agent/server/app_server.py (1)

125-125: Safe parameter unpacking implementation.

The use of **settings or {} handles both None and empty dictionary cases gracefully, maintaining backward compatibility.

Consider adding basic validation for the settings dictionary to provide better error messages:

+    # Validate settings if provided
+    if settings:
+        # Basic validation - ensure all values are JSON serializable for logging
+        try:
+            import json
+            json.dumps(settings)
+        except (TypeError, ValueError) as e:
+            raise ValueError(f"Invalid settings provided: {e}")
+
     # Create FastMCP server with the app's name
     mcp = FastMCP(
         name=app.name or "mcp_agent_server",
         # TODO: saqadri (MAC) - create a much more detailed description
         # based on all the available agents and workflows,
         # or use the MCPApp's description if available.
         instructions=f"MCP server exposing {app.name} workflows and agents. Description: {app.description}",
         lifespan=app_specific_lifespan,
         **settings or {},
     )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0c9484b and 353d724.

📒 Files selected for processing (4)
  • examples/mcp_agent_server/asyncio/README.md (2 hunks)
  • examples/mcp_agent_server/asyncio/basic_agent_server.py (3 hunks)
  • examples/mcp_agent_server/asyncio/client.py (3 hunks)
  • src/mcp_agent/server/app_server.py (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: lastmile-ai/mcp-agent#0
File: examples/usecases/reliable_conversation/CLAUDE.md:0-0
Timestamp: 2025-07-22T18:59:49.368Z
Learning: Applies to examples/usecases/reliable_conversation/examples/reliable_conversation/src/**/*.py : Use mcp-agent's Agent abstraction for ALL LLM interactions, including quality evaluation, to ensure consistent tool access, logging, and error handling.
Learnt from: CR
PR: lastmile-ai/mcp-agent#0
File: examples/usecases/reliable_conversation/CLAUDE.md:0-0
Timestamp: 2025-07-22T18:59:49.368Z
Learning: Applies to examples/usecases/reliable_conversation/examples/reliable_conversation/src/utils/config.py : Configuration values such as quality_threshold, max_refinement_attempts, consolidation_interval, and evaluator_model_provider must be loaded from mcp_agent.config.yaml.
📚 Learning: applies to examples/usecases/reliable_conversation/examples/reliable_conversation/src/**/*.py : use ...
Learnt from: CR
PR: lastmile-ai/mcp-agent#0
File: examples/usecases/reliable_conversation/CLAUDE.md:0-0
Timestamp: 2025-07-22T18:59:49.368Z
Learning: Applies to examples/usecases/reliable_conversation/examples/reliable_conversation/src/**/*.py : Use mcp-agent's Agent abstraction for ALL LLM interactions, including quality evaluation, to ensure consistent tool access, logging, and error handling.

Applied to files:

  • examples/mcp_agent_server/asyncio/client.py
  • examples/mcp_agent_server/asyncio/README.md
  • examples/mcp_agent_server/asyncio/basic_agent_server.py
📚 Learning: applies to examples/usecases/reliable_conversation/examples/reliable_conversation/src/utils/config.p...
Learnt from: CR
PR: lastmile-ai/mcp-agent#0
File: examples/usecases/reliable_conversation/CLAUDE.md:0-0
Timestamp: 2025-07-22T18:59:49.368Z
Learning: Applies to examples/usecases/reliable_conversation/examples/reliable_conversation/src/utils/config.py : Configuration values such as quality_threshold, max_refinement_attempts, consolidation_interval, and evaluator_model_provider must be loaded from mcp_agent.config.yaml.

Applied to files:

  • examples/mcp_agent_server/asyncio/basic_agent_server.py
🧬 Code Graph Analysis (1)
src/mcp_agent/server/app_server.py (1)
src/mcp_agent/app.py (1)
  • MCPApp (35-532)
🔇 Additional comments (11)
src/mcp_agent/server/app_server.py (2)

84-86: LGTM! Function signature updated correctly.

The addition of the optional settings parameter follows good practices with proper typing and default value.


92-92: Docstring updated appropriately.

The parameter documentation clearly explains the purpose of the new settings parameter.

examples/mcp_agent_server/asyncio/README.md (3)

15-15: Documentation updated to reflect new capability.

The mention of custom FastMCP settings is appropriately placed in the concepts section.


96-99: Clear server usage examples provided.

The documentation shows both default and custom FastMCP settings usage patterns for the server.


105-108: Client usage examples included.

The documentation consistently shows the flag usage for both server and client, which helps users understand the complete workflow.

examples/mcp_agent_server/asyncio/client.py (3)

1-1: Import added for command-line argument parsing.

The argparse import is correctly placed and necessary for the new functionality.


15-23: Command-line argument parsing implemented correctly.

The argument parser setup follows standard practices with a clear help message and appropriate action type.


34-45: Server arguments conditionally modified based on flag.

The implementation correctly adjusts the server command arguments and includes informative logging to indicate which settings are being used.

examples/mcp_agent_server/asyncio/basic_agent_server.py (3)

10-10: Import added for command-line argument parsing.

The argparse import is correctly placed and necessary for the new functionality.


173-181: Command-line argument parsing implemented correctly.

The argument parser setup follows standard practices with a clear help message and appropriate action type.


195-204: Settings configuration and server creation updated appropriately.

The conditional settings creation provides meaningful custom values for demonstration purposes. The settings are properly passed to the create_mcp_server_for_app function, and logging is added to show the applied configuration.

@@ -119,6 +122,7 @@ async def app_specific_lifespan(mcp: FastMCP) -> AsyncIterator[ServerContext]:
# or use the MCPApp's description if available.
instructions=f"MCP server exposing {app.name} workflows and agents. Description: {app.description}",
lifespan=app_specific_lifespan,
**settings or {},

This comment was marked as resolved.

Comment on lines 84 to 86
def create_mcp_server_for_app(
app: MCPApp, settings: dict[str, Any] | None = None
) -> FastMCP:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we do this simply as kwargs

Suggested change
def create_mcp_server_for_app(
app: MCPApp, settings: dict[str, Any] | None = None
) -> FastMCP:
def create_mcp_server_for_app(
app: MCPApp, **kwargs: Any
) -> FastMCP:

Copy link
Member Author

Choose a reason for hiding this comment

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

That works, too. Updated

@rholinshead rholinshead merged commit 136a847 into main Aug 7, 2025
8 checks passed
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