Skip to main content
Glama

search_document

Find specific content within documents using search queries to locate relevant information quickly.

Instructions

Search for specific content within a document.

Args:
    doc_id: Document identifier
    query: Search term or phrase

Returns:
    Formatted search results with context

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYes
queryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler implementation of search_document in DocumentNavigator class. Performs recursive traversal of document nodes, searches for query matches in content, associates with nearest heading for context, formats top 5 results.
    def search_document(self, doc_id: str, query: str) -> str:
        """Search document and return formatted results."""
        document = self.get_document(doc_id)
        if not document:
            return f"Document '{doc_id}' not found"
    
        # Perform search using document's search functionality
        results = []
        query_lower = query.lower()
    
        def search_node(node: DocumentNode) -> None:
            if query_lower in node.content.lower():
                # Find nearest heading as context
                parent = node.parent
                while parent and parent.type != "heading":
                    parent = parent.parent
    
                section_title = parent.title if parent else "Document Root"
    
                from .models import SearchResult
    
                results.append(
                    SearchResult(
                        node_id=node.id,
                        section=section_title,
                        section_id=parent.id if parent else "root",
                        content=node.content,
                        type=node.type,
                        line_number=node.attributes.get("line_number"),
                    )
                )
    
            for child in node.children:
                search_node(child)
    
        if document.root:
            search_node(document.root)
    
        if not results:
            return f"No results found for '{query}'"
    
        output = f"Found {len(results)} results for '{query}':\n\n"
        for i, result in enumerate(results[:5], 1):  # Limit to first 5 results
            output += f"{i}. In section '{result.section}' (#{result.section_id}):\n"
            output += f"   {result.content[:100]}...\n\n"
    
        return output
  • server.py:85-96 (registration)
    MCP tool registration for 'search_document'. Thin wrapper that delegates to the navigator's search_document method. Input schema defined by function signature and docstring.
    @mcp.tool()
    def search_document(doc_id: str, query: str) -> str:
        """Search for specific content within a document.
    
        Args:
            doc_id: Document identifier
            query: Search term or phrase
    
        Returns:
            Formatted search results with context
        """
        return navigator.search_document(doc_id, query)
Behavior2/5

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

With no annotations provided, the description carries full burden but provides minimal behavioral information. It mentions 'Formatted search results with context' which gives some output expectation, but doesn't disclose important behavioral traits like whether this is a read-only operation, performance characteristics, authentication needs, rate limits, or what happens with invalid inputs. The description doesn't contradict annotations (none exist).

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 appropriately sized and well-structured with clear sections (Args, Returns). The purpose is stated upfront, and each section adds value. However, the 'Args' and 'Returns' headings are somewhat redundant since the schema already defines parameters and there's an output schema, making the structure slightly less efficient than it could be.

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

Completeness3/5

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

Given 2 parameters with 0% schema coverage but an output schema exists, the description provides basic parameter semantics and output expectations. However, for a search tool with no annotations, it should ideally explain more about search behavior (case sensitivity, partial matching, performance implications) and relationship to sibling tools. The existence of an output schema reduces the need to detail return values, but behavioral context remains sparse.

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 description coverage is 0%, but the description adds basic semantic meaning for both parameters: 'doc_id: Document identifier' and 'query: Search term or phrase'. This compensates somewhat for the lack of schema descriptions, though it doesn't provide format details, constraints, or examples. With 2 parameters and no schema descriptions, this provides baseline compensation.

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 with 'Search for specific content within a document' - a specific verb ('Search') and resource ('content within a document'). It distinguishes from siblings like 'list_documents' (which lists documents) and 'read_section' (which reads a specific section), but doesn't explicitly differentiate from all siblings like 'navigate_section' which might also involve document navigation.

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 is provided. The description doesn't mention when search is appropriate versus using 'read_section' for direct reading, 'navigate_section' for structural navigation, or 'list_documents' for finding documents. There's no context about prerequisites or limitations.

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/shenyimings/DocNav-MCP'

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