get_table_documentation
Retrieve detailed documentation for a specific database table, enabling AI assistants and users to access schema and metadata information efficiently on the SP Database MCP Server.
Instructions
获取表的详细文档说明
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | 表名 |
Implementation Reference
- sp_database_mcp/server.py:168-176 (registration)Registration of the 'get_table_documentation' tool in MCP server, including name, description, and input schema.Tool( name="get_table_documentation", description="获取表的详细文档说明", inputSchema={ "type": "object", "properties": {"table_name": {"type": "string", "description": "表名"}}, "required": ["table_name"], }, ),
- sp_database_mcp/server.py:236-259 (handler)Server-side tool handler dispatches to get table info and documentation, then formats the output.elif name == "get_table_documentation": table_name = arguments.get("table_name") if not table_name: return [TextContent(type="text", text="错误:缺少表名参数")] # 首先尝试获取表信息 table_info = await _get_table_info(table_name, "auto") if not table_info: return [ TextContent(type="text", text=f"未找到表 '{table_name}' 的信息") ] # 如果有 API 客户端,尝试获取文档 documentation = "" if api_client: try: documentation = await api_client.get_table_documentation(table_name) except Exception as e: print(f"Error getting documentation: {e}") # 生成完整的文档 output = _format_table_documentation(table_info, documentation) return [TextContent(type="text", text=output)]
- sp_database_mcp/api_client.py:251-270 (handler)Core handler implementation in APIClient: fetches table documentation via HTTP API call.async def get_table_documentation(self, table_name: str) -> Optional[str]: """获取表的文档说明""" try: async with httpx.AsyncClient() as client: response = await client.get( f"{self.base_url}/api/database/tables/{table_name}/docs", headers=self.headers, timeout=30.0, ) if response.status_code == 200: data = response.json() return data.get("documentation", "") else: return None except httpx.RequestError as e: print(f"API request error: {e}") return None
- sp_database_mcp/server.py:354-368 (helper)Helper function to format the complete table documentation combining table info and API docs.def _format_table_documentation( table_info: TableInfo, documentation: Optional[str] = None ) -> str: """格式化表文档""" output = f"# {table_info.name} 表文档\n\n" if table_info.comment: output += f"## 表说明\n\n{table_info.comment}\n\n" if documentation: output += f"## 详细文档\n\n{documentation}\n\n" output += _format_table_info(table_info) return output