Skip to content

Commit aaa77ee

Browse files
[DA-1204] Tool to get list of services status of them (#64)
Co-authored-by: Nithish Raghunandanan <12782505+nithishr@users.noreply.github.com>
1 parent 3ca6c73 commit aaa77ee

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ An [MCP](https://modelcontextprotocol.io/) server implementation of Couchbase th
2222
- There is an option in the MCP server, `CB_MCP_READ_ONLY_QUERY_MODE` that is set to true by default to disable running SQL++ queries that change the data or the underlying collection structure. Note that the documents can still be updated by ID.
2323
- Get the status of the MCP server
2424
- Check the cluster credentials by connecting to the cluster
25+
- Get cluster health status and list of all running services
2526

2627
## Prerequisites
2728

src/tools/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
# Server tools
2424
from .server import (
2525
get_buckets_in_cluster,
26+
get_cluster_health_and_services,
2627
get_collections_in_scope,
2728
get_scopes_and_collections_in_bucket,
2829
get_scopes_in_bucket,
@@ -44,6 +45,7 @@
4445
get_schema_for_collection,
4546
run_sql_plus_plus_query,
4647
get_index_advisor_recommendations,
48+
get_cluster_health_and_services,
4749
]
4850

4951
__all__ = [
@@ -60,6 +62,7 @@
6062
"get_schema_for_collection",
6163
"run_sql_plus_plus_query",
6264
"get_index_advisor_recommendations",
65+
"get_cluster_health_and_services",
6366
# Convenience
6467
"ALL_TOOLS",
6568
]

src/tools/server.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
This module contains tools for getting the server status, testing the connection, and getting the buckets in the cluster, the scopes and collections in the bucket.
55
"""
66

7+
import json
78
import logging
89
from typing import Any
910

@@ -137,3 +138,43 @@ def get_collections_in_scope(
137138
ctx, query, bucket_name=bucket_name, scope_name=scope_name
138139
)
139140
return [result["collection_name"] for result in results]
141+
142+
143+
def get_cluster_health_and_services(
144+
ctx: Context, bucket_name: str | None = None
145+
) -> dict[str, Any]:
146+
"""Get cluster health status and list of all running services.
147+
148+
This tool provides health monitoring by:
149+
- Getting health status of all running services with latency information (via ping)
150+
- Listing all services running on the cluster with their endpoints
151+
- Showing connection status and node information for each service
152+
153+
If bucket_name is provided, it actively pings services from the perspective of the bucket.
154+
Otherwise, it uses cluster-level ping to get the health status of the cluster.
155+
156+
Returns:
157+
- Cluster health status with service-level connection details and latency measurements
158+
"""
159+
try:
160+
cluster = get_cluster_connection(ctx)
161+
162+
if bucket_name:
163+
# Ping services from the perspective of the bucket
164+
bucket = connect_to_bucket(cluster, bucket_name)
165+
result = bucket.ping().as_json()
166+
else:
167+
# Ping services from the perspective of the cluster
168+
result = cluster.ping().as_json()
169+
170+
return {
171+
"status": "success",
172+
"data": json.loads(result),
173+
}
174+
except Exception as e:
175+
logger.error(f"Error getting cluster health: {e}")
176+
return {
177+
"status": "error",
178+
"error": str(e),
179+
"message": "Failed to get cluster health and services information",
180+
}

0 commit comments

Comments
 (0)