get_table_info
Retrieve detailed database table structure information, including field definitions, types, and comments, using either low-code system schema queries or traditional database metadata methods.
Instructions
获取指定数据库表的结构信息,包括字段定义、类型、注释等。支持两种查询方式:1) 低代码系统schema查询(通过da_logic_entity和da_entity_attribute表);2) 传统数据库元数据查询。优先使用低代码系统方式获取更详细的字段信息。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | No | 数据源类型:database(直连数据库)、api(通过API)、auto(自动选择) | auto |
| table_name | Yes | 要查询的表名 |
Implementation Reference
- sp_database_mcp/simple_server.py:282-294 (handler)Handler logic within call_tool that processes the get_table_info tool call, retrieves table data from MOCK_TABLES, formats it, and returns the response.if name == "get_table_info": table_name = arguments.get("table_name") if not table_name: return [TextContent(type="text", text="错误:缺少表名参数")] if table_name in MOCK_TABLES: table_info = MOCK_TABLES[table_name] output = format_table_info(table_info) return [TextContent(type="text", text=output)] else: available_tables = ", ".join(MOCK_TABLES.keys()) return [TextContent(type="text", text=f"未找到表 '{table_name}'。可用的表有: {available_tables}")]
- Input schema definition for the get_table_info tool, specifying the required 'table_name' parameter.inputSchema={ "type": "object", "properties": { "table_name": { "type": "string", "description": "要查询的表名,如:activity_node, scene_activity, da_asset_object" } }, "required": ["table_name"] }
- sp_database_mcp/simple_server.py:224-236 (registration)Registration of the get_table_info tool in the list_tools handler, including name, description, and schema.name="get_table_info", description="获取指定数据库表的结构信息,包括字段定义、类型、注释等", inputSchema={ "type": "object", "properties": { "table_name": { "type": "string", "description": "要查询的表名,如:activity_node, scene_activity, da_asset_object" } }, "required": ["table_name"] } ),
- Helper function to format the table information into a markdown table for the tool response.def format_table_info(table_info: Dict[str, Any]) -> str: """格式化表信息输出""" output = f"# {table_info['name']} 表结构信息\n\n" if table_info.get("comment"): output += f"**表说明**: {table_info['comment']}\n\n" output += "## 字段信息\n\n" output += "| 字段名 | 类型 | 可空 | 主键 | 说明 |\n" output += "|--------|------|------|------|------|\n" for column in table_info["columns"]: nullable = "是" if column.get("nullable", True) else "否" primary_key = "是" if column.get("is_primary_key", False) else "否" comment = column.get("comment", "-") output += f"| {column['name']} | {column['type']} | {nullable} | {primary_key} | {comment} |\n" return output