list-tables
Retrieve a list of all tables within a specified database and schema using the Superset MCP Server. Simplify database exploration by accessing structured table information for efficient querying and analysis.
Instructions
获取指定数据库的表列表
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| databaseId | Yes | 数据库ID | |
| schema | No | Schema名称 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"databaseId": {
"description": "数据库ID",
"type": "number"
},
"schema": {
"description": "Schema名称",
"type": "string"
}
},
"required": [
"databaseId"
],
"type": "object"
}
Implementation Reference
- src/index.ts:343-417 (registration)Registration of the "list-tables" MCP tool, including input schema (databaseId: number, schema?: string) and the complete inline handler function that fetches tables from cache for the given database and optional schema, formats and returns them as text.server.tool( "list-tables", "获取指定数据库的表列表", { databaseId: z.number().describe("数据库ID"), schema: z.string().describe("Schema名称").optional(), }, async ({ databaseId, schema}) => { try { // 如果缓存为空,初始化缓存 if (databasesCache.length === 0) { initializeCache(); return { content: [ { type: "text", text: "初始化缓存中...", }, ], }; } const database = databasesCache.find(db => db.id === databaseId); if (!database) { return { content: [ { type: "text", text: `找不到ID为 ${databaseId} 的数据库`, }, ], }; } // 获取表列表 let tables = tablesCache.get(databaseId); // 如果提供了schema,则过滤表 if (tables && schema) { tables = tables.filter(table => table.schema === schema); } if (!tables || tables.length === 0) { // 如果缓存中没有,尝试重新获取 return { content: [ { type: "text", text: `数据库 ${database.database_name} 中没有找到表`, }, ], }; } const tablesList = tables.map(table => `Schema: ${table.schema}, 表名: ${table.name}`).join("\n"); return { content: [ { type: "text", text: `数据库 ${database.database_name} 的表列表:\n\n${tablesList}`, }, ], }; } catch (error) { console.error("获取表列表失败:", error); return { content: [ { type: "text", text: `获取表列表失败: ${(error as Error).message}`, }, ], }; } } );
- src/index.ts:350-416 (handler)The handler function for the list-tables tool. It initializes cache if needed, finds the database, retrieves tables from cache, filters by schema if provided, and returns a formatted text list of tables.async ({ databaseId, schema}) => { try { // 如果缓存为空,初始化缓存 if (databasesCache.length === 0) { initializeCache(); return { content: [ { type: "text", text: "初始化缓存中...", }, ], }; } const database = databasesCache.find(db => db.id === databaseId); if (!database) { return { content: [ { type: "text", text: `找不到ID为 ${databaseId} 的数据库`, }, ], }; } // 获取表列表 let tables = tablesCache.get(databaseId); // 如果提供了schema,则过滤表 if (tables && schema) { tables = tables.filter(table => table.schema === schema); } if (!tables || tables.length === 0) { // 如果缓存中没有,尝试重新获取 return { content: [ { type: "text", text: `数据库 ${database.database_name} 中没有找到表`, }, ], }; } const tablesList = tables.map(table => `Schema: ${table.schema}, 表名: ${table.name}`).join("\n"); return { content: [ { type: "text", text: `数据库 ${database.database_name} 的表列表:\n\n${tablesList}`, }, ], }; } catch (error) { console.error("获取表列表失败:", error); return { content: [ { type: "text", text: `获取表列表失败: ${(error as Error).message}`, }, ], }; } }
- src/index.ts:346-349 (schema)Input schema for list-tables tool using Zod: requires databaseId (number), optional schema (string).{ databaseId: z.number().describe("数据库ID"), schema: z.string().describe("Schema名称").optional(), },