list_all_tables
Retrieve a comprehensive list of all database tables using SP Database MCP Server. Specify data source (database, API, or auto) to view schema information for efficient system querying.
Instructions
列出所有数据库表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | No | 数据源类型 | auto |
Implementation Reference
- sp_database_mcp/server.py:153-167 (registration)Registration of the list_all_tables tool with input schema definition.Tool( name="list_all_tables", description="列出所有数据库表", inputSchema={ "type": "object", "properties": { "source": { "type": "string", "enum": ["database", "api", "auto"], "description": "数据源类型", "default": "auto", } }, }, ),
- sp_database_mcp/server.py:224-235 (handler)Specific handler branch in @server.call_tool() that extracts parameters, calls _list_all_tables, and formats the list of tables as markdown output.elif name == "list_all_tables": source = arguments.get("source", "auto") tables = await _list_all_tables(source) if tables: output = f"数据库中共有 {len(tables)} 个表:\n\n" for table_name in sorted(tables): output += f"- {table_name}\n" return [TextContent(type="text", text=output)] else: return [TextContent(type="text", text="未找到任何表")]
- sp_database_mcp/server.py:304-319 (handler)Core internal handler function that routes the request to the appropriate data source client (database or API) based on the 'source' parameter.async def _list_all_tables(source: str) -> List[str]: """列出所有表的内部方法""" if source == "database" and db_client: return db_client.get_all_tables() elif source == "api" and api_client: return await api_client.get_all_tables() elif source == "auto": # 优先使用数据库直连 if db_client: result = db_client.get_all_tables() if result: return result if api_client: return await api_client.get_all_tables() return []
- sp_database_mcp/database.py:197-208 (helper)DatabaseClient.get_all_tables() method: Uses SQLAlchemy MetaData.reflect() to introspect and return all table names from the database.def get_all_tables(self) -> List[str]: """获取所有表名""" if not self.engine: return [] try: metadata = MetaData() metadata.reflect(bind=self.engine) return list(metadata.tables.keys()) except SQLAlchemyError as e: print(f"Error getting table list: {e}") return []