Skip to main content
Glama
KazKozDev
by KazKozDev

search_text

Find specific text strings in Markdown files and locate their structural positions using semantic search to identify content within document hierarchies.

Instructions

Performs a semantic search for text strings and returns their structural paths.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYes
queryYesString to search for

Implementation Reference

  • Core implementation of search_text method in Document class. Recursively traverses the element tree to find elements containing the query string (case-insensitive) and returns list of dicts with path, type, and preview.
    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
  • Registers the search_text tool with the MCP server, defining its name, title, description, input schema (file_path and query), and output schema.
    Tool(
        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",
                }
            },
        },
    ),
  • Tool dispatch handler in server.py that calls search_in_document with file_path and query, formats the result with count, and returns as CallToolResult.
    elif name == "search_text":
        res = await search_in_document(file_path, arguments["query"])
        result = {"results": res, "count": len(res)}
        return CallToolResult(
            content=[TextContent(type="text", text=json.dumps(result, ensure_ascii=False, indent=2))],
            structuredContent=result,
            isError=False,
        )
  • Helper 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)
  • Top-level async wrapper function that invokes the singleton EditTool instance's search method.
    async def search_in_document(file_path: str, query: str):
        return await _instance.search(file_path, query)

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/KazKozDev/markdown-editor-mcp-server'

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