Skip to main content
Glama
andyWang1688

sql-query-mcp

get_query

Retrieve the status and paginated results of an asynchronous database query.

Instructions

Get asynchronous query status and paginated results when complete.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
query_idYes
offsetNo
limitNo

Implementation Reference

  • Core implementation of get_query: retrieves an async query job, validates offset/limit, formats results with pagination, and audits the operation.
    def get_query(
        self, query_id: str, offset: int = 0, limit: Optional[int] = None
    ) -> Dict[str, object]:
        started = time.perf_counter()
        try:
            if offset < 0:
                raise QueryExecutionError("offset 必须大于等于 0。")
            if limit is not None and int(limit) < 0:
                raise QueryExecutionError("limit 必须大于等于 0。")
            with self._lock:
                job = self._get_job_locked(query_id)
                result = self._format_job_locked(job, offset, limit)
                sql_summary = job.sql_summary
                engine = job.engine
                status = job.status
            audit_connection_id = result.get("connection_id")
            self._audit.log(
                tool="get_query",
                connection_id=(
                    audit_connection_id if isinstance(audit_connection_id, str) else None
                ),
                success=True,
                duration_ms=_elapsed_ms(started),
                sql_summary=sql_summary,
                extra={"engine": engine, "status": status},
            )
            return result
        except Exception as exc:
            sanitized = sanitize_error_message(str(exc))
            self._audit.log(
                tool="get_query",
                connection_id=None,
                success=False,
                duration_ms=_elapsed_ms(started),
                error=sanitized,
                extra={"query_id": query_id},
            )
            if isinstance(exc, QueryExecutionError):
                raise
            raise QueryExecutionError(sanitized) from exc
  • Helper _format_job_locked: formats a query job result dict, applying offset/limit pagination for succeeded queries.
    def _format_job_locked(
        self, job: _AsyncQueryJob, offset: int, limit: Optional[int]
    ) -> Dict[str, object]:
        result: Dict[str, object] = {
            "query_id": job.query_id,
            "connection_id": job.connection_id,
            "engine": job.engine,
            "status": job.status,
        }
        if job.status == FAILED:
            result["error"] = job.error
        if job.status != SUCCEEDED:
            return result
    
        page_limit = len(job.rows) if limit is None else int(limit)
        rows = job.rows[offset : offset + page_limit]
        result.update(
            {
                "rows": rows,
                "columns": job.columns,
                "row_count": job.row_count,
                "truncated": job.truncated,
                "duration_ms": job.duration_ms,
                "applied_limit": job.applied_limit,
                "offset": offset,
                "returned_row_count": len(rows),
            }
        )
        return result
  • Helper _get_job_locked: retrieves a job by query_id from the internal dict, raising QueryExecutionError if not found.
    def _get_job_locked(self, query_id: str) -> _AsyncQueryJob:
        try:
            return self._jobs[query_id]
        except KeyError as exc:
            raise QueryExecutionError(f"未知 query_id: {query_id}") from exc
  • Registration of the get_query MCP tool: decorated with @mcp.tool(), delegates to async_queries.get_query(query_id, offset, limit).
    @mcp.tool()
    def get_query(query_id: str, offset: int = 0, limit: Optional[int] = None) -> dict:
        """Get asynchronous query status and paginated results when complete."""
    
        return _run_tool(lambda: async_queries.get_query(query_id, offset, limit))
  • Schema/parameters of get_query: query_id (str), offset (int, default 0), limit (Optional[int]). Returns Dict[str, object] with query status and paginated rows.
    def get_query(
        self, query_id: str, offset: int = 0, limit: Optional[int] = None
    ) -> Dict[str, object]:
Behavior2/5

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

No annotations provided, so description must cover behavioral traits. It only states the tool gets status and results, but does not mention if it's read-only, any side effects, rate limits, or authentication needs. The 'asynchronous' hint is minimal.

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?

Single sentence, 10 words. Front-loaded and efficient with no waste, earning its place.

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?

No output schema and no description of return structure (e.g., columns, rows). Incomplete for a results-fetching tool with 3 parameters; should explain response format or behavior.

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?

Schema coverage is 0%, so description must add meaning. It mentions 'paginated results' hinting offset/limit are for pagination, adding value beyond bare schema. However, no detailed parameter descriptions.

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

Purpose5/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: get asynchronous query status and paginated results when complete. It uses specific verbs and resources, distinguishing from siblings like start_query and cancel_query.

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?

No guidance on when to use this tool versus alternatives. The description mentions 'when complete' but doesn't specify prerequisites or exclusions, leaving the agent to infer 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

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