Skip to main content
Glama
wenb1n-dev

mysql_mcp_server

get_table_index

Retrieve table indexes in a MySQL database by specifying table names, enabling efficient multi-table queries for database optimization and analysis.

Instructions

根据表名搜索数据库中对应的表索引,支持多表查询

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes要搜索的表名

Implementation Reference

  • The run_tool method implements the core execution logic: splits table names from 'text' input, builds SQL query to select indexes from information_schema.STATISTICS, executes it using the ExecuteSQL tool, and returns results or error.
    async def run_tool(self, arguments: Dict[str, Any]) -> Sequence[TextContent]:
        """获取指定表的索引信息
    
        参数:
            text (str): 要查询的表名,多个表名以逗号分隔
    
        返回:
            list[TextContent]: 包含查询结果的TextContent列表
            - 返回表的索引名、索引字段、索引类型等信息
            - 结果按表名、索引名和索引顺序排序
            - 结果以CSV格式返回,包含列名和数据
        """
        try:
            if "text" not in arguments:
                raise ValueError("缺少查询语句")
    
            text = arguments["text"]
    
            config = get_db_config()
            execute_sql = ExecuteSQL()
    
            # 将输入的表名按逗号分割成列表
            table_names = [name.strip() for name in text.split(',')]
            # 构建IN条件
            table_condition = "','".join(table_names)
    
            sql = "SELECT TABLE_NAME, INDEX_NAME, COLUMN_NAME, SEQ_IN_INDEX, NON_UNIQUE, INDEX_TYPE "
            sql += f"FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = '{config['database']}' "
            sql += f"AND TABLE_NAME IN ('{table_condition}') ORDER BY TABLE_NAME, INDEX_NAME, SEQ_IN_INDEX;"
    
            return await execute_sql.run_tool({"query": sql})
    
        except Exception as e:
            return [TextContent(type="text", text=f"执行查询时出错: {str(e)}")]
  • Defines the tool's input schema: an object requiring a 'text' string parameter for the table name(s) to search.
    def get_tool_description(self) -> Tool:
        return Tool(
            name=self.name,
            description=self.description,
            inputSchema={
                "type": "object",
                "properties": {
                    "text": {
                        "type": "string",
                        "description": "要搜索的表名"
                    }
                },
                "required": ["text"]
            }
        )
  • BaseHandler.__init_subclass__ automatically registers any subclass (like GetTableIndex) to the ToolRegistry when the class is defined.
    def __init_subclass__(cls, **kwargs):
        """子类初始化时自动注册到工具注册表"""
        super().__init_subclass__(**kwargs)
        if cls.name:  # 只注册有名称的工具
            ToolRegistry.register(cls)
  • Imports GetTableIndex class (triggering automatic registration) and includes it in __all__ for easy access.
    from .execute_sql import ExecuteSQL
    from .get_chinese_initials import GetChineseInitials
    from .get_table_desc import GetTableDesc
    from .get_table_index import GetTableIndex
    from .get_table_lock import GetTableLock
    from .get_table_name import GetTableName
    from .get_db_health_running import GetDBHealthRunning
    from .get_db_health_index_usage import GetDBHealthIndexUsage
    from .use_prompt_queryTableData import UsePromptQueryTableData
    from .optimize_sql import OptimizeSql
    
    __all__ = [
        "ExecuteSQL",
        "GetChineseInitials",
        "GetTableDesc",
        "GetTableIndex",
        "GetTableLock",
        "GetTableName",
        "GetDBHealthRunning",
        "GetDBHealthIndexUsage",
        "UsePromptQueryTableData",
        "OptimizeSql"
    ]
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool searches for table indexes and supports multi-table queries, but lacks details on permissions, rate limits, error handling, or what '多表查询' entails (e.g., how inputs are processed). This is insufficient for a tool that interacts with a database, leaving behavioral traits unclear.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that conveys the core functionality without unnecessary details. It is front-loaded with the main purpose, though it could be slightly more structured to separate capabilities from constraints. Overall, it earns its place concisely.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of database operations, lack of annotations, and no output schema, the description is incomplete. It does not explain what the tool returns (e.g., index details, error formats), behavioral aspects like side effects, or how '多表查询' works. This leaves significant gaps for an AI agent to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the parameter 'text' documented as '要搜索的表名' (table name to search). The description adds minimal value beyond this, only implying that multiple table names might be supported ('多表查询'), but without specifying format or syntax. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '根据表名搜索数据库中对应的表索引,支持多表查询' (search for table indexes in a database based on table names, supporting multi-table queries). It specifies the verb '搜索' (search) and resource '表索引' (table indexes), though it doesn't explicitly differentiate from sibling tools like get_table_desc or get_table_name, which might retrieve different metadata.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It mentions '支持多表查询' (supports multi-table queries), which hints at a capability, but does not specify scenarios, prerequisites, or exclusions compared to siblings such as execute_sql or get_table_desc. This leaves the agent without clear usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/wenb1n-dev/mysql_mcp_server_pro'

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