Skip to main content
Glama
JJVvV

SP Database MCP Server

by JJVvV

get_table_documentation

Retrieve detailed documentation for database tables to understand structure, columns, and relationships for development or analysis purposes.

Instructions

获取表的详细文档说明

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes表名

Implementation Reference

  • Registration of the 'get_table_documentation' tool including its description and input schema.
    Tool(
        name="get_table_documentation",
        description="获取表的详细文档说明",
        inputSchema={
            "type": "object",
            "properties": {"table_name": {"type": "string", "description": "表名"}},
            "required": ["table_name"],
        },
    ),
  • Main handler logic for the 'get_table_documentation' tool: validates input, fetches table info and documentation via API client, 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)]
  • Helper function in APIClient that performs the HTTP request to retrieve table documentation from the backend API.
    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
  • Helper function that formats the complete table documentation by combining table structure info and additional documentation.
    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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JJVvV/sp-enterprise-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server