Skip to main content
Glama

get_by_text

Retrieve blog content from local markdown files by searching for exact text matches within the content. Specify text to find and limit results as needed.

Instructions

Get blog content by text in content.

Args: query: text for an exact match limit: the number of results to include

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
limitNo

Implementation Reference

  • main.py:443-456 (handler)
    MCP tool handler for 'get_by_text'. Calls the content manager's method and formats the output.
    @mcp.tool() async def get_by_text(query: str, limit: int = 50) -> str: """Get blog content by text in content. Args: query: text for an exact match limit: the number of results to include """ if content_manager is None: return "Content has not been loaded. Please ensure the server is properly initialized." matching_content = content_manager.get_by_text(query, limit) return format_content_for_output(matching_content)
  • Implementation of text search in HugoContentManager class. Searches content files for exact substring match (case-insensitive), sorts by date descending, limits results.
    def get_by_text(self, query: str, limit: int = 50) -> List[ContentFile]: """Find all files containing the specified text""" matches = [] query_lower = query.lower() debug_print(f"Searching for text: '{query}'") for file_path, content_file in self.path_to_content.items(): if query_lower in content_file.data.lower(): matches.append(content_file) debug_print(f"Found {len(matches)} files containing '{query}'") # Sort by date (most recent first) def get_sort_key(content_file): date = content_file.date if date is None: return datetime.min # Make date naive if it has timezone info if hasattr(date, 'tzinfo') and date.tzinfo is not None: date = date.replace(tzinfo=None) return date matches.sort(key=get_sort_key, reverse=True) return matches[:limit]
  • Input schema defined in the tool's docstring.
    """Get blog content by text in content. Args: query: text for an exact match limit: the number of results to include """
  • Helper function to format search results into a readable string output.
    def format_content_for_output(content_files: List[ContentFile]) -> str: """Format the content files for output""" if not content_files: return "No matching content found." result = [] for i, file in enumerate(content_files): result.append(f"File: {file.path}") result.append("Metadata:") for key, value in file.meta.items(): result.append(f" {key}: {value}") # Include the full content result.append("Content:") result.append(file.data.strip()) # Add separator between entries, but not after the last one if i < len(content_files) - 1: result.append("-" * 50) return "\n".join(result)

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/lethain/library-mcp'

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