get_by_tag
Retrieve blog content by specific tag with customizable results limit using the 'get_by_tag' tool on the Library MCP server. Streamline content discovery in Markdown knowledge bases.
Instructions
Get blog content by its tag.
Args: tag: the tag associated with content limit: the number of results to include
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| tag | Yes |
Implementation Reference
- main.py:428-440 (handler)MCP tool handler for 'get_by_tag'. Registers the tool and implements the logic by calling the content manager's get_by_tag method and formatting the output as a string.@mcp.tool() async def get_by_tag(tag: str, limit: int = 50) -> str: """Get blog content by its tag. Args: tag: the tag associated with content 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_tag(tag, limit) return format_content_for_output(matching_content)
- main.py:163-204 (helper)Helper method in HugoContentManager class that performs the core search logic for content files by tag (exact or partial match, case-insensitive), normalizes tags, sorts results by date descending, and applies limit.def get_by_tag(self, tag: str, limit: int = 50) -> List[ContentFile]: """Find all files with a given tag""" matches = [] tag_lower = tag.lower() debug_print(f"Searching for tag: '{tag_lower}'") for file_path, content_file in self.path_to_content.items(): raw_tags = content_file.meta.get('tags', []) tags = self._normalize_tags(raw_tags) # Debug if tags: debug_print(f"File: {os.path.basename(file_path)} - Tags: {tags}") # Check for exact tag match (case insensitive) if any(tag_lower == t.lower() for t in tags): debug_print(f"Found exact tag match in {os.path.basename(file_path)}") matches.append(content_file) continue # Check if the tag is part of a tag for t in tags: if tag_lower in t.lower(): debug_print(f"Found partial tag match in {os.path.basename(file_path)}: '{t}'") matches.append(content_file) break debug_print(f"Found {len(matches)} files with tag '{tag}'") # 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]