test_connection
Verifies accessibility of the target URL (http://localhost) to ensure proper connectivity for localhost web applications in the MCP Login Server environment.
Instructions
Tests if the target URL (http://localhost) is accessible
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools.ts:129-169 (handler)The inline async handler function that implements the core logic of the test_connection tool. It attempts a HEAD fetch to http://localhost with 5s timeout and returns a markdown-formatted response with connection status.async () => { try { // Basic connectivity test const response = await fetch(LOGIN_CREDENTIALS.targetUrl, { method: 'HEAD', signal: AbortSignal.timeout(5000) }); return { content: [ { type: "text", text: `Connection Test Results: 🎯 Target URL: ${LOGIN_CREDENTIALS.targetUrl} ✅ Status: ${response.status} ${response.statusText} 🔗 Accessible: Yes ⏱️ Response Time: Available 💡 The target URL is accessible and ready for login operations.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Connection Test Results: 🎯 Target URL: ${LOGIN_CREDENTIALS.targetUrl} ❌ Status: Connection Failed 🔗 Accessible: No ⚠️ Error: ${error instanceof Error ? error.message : String(error)} 💡 Please ensure the target server is running on localhost.` } ] }; } }
- src/tools.ts:124-171 (registration)Registers the test_connection tool with the MCP server, providing the tool name, description, empty input schema {}, and the inline handler function.export function registerTestConnectionTool(server: McpServer): void { server.tool( "test_connection", "Tests if the target URL (http://localhost) is accessible", {}, async () => { try { // Basic connectivity test const response = await fetch(LOGIN_CREDENTIALS.targetUrl, { method: 'HEAD', signal: AbortSignal.timeout(5000) }); return { content: [ { type: "text", text: `Connection Test Results: 🎯 Target URL: ${LOGIN_CREDENTIALS.targetUrl} ✅ Status: ${response.status} ${response.statusText} 🔗 Accessible: Yes ⏱️ Response Time: Available 💡 The target URL is accessible and ready for login operations.` } ] }; } catch (error) { return { content: [ { type: "text", text: `Connection Test Results: 🎯 Target URL: ${LOGIN_CREDENTIALS.targetUrl} ❌ Status: Connection Failed 🔗 Accessible: No ⚠️ Error: ${error instanceof Error ? error.message : String(error)} 💡 Please ensure the target server is running on localhost.` } ] }; } } ); }
- src/tools.ts:244-244 (registration)Within registerAllTools, calls registerTestConnectionTool to include test_connection in the full toolset registration.registerTestConnectionTool(server);
- src/tools.ts:8-12 (helper)Configuration constant providing the targetUrl used by the test_connection handler for the fetch request.export const LOGIN_CREDENTIALS = { username: "admin", password: "AIWorkshopJuly!25", targetUrl: "http://localhost" };
- src/tools.ts:255-255 (helper)Lists test_connection in the array of available tools returned by getAvailableTools()."test_connection",