Skip to main content
Glama

query_tool

Get answers from indexed documents using natural language queries. Search PDFs, YouTube videos, GitHub repos, and Discord exports with RAG-powered responses that include source citations.

Instructions

Query indexed documents and return an answer with citations.

Searches through all indexed documents (PDF, Discord, etc.) and uses RAG
to provide an answer based on retrieved context, with source citations.

Args:
    query: Natural language question to ask.
    document_id: Optional document ID to filter retrieval (from list_documents).
    page_min: Optional start of page range (inclusive). PDF only.
    page_max: Optional end of page range (inclusive). PDF only.
    tag: Optional tag to filter retrieval (from list_documents).
    document_type: Optional type to filter: "pdf", "youtube", "discord", "github", or "plaintext".
    file_path: Optional file path within a document (GitHub: e.g. src/ria/api/atr.c). Use list_documents to see files.
    response_style: Answer style: "thorough" (detailed) or "concise" (default: "thorough").
    ctx: MCP request context (injected by the server; unused).

Returns:
    Dictionary containing answer and sources (document_id, page).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesNatural language question to ask.
document_idNoOptional document ID to filter retrieval (from list_documents).
page_minNoOptional start of page range (inclusive). PDF only.
page_maxNoOptional end of page range (inclusive). PDF only.
tagNoOptional tag to filter retrieval (from list_documents).
document_typeNoOptional type to filter: 'pdf', 'youtube', 'discord', 'github', or 'plaintext'.
file_pathNoOptional file path within a document (GitHub: e.g. src/ria/api/atr.c). Use list_documents to see files.
response_styleNoAnswer style: 'thorough' (detailed) or 'concise'.thorough

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The implementation of the `query_tool`, which handles queries by running `query_index` in a separate thread.
    async def query_tool(
        query: Annotated[str, Field(description="Natural language question to ask.")],
        document_id: Annotated[
            str,
            Field(
                description="Optional document ID to filter retrieval (from list_documents)."
            ),
        ] = "",
        page_min: Annotated[
            int | None,
            Field(description="Optional start of page range (inclusive). PDF only."),
        ] = None,
        page_max: Annotated[
            int | None,
            Field(description="Optional end of page range (inclusive). PDF only."),
        ] = None,
        tag: Annotated[
            str,
            Field(description="Optional tag to filter retrieval (from list_documents)."),
        ] = "",
        document_type: Annotated[
            str,
            Field(
                description="Optional type to filter: 'pdf', 'youtube', 'discord', 'github', or 'plaintext'."
            ),
        ] = "",
        file_path: Annotated[
            str,
            Field(
                description="Optional file path within a document (GitHub: e.g. src/ria/api/atr.c). Use list_documents to see files."
            ),
        ] = "",
        response_style: Annotated[
            str, Field(description="Answer style: 'thorough' (detailed) or 'concise'.")
        ] = "thorough",
        ctx: Context | None = None,
    ) -> dict:
        """Query indexed documents and return an answer with citations.
    
        Searches through all indexed documents (PDF, Discord, etc.) and uses RAG
        to provide an answer based on retrieved context, with source citations.
    
        Args:
            query: Natural language question to ask.
            document_id: Optional document ID to filter retrieval (from list_documents).
            page_min: Optional start of page range (inclusive). PDF only.
            page_max: Optional end of page range (inclusive). PDF only.
            tag: Optional tag to filter retrieval (from list_documents).
            document_type: Optional type to filter: "pdf", "youtube", "discord", "github", or "plaintext".
            file_path: Optional file path within a document (GitHub: e.g. src/ria/api/atr.c). Use list_documents to see files.
            response_style: Answer style: "thorough" (detailed) or "concise" (default: "thorough").
            ctx: MCP request context (injected by the server; unused).
    
        Returns:
            Dictionary containing answer and sources (document_id, page).
    
        """
        style_input = (response_style or "").strip().lower()
        if style_input in ("thorough", "concise"):
            style = style_input
        else:
            style = config.get_response_style()
    
        def _run() -> dict:
            return query_index(
                user_query=query,
                document_id=document_id or None,
                page_min=page_min,
                page_max=page_max,
                tag=tag or None,
                document_type=document_type or None,
                file_path=file_path or None,
                response_style=style,
            )
    
        return await anyio.to_thread.run_sync(_run)
Behavior3/5

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

With no annotations provided, the description must carry the full disclosure burden. It successfully explains the RAG mechanism and citation behavior but omits safety-critical context (read-only nature, error handling when documents missing, rate limits) that annotations would typically cover.

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?

Well-structured with clear Args/Returns sections and front-loaded summary. The Args section largely mirrors schema properties but justifies its length by adding cross-references and usage examples not present in the structured schema. Slight verbosity in the Args list, but every parameter earns its documentation.

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

Completeness5/5

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

Given the complexity (8 parameters, multiple filter types, RAG architecture), the description comprehensively covers: the retrieval mechanism, all filter parameters with domain-specific notes (PDF page ranges, GitHub paths), response style options, and return structure (answer + sources). Complete for a sophisticated query tool.

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

Parameters4/5

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

Despite 100% schema coverage (baseline 3), the description adds substantial value: cross-references to list_documents for document_id/file_path, domain constraints ('PDF only' for page ranges), specific GitHub path examples, and enumerated style options. The only minor issue is documenting 'ctx' as an injected argument not present in the schema.

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 provides a specific verb ('Query') and resource ('indexed documents'), clearly distinguishing this RAG-based search tool from sibling add/remove/list operations. Opening sentence immediately establishes the retrieval-and-answer paradigm.

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

Usage Guidelines4/5

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

The description provides clear usage context by repeatedly referencing list_documents for obtaining valid document_id and file_path values, establishing a workflow dependency. However, it lacks explicit 'when not to use' guidance or contrast with the sibling list_documents_tool for browsing vs querying.

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/ndjordjevic/pinrag'

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