Skip to content

MCP server: auto-restart on version mismatch after upgrade #491

@paddymul

Description

@paddymul

Problem

After a user upgrades buckaroo (uvx --reinstall buckaroo-table), the old data server process keeps running. ensure_server() in mcp_tool.py checks /health and reuses whatever server is already on port 8700 — no version check. The user gets the new MCP tool code but the old server.

Additionally, users have no way to know a new version is available unless they check PyPI manually.

Proposed Fix

Four changes:

1. Add version to /health response

Currently version is only in /diagnostics. The MCP tool already hits /health on every view_data call — add buckaroo.__version__ there so we don't need a second request.

# handlers.py HealthHandler.get()
import buckaroo
self.write({
    "status": "ok",
    "version": getattr(buckaroo, "__version__", "unknown"),
    "pid": os.getpid(),
    ...
})

2. Add POST /shutdown endpoint

Graceful server stop. Returns {"status": "shutting_down"} and stops the IOLoop after a brief delay.

3. Version check in ensure_server()

In mcp_tool.py, after the health check succeeds, compare buckaroo.__version__ with the server's reported version. On mismatch: POST /shutdown, wait for the process to exit, then start a new server.

health = _health_check()
if health:
    import buckaroo
    running_version = health.get("version", "unknown")
    my_version = getattr(buckaroo, "__version__", "unknown")
    if running_version != my_version:
        log.info("Version mismatch: server=%s, mcp=%s — restarting", running_version, my_version)
        _shutdown_server()
        # fall through to start new server
    else:
        return {"server_status": "reused", ...}

4. Check PyPI for new releases, notify user

Once per MCP tool process (i.e. once per Claude Code session), check https://pypi.org/pypi/buckaroo/json for the latest version and compare against buckaroo.__version__. If a newer version exists, append a note to the view_data tool result:

Update available: buckaroo 0.13.0 → 0.14.0
Run: uvx --reinstall buckaroo-table

This way the LLM sees it and can relay it to the user.

Key constraints:

  • Non-blocking — 2s timeout, skip silently on failure. Never break view_data.
  • Once per session — cache result in a module-level variable. Don't hit PyPI on every call.
  • Optional daily cache — write last-checked timestamp + latest version to ~/.buckaroo/update_check.json. Only re-check PyPI if >24h since last check.

User-Facing Upgrade Flow

uvx --reinstall buckaroo-table    # pull latest from PyPI
# next Claude Code session auto-restarts the stale server — invisible to user

References

  • Plan doc: docs/plans/mcp-install-story.md (Upgrade Story section)
  • Current code: buckaroo/mcp_tool.py lines 63-99 (ensure_server)
  • Health handler: buckaroo/server/handlers.py line 49-59

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions