Skip to content

Commit 84032de

Browse files
committed
Fix basic health handling + give json instead of dict for list of indices
1 parent 84c2035 commit 84032de

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/meilisearch_mcp/client.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def __init__(self, url: str = "http://localhost:7700", api_key: Optional[str] =
3030
async def health_check(self) -> bool:
3131
"""Check if Meilisearch is healthy"""
3232
try:
33-
health = self.client.health()
34-
return health.status == "available"
33+
response = self.client.health()
34+
return response.get("status") == "available"
3535
except Exception:
3636
return False
3737

@@ -41,4 +41,25 @@ async def get_version(self) -> Dict[str, Any]:
4141

4242
async def get_stats(self) -> Dict[str, Any]:
4343
"""Get database stats"""
44-
return self.client.get_stats()
44+
# return self.client.get_stats()
45+
return "This method has not yet been implemented in the Meilisearch client."
46+
47+
async def get_indexes(self) -> Dict[str, Any]:
48+
"""Get all indexes"""
49+
indexes = self.client.get_indexes()
50+
# Convert Index objects to serializable dictionaries
51+
serialized_indexes = []
52+
for index in indexes['results']:
53+
serialized_indexes.append({
54+
"uid": index.uid,
55+
"primaryKey": index.primary_key,
56+
"createdAt": index.created_at,
57+
"updatedAt": index.updated_at
58+
})
59+
60+
return {
61+
"results": serialized_indexes,
62+
"offset": indexes['offset'],
63+
"limit": indexes['limit'],
64+
"total": indexes['total']
65+
}

src/meilisearch_mcp/server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ async def handle_call_tool(name: str, arguments: Optional[Dict[str, Any]] = None
257257
)]
258258

259259
elif name == "list-indexes":
260-
indexes = await self.meili_client.indexes.list_indexes()
260+
indexes = await self.meili_client.get_indexes()
261+
formatted_json = json.dumps(indexes, indent=2)
261262
return [types.TextContent(
262263
type="text",
263-
text=f"Available indexes: {indexes}"
264+
text=f"Indexes:\n{formatted_json}"
264265
)]
265266

266267
elif name == "get-documents":
@@ -289,7 +290,7 @@ async def handle_call_tool(name: str, arguments: Optional[Dict[str, Any]] = None
289290
is_healthy = await self.meili_client.health_check()
290291
return [types.TextContent(
291292
type="text",
292-
text=f"Meilisearch health status: {'healthy' if is_healthy else 'unhealthy'}"
293+
text=f"Meilisearch is {is_healthy and 'available' or 'unavailable'}"
293294
)]
294295

295296
elif name == "get-version":

0 commit comments

Comments
 (0)