Skip to main content
Glama
andyWang1688

sql-query-mcp

get_table_sample

Fetch a small sample from database tables to discover schema structure and understand data organization for query planning.

Instructions

Fetch a small sample from a table for schema discovery.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
connection_idYes
table_nameYes
schemaNo
databaseNo
limitNo

Implementation Reference

  • The actual implementation of the get_table_sample tool, which builds the query, executes it, and formats the results.
    def get_table_sample(
        self,
        connection_id: str,
        table_name: str,
        schema: Optional[str] = None,
        database: Optional[str] = None,
        limit: Optional[int] = None,
    ) -> Dict[str, object]:
        row_limit = clamp_limit(
            limit, self._settings.default_limit, self._settings.max_limit
        )
        started = time.perf_counter()
        config = None
        try:
            config = self._registry.get_connection_config(connection_id)
            namespace = resolve_namespace(config, schema=schema, database=database)
            adapter = self._registry.get_adapter(config)
            query = adapter.build_sample_query(
                namespace.value, table_name, row_limit + 1
            )
            with self._registry.connection_from_config(config) as (conn, adapter):
                _apply_statement_timeout(
                    adapter, conn, self._settings.statement_timeout_ms
                )
                with conn.cursor() as cur:
                    cur.execute(query)
                    columns = adapter.column_names(cur.description)
                    rows = cur.fetchall()
    
                truncated = len(rows) > row_limit
                trimmed_rows = rows[:row_limit]
                duration_ms = _elapsed_ms(started)
                self._audit.log(
  • The wrapper function in the MCP app that invokes the executor's get_table_sample method.
    def get_table_sample(
        connection_id: str,
        table_name: str,
        schema: Optional[str] = None,
        database: Optional[str] = None,
        limit: Optional[int] = None,
    ) -> dict:
        """Fetch a small sample from a table for schema discovery."""
    
        return _run_tool(lambda: executor.get_table_sample(connection_id, table_name, schema, database, limit))
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions fetching a 'small sample' but doesn't specify default sample size, whether it's random or ordered, if it requires read permissions, or what happens with invalid inputs. For a tool with 5 parameters and no annotation coverage, this leaves significant behavioral gaps.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose. Every word earns its place with no redundancy or unnecessary elaboration, making it easy to parse quickly.

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?

For a tool with 5 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficient. It doesn't explain parameter usage, return format, error conditions, or behavioral constraints. The context demands more completeness given the complexity and lack of structured documentation.

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

Parameters2/5

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

Schema description coverage is 0%, so parameters are undocumented in the schema. The description mentions 'table' and implies 'schema discovery' but doesn't explain any of the 5 parameters (connection_id, table_name, schema, database, limit) or their relationships. It adds minimal semantic value beyond what's inferred from parameter names.

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 action ('fetch a small sample') and purpose ('for schema discovery'), specifying both verb and resource. It distinguishes from siblings like 'describe_table' (metadata) and 'run_select' (full queries), but doesn't explicitly name alternatives.

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

Usage Guidelines3/5

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

The description implies usage for schema discovery rather than data retrieval, suggesting when to use it. However, it doesn't provide explicit guidance on when to choose this over 'describe_table' for schema analysis or 'run_select' for data sampling, nor does it mention prerequisites like needing a valid connection.

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

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/andyWang1688/sql-query-mcp'

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