Skip to main content
Glama

find_text_in_document

Search for specific text within a Word document, with options to match case or whole words, enabling precise text location and analysis.

Instructions

Find occurrences of specific text in a Word document.

Input Schema

NameRequiredDescriptionDefault
filenameYes
match_caseNo
text_to_findYes
whole_wordNo

Input Schema (JSON Schema)

{ "properties": { "filename": { "title": "Filename", "type": "string" }, "match_case": { "default": true, "title": "Match Case", "type": "boolean" }, "text_to_find": { "title": "Text To Find", "type": "string" }, "whole_word": { "default": false, "title": "Whole Word", "type": "boolean" } }, "required": [ "filename", "text_to_find" ], "type": "object" }

Implementation Reference

  • MCP tool handler function for 'find_text_in_document', registered via @mcp.tool() decorator. Delegates execution to the core implementation in extended_document_tools.
    def find_text_in_document(filename: str, text_to_find: str, match_case: bool = True, whole_word: bool = False): """Find occurrences of specific text in a Word document.""" return extended_document_tools.find_text_in_document( filename, text_to_find, match_case, whole_word )
  • Core helper function implementing the text search logic. Performs validation, calls the low-level find_text utility, and returns JSON-formatted results.
    async def find_text_in_document(filename: str, text_to_find: str, match_case: bool = True, whole_word: bool = False) -> str: """Find occurrences of specific text in a Word document. Args: filename: Path to the Word document text_to_find: Text to search for in the document match_case: Whether to match case (True) or ignore case (False) whole_word: Whether to match whole words only (True) or substrings (False) """ filename = ensure_docx_extension(filename) if not os.path.exists(filename): return f"Document {filename} does not exist" if not text_to_find: return "Search text cannot be empty" try: result = find_text(filename, text_to_find, match_case, whole_word) return json.dumps(result, indent=2) except Exception as e: return f"Failed to search for text: {str(e)}"

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/GongRzhe/Office-Word-MCP-Server'

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