Skip to main content
Glama

find_in_doc

Read-only

Search a Google Doc for literal or regex text and return match locations as document character offsets, ready for applying styles to specific ranges.

Instructions

Search a Google Doc's text and return match locations as document character offsets.

Matches feed directly into style_doc_range's ranges — e.g. to link up bare URLs already sitting in a doc: find_in_doc(doc_id, query=r'https?://[^\s<>"]+(?<![.,;:!?)])', regex=True), then style_doc_range with link_url per match. The trailing negative lookbehind keeps a URL followed by sentence punctuation (or an unmatched closing paren) from swallowing it into the link.

Args: doc_id: The Google Doc file ID. query: Text to search for. Interpreted literally by default; pass regex=True to treat it as a Python regular expression. regex: Whether query is a regular expression (default False). case_sensitive: Whether the search is case-sensitive (default False). max_results: Maximum number of matches to return (default 50). local_path: Optional local filesystem path (file or directory) to write the result to instead of returning it inline. Bypasses the response-size cap. A path ending in '/' is a directory, created if missing. A file in place of a parent directory, or at a path ending in '/', raises ValueError; an existing file at a plain file path is replaced. Same caveat as download_file/download_folder: this path is resolved on the server's filesystem, not the caller's.

Returns: List of matches, each with start_index/end_index (document offsets usable directly as a style_doc_range range), matched_text, and context (the containing paragraph's full text). Searches paragraph text in the document body, including table cells; headers, footers, and footnotes are not searched. A zero-length regex match (e.g. "x*" with no "x" present) is skipped. Returns {"error": ...} if query is an invalid regex, or if the Docs API call itself fails (e.g. doc_id doesn't exist). max_results bounds match count, not response size — matched context can still be large. Raises ValueError if the response exceeds a safety cap (see MAX_TOOL_RESPONSE_CHARS in docs/configuration.md for the configured default) and local_path is not set — lower max_results, or pass local_path. If local_path is set, returns {local_path, doc_id, query, match_count, bytes_written} instead.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "doc_id": "<doc_id>",
      "query": "<query>"
    },
    "name": "find_in_doc"
  }
}

Input Schema

NameRequiredDescriptionDefault
queryYes
regexNo
doc_idYes
local_pathNo
max_resultsNo
case_sensitiveNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.7/5.0
Behavior5/5

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

Adds substantial behavior beyond readOnlyHint=true: it discloses search scope (body plus table cells; headers, footers, footnotes excluded), zero-length regex match skipping, error shapes for invalid regex or failed API calls, and that max_results bounds match count rather than response size. It also flags the response-size safety cap and the critical caveat that local_path resolves on the server's filesystem — exactly the kind of context annotations cannot carry.

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 front-loaded with purpose then a worked example then Args/Returns, and nearly every sentence carries information. The URL regex with its lookbehind rationale is verbose for a general-purpose description and could be trimmed without losing selection guidance.

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?

For a six-parameter read tool with rich failure modes, the description covers scope, output fields, both inline and local_path return shapes, and error conditions. Nothing needed to invoke it correctly appears missing.

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

Parameters5/5

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

Schema description coverage is 0%, so the description carries the full burden, and it does: it documents all six parameters including defaults (regex False, case_sensitive False, max_results 50) and full local_path semantics (directory vs file, ValueError on bad shapes, existing file replaced). It explains the interaction between max_results, response size, and local_path, which the bare schema cannot.

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?

Opens with a specific verb+resource ('Search a Google Doc's text') and immediately states the output form (match locations as document character offsets), which distinguishes it from read-style siblings like get_doc_as_markdown or get_doc_structure.

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?

Gives a concrete when-to-use scenario and an explicit chaining target (style_doc_range with link_url per match), including the exact call shape. It stops short of stating when-not-to or how it relates to sibling searches like find_in_spreadsheet or search_files, so it falls just short of a 5.

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

Deploy Server

Other Tools