get_db_schema
Retrieve the complete database schema showing all tables and their structures for analysis and query planning.
Instructions
Get the schema for all tables in the database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"type": "object"
}
Implementation Reference
- src/utils.ts:33-40 (handler)Core handler logic for the get_db_schema tool: executes SQL query to fetch CREATE TABLE statements for all user tables from sqlite_master.export async function dbSchema(client: Client): Promise<string[]> { const result = await client.execute({ sql: "SELECT sql FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'", args: [], }); return result.rows.map((row) => row.sql as string); }
- src/index.ts:66-81 (registration)Registers the get_db_schema tool with FastMCP server, defining empty input schema (z.object({})), description, and thin execute wrapper that calls dbSchema and formats response.server.addTool({ name: "get_db_schema", description: "Get the schema for all tables in the database", parameters: z.object({}), execute: async () => { try { const schema = await dbSchema(db); return content(JSON.stringify({ schema }, null, 2)); } catch (error) { return content( `Error getting schema: ${error instanceof Error ? error.message : String(error)}`, true, ); } }, });
- src/index.ts:69-69 (schema)Input schema for get_db_schema tool: empty object (no parameters).parameters: z.object({}),
- src/utils.ts:134-142 (helper)Helper function to format tool responses as MCP content objects, used in get_db_schema execute.export function content( text: string, error = false, ): { content: TextContent[]; isError: boolean } { return { content: [{ type: "text", text }], isError: error, }; }