add-api
Create a new API endpoint within an API group to define HTTP methods, descriptions, and documentation for database interactions.
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 | |
| name | Yes | Name of the API | |
| description | Yes | Description of the API | |
| docs | No | Documentation for the API | |
| verb | Yes | HTTP verb for the API | |
| tag | No | Tags to associate with the API |
Implementation Reference
- src/index.ts:933-983 (handler)The handler function that implements the core logic of the 'add-api' tool. It constructs a request body from the input parameters and makes a POST request to the Xano API to create a new API in the specified API group. It formats and returns a success message with details of the created 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 }; } }
- src/index.ts:925-932 (schema)Zod schema defining the input parameters and validation for the 'add-api' tool.{ 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)The server.tool registration call that defines and registers the 'add-api' tool with the MCP server, including its name, description, input schema, and 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 }; } } );