get-table-schema
Retrieve and visualize the schema of a specific table from a Xano database. Choose between markdown for readable documentation or json for detailed schema representation.
Instructions
Browse the schema of a table
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output format: 'markdown' for readable documentation or 'json' for complete schema | markdown |
| table_id | Yes | ID of the table to get schema from |
Implementation Reference
- src/index.ts:187-251 (handler)Main execution logic for the get-table-schema tool. Fetches the schema from the Xano API using makeXanoRequest, then formats it as either 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 }; } } );
- src/index.ts:183-186 (schema)Zod input schema defining parameters for the tool: table_id (required string) and format (optional enum markdown/json, defaults to 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-252 (registration)Registration of the get-table-schema tool using server.tool(), including 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 }; } } );