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
| Name | Required | Description | Default |
|---|---|---|---|
| identifier | Yes |
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])
- main.py:302-329 (helper)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
- main.py:372-393 (helper)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)