@@ -39,17 +39,45 @@ def __init__(
3939 log_dir = os .path .expanduser ("~/.meilisearch-mcp/logs" )
4040
4141 self .logger = MCPLogger ("meilisearch-mcp" , log_dir )
42+ self .url = url
43+ self .api_key = api_key
4244 self .meili_client = MeilisearchClient (url , api_key )
4345 self .server = Server ("meilisearch" )
4446 self ._setup_handlers ()
4547
48+ async def update_connection (self , url : Optional [str ] = None , api_key : Optional [str ] = None ):
49+ """Update connection settings and reinitialize client if needed"""
50+ if url :
51+ self .url = url
52+ if api_key :
53+ self .api_key = api_key
54+
55+ self .meili_client = MeilisearchClient (self .url , self .api_key )
56+ self .logger .info ("Updated Meilisearch connection settings" , url = self .url )
57+
4658 def _setup_handlers (self ):
4759 """Setup MCP request handlers"""
4860
4961 @self .server .list_tools ()
5062 async def handle_list_tools () -> list [types .Tool ]:
5163 """List available tools"""
5264 return [
65+ types .Tool (
66+ name = "get-connection-settings" ,
67+ description = "Get current Meilisearch connection settings" ,
68+ inputSchema = {"type" : "object" , "properties" : {}},
69+ ),
70+ types .Tool (
71+ name = "update-connection-settings" ,
72+ description = "Update Meilisearch connection settings" ,
73+ inputSchema = {
74+ "type" : "object" ,
75+ "properties" : {
76+ "url" : {"type" : "string" , "optional" : True },
77+ "api_key" : {"type" : "string" , "optional" : True },
78+ },
79+ },
80+ ),
5381 types .Tool (
5482 name = "health-check" ,
5583 description = "Check Meilisearch server health" ,
@@ -241,7 +269,27 @@ async def handle_call_tool(
241269 ) -> list [types .TextContent ]:
242270 """Handle tool execution"""
243271 try :
244- if name == "create-index" :
272+ if name == "get-connection-settings" :
273+ return [
274+ types .TextContent (
275+ type = "text" ,
276+ text = f"Current connection settings:\n URL: { self .url } \n API Key: { '*' * 8 if self .api_key else 'Not set' } " ,
277+ )
278+ ]
279+
280+ elif name == "update-connection-settings" :
281+ await self .update_connection (
282+ arguments .get ("url" ),
283+ arguments .get ("api_key" )
284+ )
285+ return [
286+ types .TextContent (
287+ type = "text" ,
288+ text = f"Successfully updated connection settings to URL: { self .url } " ,
289+ )
290+ ]
291+
292+ elif name == "create-index" :
245293 result = await self .meili_client .indexes .create_index (
246294 arguments ["uid" ], arguments .get ("primaryKey" )
247295 )
0 commit comments