get_database_schema
Retrieve Oracle database schema details, including table lists or specific column information for query planning and data analysis.
Instructions
Get database schema information. If tableName is provided, returns column details for that table. Otherwise, returns a list of all accessible tables.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| tableName | No | Optional table name to get column information for |
Implementation Reference
- src/tools/getSchema.ts:15-36 (handler)Main handler function that executes the core logic for the 'get_database_schema' tool: input validation, schema retrieval, error handling, and response formatting.export async function getDatabaseSchema(input: GetSchemaInput = {}) { try { const validated = GetSchemaSchema.parse(input); logger.info('Getting database schema via MCP tool', { tableName: validated.tableName || 'all tables', }); const result = await getSchema(validated.tableName); return { success: true, data: result, }; } catch (err: any) { logger.error('Get schema tool failed', { error: err.message }); return { success: false, error: err.message || 'Unknown error occurred', }; }
- src/tools/getSchema.ts:6-8 (schema)Zod input schema for validating parameters of the 'get_database_schema' tool (optional tableName).export const GetSchemaSchema = z.object({ tableName: z.string().optional(), });
- src/server.ts:61-74 (registration)Tool registration in MCP server's tools list, defining name, description, and input schema.{ name: 'get_database_schema', description: 'Get database schema information. If tableName is provided, returns column details for that table. Otherwise, returns a list of all accessible tables.', inputSchema: { type: 'object', properties: { tableName: { type: 'string', description: 'Optional table name to get column information for', }, }, }, },
- src/server.ts:102-113 (handler)MCP server dispatch handler for 'get_database_schema' tool calls: validates arguments, invokes the tool handler, and formats MCP response.} else if (name === 'get_database_schema') { const validated = GetSchemaSchema.parse(args || {}); const result = await getDatabaseSchema(validated); return { content: [ { type: 'text' as const, text: JSON.stringify(result, null, 2), }, ], };
- src/database/queryExecutor.ts:94-121 (helper)Supporting database function that generates and executes SQL queries for table lists or column schemas, used by the main tool handler.export async function getSchema(tableName?: string): Promise<any> { let query: string; if (tableName) { // Get columns for specific table query = ` SELECT column_name, data_type, data_length, nullable FROM user_tab_columns WHERE table_name = UPPER('${tableName}') ORDER BY column_id `; } else { // Get all accessible tables query = ` SELECT table_name, tablespace_name FROM user_tables ORDER BY table_name `; } return executeQuery(query, { maxRows: 1000 }); }