DA-2125: Add cluster metrics tool and node discovery tool - #248
Open
VirajAgarwal-couchbase wants to merge 4 commits into
Open
DA-2125: Add cluster metrics tool and node discovery tool#248VirajAgarwal-couchbase wants to merge 4 commits into
VirajAgarwal-couchbase wants to merge 4 commits into
Conversation
VirajAgarwal-couchbase
marked this pull request as ready for review
August 31, 2026 08:13
VirajAgarwal-couchbase
requested review from
AayushTyagi1
and
a lite review from Copilot
August 31, 2026 08:13
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds two new read-only Couchbase Server MCP tools that call Management REST endpoints directly: one for fetching historical cluster metrics (stats-range) and one for discovering cluster nodes (Prometheus SD). The change also introduces small connection-string parsing utilities, registers the new tools in the tool registry/read-only mode, and expands unit/integration/accuracy coverage plus documentation.
Changes:
- Add
get_cluster_metrics(POST/pools/default/stats/range) andget_nodes_in_cluster(GET/prometheus_sd_config) with Capella upfront rejection and multi-host failover. - Register both tools as always-available read-only tools and update read-only tool counts.
- Add/extend unit, integration, and accuracy tests; update README/DOCKER docs.
File summaries
| File | Description |
|---|---|
| tests/unit/test_server_tools_unit.py | Adds unit tests for Capella rejection, REST success/error envelopes, and multi-host failover for the new tools. |
| tests/unit/test_read_only_mode.py | Updates read-only tool name set and expected tool counts to include the two new tools. |
| tests/unit/test_connection_string.py | Adds unit tests for connection-string host extraction and Capella detection helpers. |
| tests/integration/test_server_tools.py | Adds integration coverage for calling the two new tools via MCP session. |
| tests/integration/conftest.py | Allows the new tools in integration tool allowlists. |
| tests/accuracy/tool_calling/test_server.py | Adds accuracy cases expecting the model to select the new tools. |
| tests/accuracy/result_validation/test_server.py | Adds faithfulness validation cases for the new tools’ outputs. |
| src/cb_mcp/utils/connection_string.py | Introduces helpers to extract hosts from connection strings and detect Capella connections. |
| src/cb_mcp/tools/server.py | Implements the two new REST-backed tools and uses connection-string helpers + settings validation. |
| src/cb_mcp/tools/init.py | Registers the new tools in READ_ONLY_TOOLS, annotations, and __all__. |
| README.md | Documents the two new tools and Capella/self-managed constraints. |
| DOCKER.md | Mirrors README tool documentation updates for Docker usage. |
Review details
Suppressed comments (1)
src/cb_mcp/tools/server.py:414
- Same as
get_cluster_metrics: if host extraction returns an empty list, the function currently falls through and raisesRuntimeErrorwithlast_error=None(and may attempt invalid URLs). Add a fast-fail check for an empty host list to return a clearer error envelope.
# Capella is already excluded above, so no Capella-CA handling is needed here —
# just the CA path for a self-signed self-managed cert, or the system CA bundle.
verify_ssl = (settings.get("ca_cert_path") or True) if is_tls else False
hosts = extract_hosts_from_connection_string(connection_string)
last_error: Exception | None = None
with httpx.Client(verify=verify_ssl, timeout=timeout) as client:
for host in hosts:
- Files reviewed: 12/12 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issue
Resolves: DA-2125
What does this change do?
Adds two new read-only MCP tools:
get_cluster_metrics— retrieves one or more cluster statistics over a historic time windowin a single call, via the Management REST API's
POST /pools/default/stats/range(stats-range) endpoint.
get_nodes_in_cluster— lists the cluster's nodes ashost:porttargets, via the ManagementREST API's
GET /prometheus_sd_config(Prometheus service-discovery) endpoint.Both tools are registered as read-only (
readOnlyHint=True, always available regardless ofREAD_ONLY_MODE) and are self-managed-Couchbase-Server-only: if the configured connectionstring points at a Capella cluster, the tool detects this up front and returns a clean
{"status": "error", ...}response instead of attempting the REST call.Evidence of Testing
Automated tests — commands run and results summary:
Environments tested:
suite (unit + integration + accuracy) run above.
Manual verification — MCP client used (Claude Desktop, Cursor, MCP Inspector, ...) and what was exercised. Screenshots or tool-call transcripts are very helpful:
Compatibility Considerations
REST endpoints (
/pools/default/stats/range,/prometheus_sd_config) that Capella does notexpose the same way; rather than let the request fail with an opaque network/auth error, the
tools detect a Capella connection string up front and return a clear, structured error instead.
Checklist
httpx, following the same precedent aslist_indexes's existing/getIndexStatusREST fallback inindex_utils.py.cb_mcp.corecontracts / managed MCP interfaces (or discussed first)