@@ -535,6 +535,15 @@ async def list_tools() -> List[Tool]:
535535 },
536536 "required" : ["start_x" , "start_y" , "start_z" , "end_x" , "end_y" , "end_z" , "block_type" , "stair_type" , "staircase_direction" ]
537537 }
538+ ),
539+ Tool (
540+ name = "test_server_connection" ,
541+ description = "Test if the Minecraft server API is running and responding to requests" ,
542+ inputSchema = {
543+ "type" : "object" ,
544+ "properties" : {},
545+ "required" : []
546+ }
538547 )
539548 ]
540549
@@ -582,6 +591,9 @@ async def call_tool(name: str, arguments: Dict[str, Any]) -> List[ContentBlock]:
582591 elif name == "place_stairs" :
583592 result = await self .place_stairs (** arguments )
584593 return result .content
594+ elif name == "test_server_connection" :
595+ result = await self .test_server_connection ()
596+ return result .content
585597 else :
586598 raise ValueError (f"Unknown tool: { name } " )
587599 except Exception as e :
@@ -1189,6 +1201,58 @@ async def place_stairs(self, start_x: int, start_y: int, start_z: int, end_x: in
11891201 content = [TextContent (type = "text" , text = f"Error connecting to Minecraft API: { str (e )} " )]
11901202 )
11911203
1204+ async def test_server_connection (self ) -> CallToolResult :
1205+ """Test if the Minecraft server API is running and responding."""
1206+ try :
1207+ async with httpx .AsyncClient (timeout = 5.0 ) as client :
1208+ response = await client .get (f"{ self .api_base } /" )
1209+ response .raise_for_status ()
1210+
1211+ # Check if we get the expected "Hello World" response
1212+ response_text = response .text .strip ()
1213+ if response_text == "Hello World" :
1214+ return CallToolResult (
1215+ content = [TextContent (
1216+ type = "text" ,
1217+ text = "✅ Minecraft server is ONLINE and responding correctly"
1218+ )]
1219+ )
1220+ else :
1221+ return CallToolResult (
1222+ content = [TextContent (
1223+ type = "text" ,
1224+ text = f"⚠️ Minecraft server responded but with unexpected content: '{ response_text } '"
1225+ )]
1226+ )
1227+ except httpx .ConnectError :
1228+ return CallToolResult (
1229+ content = [TextContent (
1230+ type = "text" ,
1231+ text = "❌ Cannot connect to Minecraft server - server is OFFLINE or not running"
1232+ )]
1233+ )
1234+ except httpx .TimeoutException :
1235+ return CallToolResult (
1236+ content = [TextContent (
1237+ type = "text" ,
1238+ text = "❌ Minecraft server connection TIMEOUT - server may be overloaded"
1239+ )]
1240+ )
1241+ except httpx .HTTPStatusError as e :
1242+ return CallToolResult (
1243+ content = [TextContent (
1244+ type = "text" ,
1245+ text = f"❌ Minecraft server returned HTTP error { e .response .status_code } : { e .response .text } "
1246+ )]
1247+ )
1248+ except Exception as e :
1249+ return CallToolResult (
1250+ content = [TextContent (
1251+ type = "text" ,
1252+ text = f"❌ Error testing server connection: { str (e )} "
1253+ )]
1254+ )
1255+
11921256 async def run (self ):
11931257 """Run the MCP server."""
11941258 print ("Starting MCP server stdio connection..." , file = sys .stderr )
0 commit comments