set-api-url
Configure the API endpoint for PI Dashboard by setting the base URL, directing all subsequent API calls to the specified server.
Instructions
Set the API base URL for all requests
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | API base URL (e.g., http://localhost:8224/pi/api/v2) |
Implementation Reference
- build/index.js:312-345 (registration)Registration of the 'set-api-url' MCP tool using server.tool(), defining the tool name, description, schema with a 'url' parameter, and the async handler function.
server.tool("set-api-url", "Set the API base URL for all requests", { url: z.string().describe("API base URL (e.g., http://localhost:8224/pi/api/v2)") }, async ({ url }) => { try { // Validate URL format try { new URL(url); } catch (e) { return { isError: true, content: [{ type: "text", text: `Invalid URL format. Please provide a valid URL including protocol (http:// or https://).` }] }; } API_BASE_URL = url; apiUrlSet = true; connectionVerified = false; return { content: [{ type: "text", text: `API URL set to: ${url}\n\nNext step: Please authenticate to start using the API.` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error setting API URL: ${getErrorMessage(error)}` }] }; } }); - build/index.js:313-314 (schema)Input schema for the 'set-api-url' tool: requires a single 'url' string parameter described as 'API base URL (e.g., http://localhost:8224/pi/api/v2)'.
url: z.string().describe("API base URL (e.g., http://localhost:8224/pi/api/v2)") }, async ({ url }) => { - build/index.js:314-345 (handler)Handler function for 'set-api-url'. Validates URL format using new URL(), sets API_BASE_URL and apiUrlSet globals, resets connectionVerified, and returns a success message prompting the user to authenticate.
}, async ({ url }) => { try { // Validate URL format try { new URL(url); } catch (e) { return { isError: true, content: [{ type: "text", text: `Invalid URL format. Please provide a valid URL including protocol (http:// or https://).` }] }; } API_BASE_URL = url; apiUrlSet = true; connectionVerified = false; return { content: [{ type: "text", text: `API URL set to: ${url}\n\nNext step: Please authenticate to start using the API.` }] }; } catch (error) { return { isError: true, content: [{ type: "text", text: `Error setting API URL: ${getErrorMessage(error)}` }] }; } }); - build/index.js:43-44 (helper)Global state variable 'apiUrlSet' that tracks whether the API URL has been set (initialized from CLI --api-url arg or via the set-api-url tool).
let apiUrlSet = !!API_BASE_URL; let connectionVerified = false; - build/index.js:58-59 (helper)The authenticatedRequest helper checks apiUrlSet and throws an error referencing the set-api-url tool if the URL hasn't been configured yet.
if (!apiUrlSet) { throw new Error("API URL not set. Please set the API URL using the set-api-url tool.");