search_text
Find specific text strings in Markdown files and identify their structural locations using semantic search functionality.
Instructions
Performs a semantic search for text strings and returns their structural paths.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| query | Yes | String to search for |
Implementation Reference
- Core handler function that recursively searches document elements for the query string and returns matching paths, types, and previews.def search_text(self, query: str) -> List[Dict[str, Any]]: """Search text across all elements""" query = query.lower() results = [] def walk(elements): for el in elements: if query in el.content.lower(): results.append({ "path": el.path, "type": el.type, "preview": el.content[:100] }) walk(el.children) walk(self.elements) return results
- Tool registration including input schema (file_path, query) and output schema (results array).name="search_text", title="Search Text in Document", description="Performs a semantic search for text strings and returns their structural paths.", inputSchema={ "type": "object", "properties": { "file_path": { "type": "string", "examples": ["./document.md", "/path/to/file.md"] }, "query": { "type": "string", "description": "String to search for", "examples": ["TODO", "urgent", "deadline"] } }, "required": ["file_path", "query"], "additionalProperties": False }, outputSchema={ "type": "object", "properties": { "results": { "type": "array", "description": "List of matching elements with their paths" } } }
- src/markdown_editor/server.py:550-552 (registration)Dispatch handler in MCP server that calls the search_in_document wrapper with file_path and query.elif name == "search_text": res = await search_in_document(file_path, arguments["query"]) return {"content": [TextContent(type="text", text=f"Found {len(res)} matches")], "structuredContent": {"results": res}, "isError": False}
- Wrapper method in EditTool class that loads the Document instance and delegates to its search_text method.async def search(self, file_path: str, query: str) -> List[Dict[str, Any]]: doc = self.get_doc(file_path) return doc.search_text(query)
- Exported async function imported by server.py, calls the EditTool instance's search method.async def search_in_document(file_path: str, query: str): return await _instance.search(file_path, query)