list-products
Retrieve available GPU products from Novita AI clusters to identify suitable instances for AI workloads. Filter results by product name to find specific configurations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clusterId | No | ID of the cluster to list products from. You can use the `list-clusters` tool to get the cluster ID. | |
| productName | No | Name of the product to filter by. |
Implementation Reference
- src/tools.ts:40-58 (handler)The async handler function that implements the core logic of the 'list-products' tool: builds optional query parameters from inputs, calls the Novita API /products endpoint, and returns the JSON-formatted result as MCP text content.}, async (params) => { const queryParams = new URLSearchParams(); if (params.clusterId) queryParams.append("clusterId", params.clusterId); if (params.productName) queryParams.append("productName", params.productName); const queryString = queryParams.toString() ? `?${queryParams.toString()}` : ""; const result = await novitaRequest(`/products${queryString}`); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; });
- src/tools.ts:32-39 (schema)Input schema using Zod validators for the optional 'clusterId' and 'productName' parameters of the list-products tool.clusterId: z .string() .optional() .describe("ID of the cluster to list products from. You can use the `list-clusters` tool to get the cluster ID."), productName: z .string() .optional() .describe("Name of the product to filter by."),
- src/tools.ts:30-59 (registration)The registerProductTools function registers the 'list-products' MCP tool on the server, defining its name, input schema, and handler implementation.function registerProductTools(server: McpServer) { server.tool("list-products", { clusterId: z .string() .optional() .describe("ID of the cluster to list products from. You can use the `list-clusters` tool to get the cluster ID."), productName: z .string() .optional() .describe("Name of the product to filter by."), }, async (params) => { const queryParams = new URLSearchParams(); if (params.clusterId) queryParams.append("clusterId", params.clusterId); if (params.productName) queryParams.append("productName", params.productName); const queryString = queryParams.toString() ? `?${queryParams.toString()}` : ""; const result = await novitaRequest(`/products${queryString}`); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }); }
- src/utils.ts:15-55 (helper)The novitaRequest helper function used by the list-products handler (and other tools) to perform authenticated HTTP requests to the Novita AI GPU instance API endpoints.export async function novitaRequest( endpoint: string, method: string = "GET", body: any = null ) { // Base URL for Novita AI API const API_BASE_URL = "https://api.novita.ai/gpu-instance/openapi/v1"; // Get API key from environment variable const API_KEY = process.env.NOVITA_API_KEY; const url = `${API_BASE_URL}${endpoint}`; const headers = { Authorization: `Bearer ${API_KEY}`, "Content-Type": "application/json", }; const options: any = { method, headers, }; if (body && (method === "POST" || method === "PATCH")) { options.body = JSON.stringify(body); } try { const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); throw new Error(`Novita AI API Error: ${response.status} - ${errorText}`); } // Some endpoints might not return JSON const contentType = response.headers.get("content-type"); if (contentType && contentType.includes("application/json")) { return await response.json(); } return { success: true, status: response.status }; } catch (error) { console.error("Error calling Novita AI API:", error); throw error; } }
- src/index.ts:23-23 (registration)Top-level call to registerAllTools which includes registration of list-products via registerProductTools.registerAllTools(server);