Skip to main content
Glama

get-table-schema

Retrieve the schema of a Xano database table to understand its structure and fields, available in markdown or JSON format.

Instructions

Browse the schema of a table

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_idYesID of the table to get schema from
formatNoOutput format: 'markdown' for readable documentation or 'json' for complete schemamarkdown

Implementation Reference

  • The handler function for the get-table-schema tool. It fetches the schema from Xano API using makeXanoRequest, then formats it as JSON or Markdown based on the format parameter, and returns structured content.
    async ({ table_id, format }) => {
      console.error(`[Tool] Executing get-table-schema for table ID: ${table_id} with format: ${format}`);
      try {
        const schema = await makeXanoRequest(`/workspace/${XANO_WORKSPACE}/table/${table_id}/schema`);
        
        if (format === "json") {
          // Return the complete JSON schema
          return {
            content: [
              {
                type: "text",
                text: `# Table Schema (Full JSON)\n\n\`\`\`json\n${JSON.stringify(schema, null, 2)}\n\`\`\``
              }
            ]
          };
        } else {
          // Format schema into readable structure
          const formattedContent = `# Schema for Table ID: ${table_id}\n\n` +
            (Array.isArray(schema) ? 
              schema.map(field => {
                let content = `## ${field.name} (${field.type})\n`;
                content += `**Required**: ${field.required ? 'Yes' : 'No'}\n`;
                content += `**Nullable**: ${field.nullable ? 'Yes' : 'No'}\n`;
                content += `**Access**: ${field.access || 'public'}\n`;
                content += `**Style**: ${field.style || 'single'}\n`;
                if (field.description) content += `**Description**: ${field.description}\n`;
                if (field.default !== undefined) content += `**Default**: ${field.default}\n`;
                if (field.config && Object.keys(field.config).length > 0) {
                  content += `**Config**:\n\`\`\`json\n${JSON.stringify(field.config, null, 2)}\n\`\`\`\n`;
                }
                if (field.validators && Object.keys(field.validators).length > 0) {
                  content += `**Validators**:\n\`\`\`json\n${JSON.stringify(field.validators, null, 2)}\n\`\`\`\n`;
                }
                if (field.children && field.children.length > 0) {
                  content += `**Children**:\n\`\`\`json\n${JSON.stringify(field.children, null, 2)}\n\`\`\`\n`;
                }
                return content;
              }).join('\n\n') : 
              `Error: Unexpected schema format: ${JSON.stringify(schema)}`
            );
    
          console.error(`[Tool] Successfully retrieved schema for table ID: ${table_id}`);
          return {
            content: [
              {
                type: "text",
                text: formattedContent
              }
            ]
          };
        }
      } catch (error) {
        console.error(`[Error] Failed to get table schema: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [
            {
              type: "text",
              text: `Error getting table schema: ${error instanceof Error ? error.message : String(error)}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining input parameters: table_id (string) and format (enum markdown/json, default markdown).
    {
      table_id: z.string().describe("ID of the table to get schema from"),
      format: z.enum(["markdown", "json"]).default("markdown").describe("Output format: 'markdown' for readable documentation or 'json' for complete schema")
    },
  • src/index.ts:180-251 (registration)
    The server.tool call that registers the get-table-schema tool, including its name, description, input schema, and handler function.
    server.tool(
      "get-table-schema",
      "Browse the schema of a table",
      {
        table_id: z.string().describe("ID of the table to get schema from"),
        format: z.enum(["markdown", "json"]).default("markdown").describe("Output format: 'markdown' for readable documentation or 'json' for complete schema")
      },
      async ({ table_id, format }) => {
        console.error(`[Tool] Executing get-table-schema for table ID: ${table_id} with format: ${format}`);
        try {
          const schema = await makeXanoRequest(`/workspace/${XANO_WORKSPACE}/table/${table_id}/schema`);
          
          if (format === "json") {
            // Return the complete JSON schema
            return {
              content: [
                {
                  type: "text",
                  text: `# Table Schema (Full JSON)\n\n\`\`\`json\n${JSON.stringify(schema, null, 2)}\n\`\`\``
                }
              ]
            };
          } else {
            // Format schema into readable structure
            const formattedContent = `# Schema for Table ID: ${table_id}\n\n` +
              (Array.isArray(schema) ? 
                schema.map(field => {
                  let content = `## ${field.name} (${field.type})\n`;
                  content += `**Required**: ${field.required ? 'Yes' : 'No'}\n`;
                  content += `**Nullable**: ${field.nullable ? 'Yes' : 'No'}\n`;
                  content += `**Access**: ${field.access || 'public'}\n`;
                  content += `**Style**: ${field.style || 'single'}\n`;
                  if (field.description) content += `**Description**: ${field.description}\n`;
                  if (field.default !== undefined) content += `**Default**: ${field.default}\n`;
                  if (field.config && Object.keys(field.config).length > 0) {
                    content += `**Config**:\n\`\`\`json\n${JSON.stringify(field.config, null, 2)}\n\`\`\`\n`;
                  }
                  if (field.validators && Object.keys(field.validators).length > 0) {
                    content += `**Validators**:\n\`\`\`json\n${JSON.stringify(field.validators, null, 2)}\n\`\`\`\n`;
                  }
                  if (field.children && field.children.length > 0) {
                    content += `**Children**:\n\`\`\`json\n${JSON.stringify(field.children, null, 2)}\n\`\`\`\n`;
                  }
                  return content;
                }).join('\n\n') : 
                `Error: Unexpected schema format: ${JSON.stringify(schema)}`
              );
    
            console.error(`[Tool] Successfully retrieved schema for table ID: ${table_id}`);
            return {
              content: [
                {
                  type: "text",
                  text: formattedContent
                }
              ]
            };
          }
        } catch (error) {
          console.error(`[Error] Failed to get table schema: ${error instanceof Error ? error.message : String(error)}`);
          return {
            content: [
              {
                type: "text",
                text: `Error getting table schema: ${error instanceof Error ? error.message : String(error)}`
              }
            ],
            isError: true
          };
        }
      }
    );

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