add-api
Add a new API to an API group in the Xano MCP Server by specifying its ID, name, description, HTTP verb, and optional tags for organization.
Instructions
Add a new API to an API group
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| apigroup_id | Yes | ID of the API group to add the API to | |
| description | Yes | Description of the API | |
| docs | No | Documentation for the API | |
| name | Yes | Name of the API | |
| tag | No | Tags to associate with the API | |
| verb | Yes | HTTP verb for the API |
Implementation Reference
- src/index.ts:933-983 (handler)The asynchronous handler function for the 'add-api' tool. It constructs a request body from the input parameters and uses makeXanoRequest to POST a new API to the specified API group endpoint. It formats a success response with details or returns an error message.async ({ apigroup_id, name, description, docs, verb, tag }) => { console.error(`[Tool] Executing add-api for API group ID: ${apigroup_id}`); try { const requestBody = { name, description, verb, ...(docs !== undefined && { docs }), ...(tag !== undefined && { tag }) }; const response = await makeXanoRequest<XanoApi>( `/workspace/${XANO_WORKSPACE}/apigroup/${apigroup_id}/api`, 'POST', requestBody ); console.error(`[Tool] Successfully added API "${name}" with ID: ${response.id} to API group ID: ${apigroup_id}`); const formattedContent = `# API Added\n\n` + `**Name**: ${response.name}\n` + `**ID**: ${response.id}\n` + `**API Group ID**: ${apigroup_id}\n` + `**Verb**: ${response.verb}\n` + `**Description**: ${response.description}\n` + `${response.docs ? `**Documentation**: ${response.docs}\n` : ''}` + `**Created**: ${new Date(response.created_at).toLocaleString()}\n` + `${response.guid ? `**GUID**: ${response.guid}\n` : ''}` + `${response.tag && response.tag.length > 0 ? `**Tags**: ${response.tag.join(', ')}\n` : ''}`; return { content: [ { type: "text", text: formattedContent } ] }; } catch (error) { console.error(`[Error] Failed to add API: ${error instanceof Error ? error.message : String(error)}`); return { content: [ { type: "text", text: `Error adding API: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
- src/index.ts:926-932 (schema)Zod schema defining the input parameters for the 'add-api' tool: apigroup_id (required string), name (string), description (string), docs (optional string), verb (enum of HTTP methods), tag (optional array of strings).apigroup_id: z.string().describe("ID of the API group to add the API to"), name: z.string().describe("Name of the API"), description: z.string().describe("Description of the API"), docs: z.string().optional().describe("Documentation for the API"), verb: z.enum(["GET", "POST", "DELETE", "PUT", "PATCH", "HEAD"]).describe("HTTP verb for the API"), tag: z.array(z.string()).optional().describe("Tags to associate with the API") },
- src/index.ts:922-984 (registration)Registration of the 'add-api' tool using server.tool(), including name, description, input schema, and inline handler function.server.tool( "add-api", "Add a new API to an API group", { apigroup_id: z.string().describe("ID of the API group to add the API to"), name: z.string().describe("Name of the API"), description: z.string().describe("Description of the API"), docs: z.string().optional().describe("Documentation for the API"), verb: z.enum(["GET", "POST", "DELETE", "PUT", "PATCH", "HEAD"]).describe("HTTP verb for the API"), tag: z.array(z.string()).optional().describe("Tags to associate with the API") }, async ({ apigroup_id, name, description, docs, verb, tag }) => { console.error(`[Tool] Executing add-api for API group ID: ${apigroup_id}`); try { const requestBody = { name, description, verb, ...(docs !== undefined && { docs }), ...(tag !== undefined && { tag }) }; const response = await makeXanoRequest<XanoApi>( `/workspace/${XANO_WORKSPACE}/apigroup/${apigroup_id}/api`, 'POST', requestBody ); console.error(`[Tool] Successfully added API "${name}" with ID: ${response.id} to API group ID: ${apigroup_id}`); const formattedContent = `# API Added\n\n` + `**Name**: ${response.name}\n` + `**ID**: ${response.id}\n` + `**API Group ID**: ${apigroup_id}\n` + `**Verb**: ${response.verb}\n` + `**Description**: ${response.description}\n` + `${response.docs ? `**Documentation**: ${response.docs}\n` : ''}` + `**Created**: ${new Date(response.created_at).toLocaleString()}\n` + `${response.guid ? `**GUID**: ${response.guid}\n` : ''}` + `${response.tag && response.tag.length > 0 ? `**Tags**: ${response.tag.join(', ')}\n` : ''}`; return { content: [ { type: "text", text: formattedContent } ] }; } catch (error) { console.error(`[Error] Failed to add API: ${error instanceof Error ? error.message : String(error)}`); return { content: [ { type: "text", text: `Error adding API: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );