Skip to main content
Glama
lethain

Library MCP

by lethain

get_by_slug_or_url

Retrieve content from a Markdown knowledge base using a slug, URL, or path fragment to locate specific posts or documents.

Instructions

Get a post by its slug or URL.

Args: identifier: the slug, URL, or path fragment to search for

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
identifierYes

Implementation Reference

  • main.py:503-520 (handler)
    MCP tool handler for 'get_by_slug_or_url'. Calls the content manager's method and formats the output for the tool response.
    @mcp.tool()
    async def get_by_slug_or_url(identifier: str) -> str:
        """Get a post by its slug or URL.
        
        Args:
            identifier: the slug, URL, or path fragment to search for
        """
        if content_manager is None:
            return "Content has not been loaded. Please ensure the server is properly initialized."
        
        post = content_manager.get_by_slug_or_url(identifier)
        
        if post is None:
            return f"No post found with slug or URL matching '{identifier}'."
        
        # Format as a list to reuse format_content_for_output
        return format_content_for_output([post])
  • Core implementation logic in HugoContentManager class that searches for ContentFile by exact URL match, exact slug match (case insensitive), or partial path match.
    def get_by_slug_or_url(self, identifier: str) -> Optional[ContentFile]:
        """Find a post by its slug or URL"""
        identifier_lower = identifier.lower()
        
        debug_print(f"Searching for post with slug or URL: '{identifier}'")
        
        # First check for exact URL match (case insensitive)
        for _, content_file in self.path_to_content.items():
            url = content_file.url
            if url and url.lower() == identifier_lower:
                debug_print(f"Found exact URL match: {url}")
                return content_file
        
        # Then check for exact slug match (case insensitive)
        for _, content_file in self.path_to_content.items():
            slug = content_file.slug
            if slug.lower() == identifier_lower:
                debug_print(f"Found exact slug match: {slug}")
                return content_file
        
        # Try partial path match if no exact matches found
        for path, content_file in self.path_to_content.items():
            if identifier_lower in path.lower():
                debug_print(f"Found partial path match: {path}")
                return content_file
        
        debug_print(f"No post found for '{identifier}'")
        return None
  • Helper function used by the tool handler to format the retrieved ContentFile(s) 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)
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool retrieves a post but doesn't disclose behavioral traits like whether it returns a single result or multiple matches, error handling for invalid identifiers, authentication needs, or rate limits. This is a significant gap for a retrieval tool with zero annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with two sentences: a clear purpose statement and a parameter explanation. It's front-loaded with the core functionality, and the Args section adds necessary detail without redundancy. There's minimal waste, though the structure could be slightly more polished.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a retrieval operation with no output schema and no annotations), the description is incomplete. It lacks details on return values, error cases, and behavioral constraints, making it inadequate for an agent to fully understand how to invoke and interpret results. More context is needed for a tool with zero structured coverage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaning by explaining that the 'identifier' parameter can be a slug, URL, or path fragment, which clarifies its purpose beyond the schema's generic 'string' type. However, with 0% schema description coverage and only 1 parameter, this provides basic but not comprehensive semantic context, meeting the baseline for minimal parameter info.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Get') and resource ('a post'), specifying it retrieves content by slug or URL. It distinguishes from siblings like get_by_date_range or get_by_tag by focusing on identifier-based lookup rather than date, tag, or text criteria. However, it doesn't explicitly contrast with all siblings (e.g., search_tags).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when you have a slug, URL, or path fragment to find a specific post, suggesting it's for precise retrieval rather than filtering or listing. It doesn't explicitly state when NOT to use it or name alternatives like get_by_text for content-based searches, leaving some ambiguity versus other lookup tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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