Skip to main content
Glama

add-table

Create a new table in Xano database with custom schema, including field types, validation rules, and foreign key relationships.

Instructions

Add a new table to the Xano database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the table
descriptionNoDescription of the table
schemaNoSchema configuration for the table. For foreign key relationships, use type 'int' with tableref_id. Example: { "name": "contact_id", "type": "int", "description": "Reference to contact table", "nullable": false, "required": false, "access": "public", "style": "single", "default": "0", "tableref_id": "100" // ID of the table to reference }

Implementation Reference

  • The handler function for the 'add-table' tool. It creates a new table in Xano using POST /workspace/{XANO_WORKSPACE}/table, then optionally processes and applies the provided schema via PUT /table/{tableId}/schema, handling foreign key validation for fields with tableref_id.
    async ({ name, description, schema }) => {
      console.error(`[Tool] Executing add-table for table: ${name}`);
      try {
        // Step 1: Create the table
        const createTableResponse = await makeXanoRequest<{ id: string }>(
          `/workspace/${XANO_WORKSPACE}/table`, 
          'POST', 
          { name, description }
        );
        
        const tableId = createTableResponse.id;
        console.error(`[Tool] Table created with ID: ${tableId}`);
        
        // Step 2: If schema is provided, process and add it to the table
        if (schema && schema.length > 0) {
          try {
            // Process schema fields to handle relationships
            const processedSchema = schema.map(field => {
              // Validate relationship fields
              if (field.tableref_id && field.type !== "int") {
                throw new Error(`Field "${field.name}" has tableref_id but type is not "int". Foreign key fields must be of type "int".`);
              }
              
              return field;
            });
            
            // Update the schema with processed fields
            await makeXanoRequest(
              `/workspace/${XANO_WORKSPACE}/table/${tableId}/schema`, 
              'PUT', 
              { schema: processedSchema }
            );
            console.error(`[Tool] Schema successfully added to table ID: ${tableId}`);
          } catch (schemaError) {
            console.error(`[Error] Failed to add schema: ${schemaError instanceof Error ? schemaError.message : String(schemaError)}`);
            return {
              content: [
                {
                  type: "text",
                  text: `Table created with ID ${tableId}, but failed to add schema: ${schemaError instanceof Error ? schemaError.message : String(schemaError)}`
                }
              ],
              isError: true
            };
          }
        }
        
        return {
          content: [
            {
              type: "text",
              text: `Successfully created table "${name}" with ID: ${tableId}${schema ? ' and added the specified schema.' : '.'}`
            }
          ]
        };
      } catch (error) {
        console.error(`[Error] Failed to create table: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [
            {
              type: "text",
              text: `Error creating table: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the 'add-table' tool: table name, optional description, and optional array of schema fields with comprehensive type, validation, and relationship support.
    {
      name: z.string().describe("Name of the table"),
      description: z.string().optional().describe("Description of the table"),
      schema: z.array(z.object({
        name: z.string().describe("Name of the schema element"),
        type: z.enum([
          "attachment", "audio", "bool", "date", "decimal", "email", "enum", 
          "geo_linestring", "geo_multilinestring", "geo_multipoint", "geo_multipolygon", 
          "geo_point", "geo_polygon", "image", "int", "json", "object", "password", 
          "tablerefuuid", "text", "timestamp", "uuid", "vector", "video"
        ]).describe("Type of the schema element"),
        description: z.string().optional().describe("Description of the schema element"),
        nullable: z.boolean().optional().default(false).describe("Whether the field can be null"),
        required: z.boolean().optional().default(false).describe("Whether the field is required"),
        access: z.enum(["public", "private", "internal"]).optional().default("public").describe("Access level for the field"),
        style: z.enum(["single", "list"]).optional().default("single").describe("Whether the field is a single value or a list"),
        default: z.string().optional().describe("Default value for the field"),
        config: z.record(z.any()).optional().describe("Additional configuration for specific field types"),
        validators: z.object({
          lower: z.boolean().optional(),
          max: z.number().optional(),
          maxLength: z.number().optional(),
          min: z.number().optional(),
          minLength: z.number().optional(),
          pattern: z.string().optional(),
          precision: z.number().optional(),
          scale: z.number().optional(),
          trim: z.boolean().optional()
        }).optional().describe("Validation rules for the field"),
        children: z.array(z.any()).optional().describe("Nested fields for object types"),
        tableref_id: z.string().optional().describe("ID of the referenced table (only valid when type is 'int')"),
        values: z.array(z.string()).optional().describe("Array of allowed values (only for enum type)")
      })).optional().describe(`Schema configuration for the table. For foreign key relationships, use type 'int' with tableref_id. Example:
      {
        "name": "contact_id",
        "type": "int",
        "description": "Reference to contact table",
        "nullable": false,
        "required": false,
        "access": "public",
        "style": "single",
        "default": "0",
        "tableref_id": "100"  // ID of the table to reference
      }`)
    },
  • src/index.ts:255-370 (registration)
    The server.tool registration call that defines and registers the 'add-table' tool with its description, input schema, and handler function.
      "add-table",
      "Add a new table to the Xano database",
      {
        name: z.string().describe("Name of the table"),
        description: z.string().optional().describe("Description of the table"),
        schema: z.array(z.object({
          name: z.string().describe("Name of the schema element"),
          type: z.enum([
            "attachment", "audio", "bool", "date", "decimal", "email", "enum", 
            "geo_linestring", "geo_multilinestring", "geo_multipoint", "geo_multipolygon", 
            "geo_point", "geo_polygon", "image", "int", "json", "object", "password", 
            "tablerefuuid", "text", "timestamp", "uuid", "vector", "video"
          ]).describe("Type of the schema element"),
          description: z.string().optional().describe("Description of the schema element"),
          nullable: z.boolean().optional().default(false).describe("Whether the field can be null"),
          required: z.boolean().optional().default(false).describe("Whether the field is required"),
          access: z.enum(["public", "private", "internal"]).optional().default("public").describe("Access level for the field"),
          style: z.enum(["single", "list"]).optional().default("single").describe("Whether the field is a single value or a list"),
          default: z.string().optional().describe("Default value for the field"),
          config: z.record(z.any()).optional().describe("Additional configuration for specific field types"),
          validators: z.object({
            lower: z.boolean().optional(),
            max: z.number().optional(),
            maxLength: z.number().optional(),
            min: z.number().optional(),
            minLength: z.number().optional(),
            pattern: z.string().optional(),
            precision: z.number().optional(),
            scale: z.number().optional(),
            trim: z.boolean().optional()
          }).optional().describe("Validation rules for the field"),
          children: z.array(z.any()).optional().describe("Nested fields for object types"),
          tableref_id: z.string().optional().describe("ID of the referenced table (only valid when type is 'int')"),
          values: z.array(z.string()).optional().describe("Array of allowed values (only for enum type)")
        })).optional().describe(`Schema configuration for the table. For foreign key relationships, use type 'int' with tableref_id. Example:
        {
          "name": "contact_id",
          "type": "int",
          "description": "Reference to contact table",
          "nullable": false,
          "required": false,
          "access": "public",
          "style": "single",
          "default": "0",
          "tableref_id": "100"  // ID of the table to reference
        }`)
      },
      async ({ name, description, schema }) => {
        console.error(`[Tool] Executing add-table for table: ${name}`);
        try {
          // Step 1: Create the table
          const createTableResponse = await makeXanoRequest<{ id: string }>(
            `/workspace/${XANO_WORKSPACE}/table`, 
            'POST', 
            { name, description }
          );
          
          const tableId = createTableResponse.id;
          console.error(`[Tool] Table created with ID: ${tableId}`);
          
          // Step 2: If schema is provided, process and add it to the table
          if (schema && schema.length > 0) {
            try {
              // Process schema fields to handle relationships
              const processedSchema = schema.map(field => {
                // Validate relationship fields
                if (field.tableref_id && field.type !== "int") {
                  throw new Error(`Field "${field.name}" has tableref_id but type is not "int". Foreign key fields must be of type "int".`);
                }
                
                return field;
              });
              
              // Update the schema with processed fields
              await makeXanoRequest(
                `/workspace/${XANO_WORKSPACE}/table/${tableId}/schema`, 
                'PUT', 
                { schema: processedSchema }
              );
              console.error(`[Tool] Schema successfully added to table ID: ${tableId}`);
            } catch (schemaError) {
              console.error(`[Error] Failed to add schema: ${schemaError instanceof Error ? schemaError.message : String(schemaError)}`);
              return {
                content: [
                  {
                    type: "text",
                    text: `Table created with ID ${tableId}, but failed to add schema: ${schemaError instanceof Error ? schemaError.message : String(schemaError)}`
                  }
                ],
                isError: true
              };
            }
          }
          
          return {
            content: [
              {
                type: "text",
                text: `Successfully created table "${name}" with ID: ${tableId}${schema ? ' and added the specified schema.' : '.'}`
              }
            ]
          };
        } catch (error) {
          console.error(`[Error] Failed to create table: ${error instanceof Error ? error.message : String(error)}`);
          return {
            content: [
              {
                type: "text",
                text: `Error creating table: ${error instanceof Error ? error.message : String(error)}`
              }
            ],
            isError: true
          };
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a creation operation ('Add a new table'), implying it's a write/mutation tool, but doesn't mention permissions required, whether it's idempotent, what happens on duplicate names, or what the response contains. For a database mutation tool with zero annotation coverage, this is a significant gap in behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that states exactly what the tool does without unnecessary words. It's appropriately sized and front-loaded with the core functionality. Every word earns its place in this minimal but complete statement of purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a database table creation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what happens after table creation, what permissions are needed, whether there are rate limits, or what the typical response format would be. The description alone doesn't provide enough context for an agent to use this tool effectively in production scenarios.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with detailed documentation for all 3 parameters (name, description, schema). The description doesn't add any parameter information beyond what's already in the schema. According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add') and resource ('new table to the Xano database'), making the purpose immediately understandable. However, it doesn't differentiate this tool from sibling tools like 'edit-table-schema' or 'create-api-group', which could involve similar database operations. The description is specific but lacks sibling distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'edit-table-schema' for modifying existing tables or 'list-tables' for viewing tables. There's no mention of prerequisites, constraints, or typical use cases, leaving the agent without contextual usage information.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lowcodelocky2/xano-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server