Skip to content

Commit c8b43bc

Browse files
committed
add alias tool
1 parent f4daf4a commit c8b43bc

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/elasticsearch_mcp_server/server.py

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .tools.index import IndexTools
55
from .tools.document import DocumentTools
66
from .tools.cluster import ClusterTools
7+
from .tools.alias import AliasTools
78

89
class ElasticsearchMCPServer:
910
def __init__(self):
@@ -26,11 +27,13 @@ def _register_tools(self):
2627
index_tools = IndexTools(self.logger)
2728
document_tools = DocumentTools(self.logger)
2829
cluster_tools = ClusterTools(self.logger)
30+
alias_tools = AliasTools(self.logger)
2931

3032
# Register tools from each module
3133
index_tools.register_tools(self.mcp)
3234
document_tools.register_tools(self.mcp)
3335
cluster_tools.register_tools(self.mcp)
36+
alias_tools.register_tools(self.mcp)
3437

3538
def run(self):
3639
"""Run the MCP server."""
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from typing import Any
2+
from ..es_client import ElasticsearchClient
3+
from mcp.types import TextContent
4+
5+
6+
class AliasTools(ElasticsearchClient):
7+
def register_tools(self, mcp: Any):
8+
"""Register alias-related tools."""
9+
10+
@mcp.tool(description="List all aliases in the Elasticsearch cluster")
11+
async def list_aliases() -> list[TextContent]:
12+
"""List all aliases in the Elasticsearch cluster."""
13+
self.logger.info("Listing aliases...")
14+
try:
15+
aliases = self.es_client.cat.aliases(format="json")
16+
return [TextContent(type="text", text=str(aliases))]
17+
except Exception as e:
18+
self.logger.error(f"Error listing aliases: {e}")
19+
return [TextContent(type="text", text=f"Error: {str(e)}")]
20+
21+
@mcp.tool(description="Get alias information for an index")
22+
async def get_alias(index: str) -> list[TextContent]:
23+
"""
24+
Get alias information for a specific index.
25+
26+
Args:
27+
index: Name of the index
28+
"""
29+
self.logger.info(f"Getting alias information for index: {index}")
30+
try:
31+
response = self.es_client.indices.get_alias(index=index)
32+
return [TextContent(type="text", text=str(response))]
33+
except Exception as e:
34+
self.logger.error(f"Error getting alias information: {e}")
35+
return [TextContent(type="text", text=f"Error: {str(e)}")]

0 commit comments

Comments
 (0)