Skip to content

Add logging inside framework#7

Merged
Agent-Hellboy merged 3 commits intomasterfrom
fix_issue#6
Jul 3, 2025
Merged

Add logging inside framework#7
Agent-Hellboy merged 3 commits intomasterfrom
fix_issue#6

Conversation

@Agent-Hellboy
Copy link
Owner

@Agent-Hellboy Agent-Hellboy commented Jul 3, 2025

fixes #6

Summary by CodeRabbit

  • New Features

    • Added example FastAPI server script with a greeting endpoint.
    • Introduced a sample script demonstrating tool registration and HTTP requests to a Flask API server.
  • Documentation

    • Enhanced README with sections on logging configuration, custom tool creation, server hosting, middleware setup, and logging details for improved user guidance.
  • Style

    • Updated server logging to use Python’s logging module at debug level instead of print statements.
  • Chores

    • Added logging configuration to example scripts for better debugging and transparency.

@coderabbitai
Copy link

coderabbitai bot commented Jul 3, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This update replaces all print statements in the framework with debug-level logging, adds logging configuration examples to the documentation and example scripts, and introduces new web-based example scripts using FastAPI and tool integration. The README is expanded with detailed guidance on logging, tool creation, server hosting, and middleware customization.

Changes

File(s) Change Summary
README.md Added sections on logging configuration, tool creation, server hosting, and middleware customization.
example/run_server.py Added logging configuration at script startup.
pymcp/server.py Replaced print statements with logging.debug for debug output.
example/web-based/fast_api_server.py New example: FastAPI server with a single "/hello" endpoint and Uvicorn launch.
example/web-based/run_mcp_with_flask_call.py New example: Tool that calls a Flask server endpoint and launches the MCP server with Uvicorn.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MCP_Server as MCP Server (pymcp.server)
    participant Tool as callFlaskHelloTool
    participant FlaskAPI as Flask API Server

    User->>MCP_Server: Sends request to callFlaskHelloTool
    MCP_Server->>Tool: Invokes callFlaskHelloTool()
    Tool->>FlaskAPI: HTTP GET /hello
    FlaskAPI-->>Tool: JSON {"message": "..."}
    Tool-->>MCP_Server: Returns formatted message
    MCP_Server-->>User: Responds with result
Loading

Assessment against linked issues

Objective Addressed Explanation
Remove print statements and add logging inside the framework (#6)
Add web-based example (#6)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Expanded README with sections on tool creation, middleware, and server hosting (README.md) These documentation enhancements, while helpful, go beyond the strict objectives of print/logging replacement and web-based example addition.

Poem

Logs now whisper where prints once yelled,
A web-based world in examples spelled.
FastAPI and Flask, together they play,
With tools and docs to light the way.
🐰 The server hums, the rabbit grins—
Debugging joy as change begins!

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.

🔧 Pylint (3.3.7)
pymcp/server.py

📜 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 156257c and 9574d3c.

📒 Files selected for processing (1)
  • pymcp/server.py (4 hunks)
✨ 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.
    • 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.
    • @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 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.

@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2025

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 74.80%. Comparing base (84be8ec) to head (9574d3c).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master       #7      +/-   ##
==========================================
+ Coverage   74.60%   74.80%   +0.19%     
==========================================
  Files           2        2              
  Lines         126      127       +1     
==========================================
+ Hits           94       95       +1     
  Misses         32       32              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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 (3)
pymcp/server.py (1)

153-155: Consider reducing log verbosity for production.

While detailed logging is helpful for debugging, logging full tool schemas might be too verbose for production environments. Consider using a more concise format or making this configurable.

-        logging.debug(f"[TOOLS] Sending {len(tools_list)} tools to Cursor")
-        logging.debug(f"[TOOLS] Tool names: {[t['name'] for t in tools_list]}")
-        logging.debug(f"[TOOLS] Tool schemas: {json.dumps(tools_list, indent=2)}")
+        logging.debug(f"[TOOLS] Sending {len(tools_list)} tools to Cursor: {[t['name'] for t in tools_list]}")
+        if logging.getLogger().isEnabledFor(logging.DEBUG):
+            logging.debug(f"[TOOLS] Tool schemas: {json.dumps(tools_list, indent=2)}")
example/web-based/run_mcp_with_flask_call.py (2)

11-11: Consider increasing the timeout for better reliability.

A 2-second timeout might be too short for network requests, especially in slower environments. Consider increasing it to 5-10 seconds.

-        resp = requests.get("http://127.0.0.1:5005/hello", timeout=2)
+        resp = requests.get("http://127.0.0.1:5005/hello", timeout=5)

22-24: Consider using logging instead of print for consistency.

Since the PR migrates from print to logging, consider using logging for this informational message to maintain consistency.

-    print(
-        "[INFO] Make sure to start the Flask API server (flask_api_server.py) before running this example."
-    )
+    import logging
+    logging.info(
+        "Make sure to start the Flask API server (flask_api_server.py) before running this example."
+    )
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 84be8ec and 156257c.

📒 Files selected for processing (5)
  • README.md (2 hunks)
  • example/run_server.py (1 hunks)
  • example/web-based/fast_api_server.py (1 hunks)
  • example/web-based/run_mcp_with_flask_call.py (1 hunks)
  • pymcp/server.py (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
example/web-based/run_mcp_with_flask_call.py (1)
pymcp/registry.py (1)
  • register (8-32)
🪛 LanguageTool
README.md

[uncategorized] ~71-~71: Possible missing comma found.
Context: ...add this before running the server with Uvicorn as shown above. Request flow of an exa...

(AI_HYDRA_LEO_MISSING_COMMA)

🔇 Additional comments (10)
example/run_server.py (1)

1-1: LGTM: Proper logging configuration setup.

The logging import and basic configuration are correctly placed at the beginning of the script, following Python best practices for logging setup.

Also applies to: 6-6

pymcp/server.py (2)

3-3: LGTM: Proper logging import added.

The logging import is correctly placed with other standard library imports.


37-38: LGTM: Good migration from print to logging.

The conversion from print statements to proper logging is well done and provides better observability.

example/web-based/fast_api_server.py (1)

1-15: LGTM: Clean FastAPI server implementation.

The code follows FastAPI best practices with proper imports, async endpoint definition, and standard Uvicorn configuration. The implementation is minimal and focused.

example/web-based/run_mcp_with_flask_call.py (1)

7-16: LGTM: Well-structured tool implementation with good error handling.

The tool follows the registry pattern correctly and includes appropriate error handling with timeout configuration.

README.md (5)

13-19: LGTM: Excellent logging configuration guidance.

The early placement of logging configuration instructions is perfect, helping users understand how to enable debug output before they encounter issues.


30-42: LGTM: Clear and practical tool creation example.

The example demonstrates the registry pattern effectively and provides users with a straightforward template for creating their own tools.


43-53: LGTM: Helpful server hosting instructions.

The FastAPI and Uvicorn hosting section provides clear guidance for users who want to customize their server deployment.


55-71: LGTM: Useful middleware configuration example.

The middleware example shows users how to extend the framework's capabilities, which is valuable for customization.


76-86: LGTM: Comprehensive logging documentation.

The final logging section reinforces the configuration requirements and provides users with clear guidance on controlling log verbosity.

@Agent-Hellboy Agent-Hellboy merged commit 8da6e51 into master Jul 3, 2025
6 of 7 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.

Remove print statements and add logging inside the framework and add web based example

2 participants