Skip to main content
Glama

get_by_text

Retrieve blog content by matching specific text from local Markdown files using 'Library MCP'. Specify search query and limit results for precise content extraction.

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
limitNo
queryYes

Implementation Reference

  • main.py:443-456 (handler)
    MCP tool handler for 'get_by_text'. Delegates to content_manager's method and formats the output using format_content_for_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)
  • Core search logic in HugoContentManager.get_by_text: searches all loaded content files for exact substring match (case-insensitive), sorts matches by date descending, limits to specified number.
    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]
  • Helper function to format list of ContentFile into human-readable string with file path, metadata, and full content, separated by lines.
    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)
  • main.py:443-443 (registration)
    The @mcp.tool() decorator registers the get_by_text function as an MCP tool.
    @mcp.tool()

Other Tools

Related Tools

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