check-connection
Verify API URL and authentication validity to ensure secure access to PI Dashboard resources.
Instructions
Check if the current API URL and authentication are valid
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- build/index.js:263-307 (handler)The handler function for the 'check-connection' tool. It checks if API URL and auth token are configured, calls verifyConnection() to test the API, and returns success or error messages.server.tool("check-connection", "Check if the current API URL and authentication are valid", {}, async () => { try { if (!apiUrlSet || !API_BASE_URL) { return { content: [{ type: "text", text: "API URL not set. Please set the API URL using the set-api-url tool." }] }; } if (!authToken) { return { content: [{ type: "text", text: "Not authenticated. Please authenticate using the authenticate tool." }] }; } // Verify the connection const isConnected = await verifyConnection(); if (isConnected) { return { content: [{ type: "text", text: `✅ Connection successful! The API URL and token are valid. You're ready to use the PI API.` }] }; } else { return { isError: true, content: [{ type: "text", text: `❌ Connection failed. The token might be invalid or expired. Please try to authenticate again.` }] }; } } catch (error) { return { isError: true, content: [{ type: "text", text: `Connection check failed: ${getErrorMessage(error)}` }] }; } });
- build/index.js:263-263 (registration)Registers the 'check-connection' tool on the MCP server with empty input schema (no parameters required).server.tool("check-connection", "Check if the current API URL and authentication are valid", {}, async () => {
- build/index.js:144-162 (helper)Helper function verifyConnection() called by the check-connection handler to test the API connection via /tokens/keepAlive endpoint.async function verifyConnection() { if (!apiUrlSet || !API_BASE_URL) { return false; } if (!authToken) { return false; } try { // Try a lightweight request to verify the connection await authenticatedRequest("/tokens/keepAlive", "POST"); connectionVerified = true; return true; } catch (error) { logError(`Connection verification failed: ${getErrorMessage(error)}`); connectionVerified = false; return false; } }
- build/index.js:263-263 (schema)Input schema for check-connection tool: empty object, indicating no input parameters are required.server.tool("check-connection", "Check if the current API URL and authentication are valid", {}, async () => {