get-template
Retrieve a specific template by ID from the Novita MCP Server to manage AI platform resources efficiently. Simplifies template access for GPU instance operations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| templateId | Yes | ID of the template to retrieve |
Implementation Reference
- src/tools.ts:328-347 (registration)Registration of the 'get-template' tool, including input schema (templateId: string) and inline async handler that constructs a query for the templateId and fetches details from the Novita API endpoint '/template' using the novitaRequest helper, returning formatted JSON text content.server.tool("get-template", { templateId: z .string() .describe("ID of the template to retrieve"), }, async (params) => { const queryParams = new URLSearchParams(); queryParams.append("templateId", params.templateId); const queryString = queryParams.toString() ? `?${queryParams.toString()}` : ""; const result = await novitaRequest(`/template${queryString}`); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; });
- src/tools.ts:329-331 (schema)Input schema for the 'get-template' tool defining the required 'templateId' parameter as a string with description.templateId: z .string() .describe("ID of the template to retrieve"),
- src/tools.ts:332-347 (handler)Handler function for 'get-template' that queries the Novita API with the provided templateId and returns the result as a text content block with JSON stringified.}, async (params) => { const queryParams = new URLSearchParams(); queryParams.append("templateId", params.templateId); const queryString = queryParams.toString() ? `?${queryParams.toString()}` : ""; const result = await novitaRequest(`/template${queryString}`); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; });
- src/utils.ts:15-55 (helper)Supporting utility function novitaRequest used by the get-template handler to perform authenticated HTTP requests to the Novita AI API.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; } }