Skip to content

feat: add MCP tracking to sessions #19

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 1 commit into from
Jun 26, 2025
Merged

feat: add MCP tracking to sessions #19

merged 1 commit into from
Jun 26, 2025

Conversation

bouthilx
Copy link
Contributor

@bouthilx bouthilx commented Jun 26, 2025

User description

Add mcps field to Session model to track active MCP servers and populate it from container labels in ContainerManager. Enhance MCP remove command to warn when removing servers used by active sessions.

🤖 Generated with Claude Code


PR Type

Enhancement


Description

  • Track MCP servers used by sessions

  • Warn when removing MCPs used by active sessions

  • Extract MCPs from container labels

  • Add comprehensive tests for MCP tracking


Changes walkthrough 📝

Relevant files
Enhancement
models.py
Add MCP tracking field to Session model                                   

cubbi/models.py

  • Added mcps field to Session model to track associated MCP servers
  • Field defaults to an empty list when not specified
  • +1/-0     
    container.py
    Extract MCP data from container labels                                     

    cubbi/container.py

  • Extract MCP server list from container labels
  • Parse comma-separated MCP names from "cubbi.mcps" label
  • Add extracted MCPs to Session object during creation
  • +9/-0     
    Tests
    test_mcp_commands.py
    Add comprehensive tests for MCP tracking                                 

    tests/test_mcp_commands.py

  • Updated existing MCP removal test to check for empty sessions
  • Added tests for removing MCPs used by active sessions
  • Added tests for removing non-existent MCPs
  • Added tests for Session model MCP attribute
  • Added tests for extracting MCPs from container labels
  • +204/-13

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Add mcps field to Session model to track active MCP servers and populate it from container labels in ContainerManager. Enhance MCP remove command to warn when removing servers used by active sessions.
    
    🤖 Generated with [Claude Code](https://claude.ai/code)
    
    Co-Authored-By: Claude <[email protected]>
    @pr-agent-monadical
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Empty MCP Handling

    The code splits MCPs by comma and filters empty strings, but doesn't handle potential whitespace-only entries that might come from malformed labels.

    mcps = (
        [mcp.strip() for mcp in mcps_str.split(",") if mcp.strip()]
        if mcps_str
        else []
    Data Validation

    There's no validation that the MCPs listed in the container labels actually exist in the system configuration before adding them to the session.

    mcps_str = labels.get("cubbi.mcps", "")
    mcps = (
        [mcp.strip() for mcp in mcps_str.split(",") if mcp.strip()]
        if mcps_str
        else []
    )

    Comment on lines +110 to +116
    # Get MCP list from container labels
    mcps_str = labels.get("cubbi.mcps", "")
    mcps = (
    [mcp.strip() for mcp in mcps_str.split(",") if mcp.strip()]
    if mcps_str
    else []
    )
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: The code doesn't handle the case where labels might be None, which could happen if the container object doesn't have labels. This could lead to an AttributeError when trying to call labels.get(). [possible issue, importance: 8]

    Suggested change
    # Get MCP list from container labels
    mcps_str = labels.get("cubbi.mcps", "")
    mcps = (
    [mcp.strip() for mcp in mcps_str.split(",") if mcp.strip()]
    if mcps_str
    else []
    )
    # Get MCP list from container labels
    labels = labels or {}
    mcps_str = labels.get("cubbi.mcps", "")
    mcps = (
    [mcp.strip() for mcp in mcps_str.split(",") if mcp.strip()]
    if mcps_str
    else []
    )

    Comment on lines +170 to +180
    # Check it ran successfully with exit code 0
    assert result.exit_code == 0
    assert "Removed MCP server 'test-mcp'" in result.stdout
    # Check warning about affected sessions
    assert (
    "Warning: Found 2 active sessions using MCP 'test-mcp'" in result.stdout
    )
    assert "session-1" in result.stdout
    assert "session-3" in result.stdout
    # session-2 should not be mentioned since it doesn't use test-mcp
    assert "session-2" not in result.stdout
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Suggestion: The test is asserting that "session-1" and "session-3" are in the output, but it doesn't verify that these are the only sessions mentioned. If the implementation incorrectly included other sessions, this test would still pass. [general, importance: 5]

    Suggested change
    # Check it ran successfully with exit code 0
    assert result.exit_code == 0
    assert "Removed MCP server 'test-mcp'" in result.stdout
    # Check warning about affected sessions
    assert (
    "Warning: Found 2 active sessions using MCP 'test-mcp'" in result.stdout
    )
    assert "session-1" in result.stdout
    assert "session-3" in result.stdout
    # session-2 should not be mentioned since it doesn't use test-mcp
    assert "session-2" not in result.stdout
    # Check it ran successfully with exit code 0
    assert result.exit_code == 0
    assert "Removed MCP server 'test-mcp'" in result.stdout
    # Check warning about affected sessions
    assert (
    "Warning: Found 2 active sessions using MCP 'test-mcp'" in result.stdout
    )
    # Verify exactly which sessions are mentioned
    assert "session-1" in result.stdout
    assert "session-3" in result.stdout
    # session-2 should not be mentioned since it doesn't use test-mcp
    assert "session-2" not in result.stdout
    # Verify no other session IDs are mentioned
    for session in mock_sessions:
    if session.id not in ["session-1", "session-3"]:
    assert session.id not in result.stdout

    @bouthilx bouthilx merged commit d750e64 into main Jun 26, 2025
    6 of 7 checks passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants