get_table_info
Retrieve database table structure information including field definitions, types, and comments. Supports both low-code system schema queries and traditional database metadata queries for comprehensive table analysis.
Instructions
获取指定数据库表的结构信息,包括字段定义、类型、注释等。支持两种查询方式:1) 低代码系统schema查询(通过da_logic_entity和da_entity_attribute表);2) 传统数据库元数据查询。优先使用低代码系统方式获取更详细的字段信息。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | 要查询的表名 | |
| source | No | 数据源类型:database(直连数据库)、api(通过API)、auto(自动选择) | auto |
Implementation Reference
- sp_database_mcp/server.py:119-135 (registration)MCP tool registration for 'get_table_info' with input schema defining table_name (required) and optional source.Tool( name="get_table_info", description="获取指定数据库表的结构信息,包括字段定义、类型、注释等。支持两种查询方式:1) 低代码系统schema查询(通过da_logic_entity和da_entity_attribute表);2) 传统数据库元数据查询。优先使用低代码系统方式获取更详细的字段信息。", inputSchema={ "type": "object", "properties": { "table_name": {"type": "string", "description": "要查询的表名"}, "source": { "type": "string", "enum": ["database", "api", "auto"], "description": "数据源类型:database(直连数据库)、api(通过API)、auto(自动选择)", "default": "auto", }, }, "required": ["table_name"], }, ),
- sp_database_mcp/server.py:186-202 (handler)Primary MCP handler logic for get_table_info tool: extracts parameters, fetches table info via helper, formats and returns as TextContent.if name == "get_table_info": table_name = arguments.get("table_name") source = arguments.get("source", "auto") if not table_name: return [TextContent(type="text", text="错误:缺少表名参数")] table_info = await _get_table_info(table_name, source) if table_info: # 格式化输出 output = _format_table_info(table_info) return [TextContent(type="text", text=output)] else: return [ TextContent(type="text", text=f"未找到表 '{table_name}' 的信息") ]
- sp_database_mcp/server.py:268-283 (helper)Helper function dispatching get_table_info calls to DatabaseClient or APIClient based on source parameter, preferring database.async def _get_table_info(table_name: str, source: str) -> Optional[TableInfo]: """获取表信息的内部方法""" if source == "database" and db_client: return db_client.get_table_info(table_name) elif source == "api" and api_client: return await api_client.get_table_info(table_name) elif source == "auto": # 优先使用数据库直连,然后是 API if db_client: result = db_client.get_table_info(table_name) if result: return result if api_client: return await api_client.get_table_info(table_name) return None
- sp_database_mcp/database.py:34-46 (handler)Core handler in DatabaseClient for get_table_info: prioritizes low-code schema query, falls back to database metadata.def get_table_info(self, table_name: str) -> Optional[TableInfo]: """获取指定表的结构信息""" if not self.engine: return None # 首先尝试通过低代码系统的 schema 表获取信息 schema_info = self._get_table_info_from_schema(table_name) if schema_info: return schema_info # 如果低代码系统查询失败,回退到传统的数据库元数据查询 return self._get_table_info_from_metadata(table_name)
- sp_database_mcp/models.py:24-32 (schema)Pydantic schema/model for TableInfo, defining the structure of table information returned by the tool.class TableInfo(BaseModel): """数据库表信息""" name: str comment: Optional[str] = None columns: List[ColumnInfo] indexes: List[Dict[str, Any]] = [] foreign_keys: List[Dict[str, Any]] = []