Skip to main content
Glama
jkingsman

https://github.com/jkingsman/qanon-mcp-server

get_post_by_id_tool

Retrieve a specific QAnon post by its ID for sociological research and analysis.

Instructions

Retrieve a specific post by its ID.

Args:
    post_id: The ID of the post to retrieve

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYes

Implementation Reference

  • The handler function for get_post_by_id_tool, decorated with @mcp.tool() for registration. Retrieves the post by ID using helper, formats it, adds adjacent post context, and returns formatted string.
    @mcp.tool()
    def get_post_by_id_tool(post_id: int) -> str:
        """
        Retrieve a specific post by its ID.
    
        Args:
            post_id: The ID of the post to retrieve
        """
        # Use the existing helper function to get the post
        post = get_post_by_id(post_id)
    
        if not post:
            return f"Post with ID {post_id} not found."
    
        # Use the existing format_post function to format the output
        formatted_post = format_post(post)
    
        # Get adjacent posts for context
        post_list = sorted(posts, key=lambda x: x.get("post_metadata", {}).get("id", 0))
        post_ids = [p.get("post_metadata", {}).get("id", 0) for p in post_list]
    
        try:
            index = post_ids.index(post_id)
            context = "\nAdjacent Posts:\n"
    
            # Get previous post if it exists
            if index > 0:
                prev_id = post_ids[index - 1]
                prev_date = datetime.fromtimestamp(
                    post_list[index - 1].get("post_metadata", {}).get("time", 0)
                ).strftime("%Y-%m-%d")
                context += f"Previous post: #{prev_id} from {prev_date}\n"
    
            # Get next post if it exists
            if index < len(post_ids) - 1:
                next_id = post_ids[index + 1]
                next_date = datetime.fromtimestamp(
                    post_list[index + 1].get("post_metadata", {}).get("time", 0)
                ).strftime("%Y-%m-%d")
                context += f"Next post: #{next_id} from {next_date}\n"
        except ValueError:
            context = ""
    
        result = f"Post #{post_id}:\n\n{formatted_post}\n{context}"
    
        return result
  • Docstring defining the tool's purpose and input parameter schema (post_id: int).
    """
    Retrieve a specific post by its ID.
    
    Args:
        post_id: The ID of the post to retrieve
    """
  • Helper function to find and return the post dictionary by ID from the loaded dataset.
    def get_post_by_id(post_id: int) -> Optional[Dict]:
        """Get a post by its ID."""
        for post in posts:
            if post.get("post_metadata", {}).get("id") == post_id:
                return post
        return None
  • Helper function to format the post data into a readable string, including metadata, text, images, and referenced posts.
    def format_post(post: Dict) -> str:
        """Format a post for display."""
        metadata = post.get("post_metadata", {})
        post_id = metadata.get("id", "Unknown")
        author = metadata.get("author", "Unknown")
        author_id = metadata.get("author_id", "Unknown")
        tripcode = metadata.get("tripcode", "Unknown")
    
        source = metadata.get("source", {})
        board = source.get("board", "Unknown")
        site = source.get("site", "Unknown")
    
        timestamp = metadata.get("time", 0)
        date_str = (
            datetime.fromtimestamp(timestamp).strftime("%Y-%m-%d %H:%M:%S")
            if timestamp
            else "Unknown"
        )
    
        text = post.get("text", "")
        if text:
            # Replace '\n' string literals with actual newlines
            text = text.replace("\\n", "\n")
    
        # Format images
        images_section = ""
        images = post.get("images", [])
        if images:
            images_section = "\nImages:\n"
            for img in images:
                images_section += f"- File: {img.get('file', 'Unknown')}, Name: {img.get('name', 'Unknown')}\n"
    
        # Format referenced posts
        refs_section = ""
        refs = post.get("referenced_posts", [])
        if refs:
            refs_section = "\nReferenced Posts:\n"
            for ref in refs:
                ref_text = ref.get("text", "No text")
                if ref_text:
                    ref_text = ref_text.replace("\\n", "\n")
                ref_author_id = ref.get("author_id", "Unknown")
                refs_section += f"- Reference: {ref.get('reference', 'Unknown')}\n"
                refs_section += f"  Author ID: {ref_author_id}\n"
                refs_section += f"  Text: {ref_text}\n"
    
        # Assemble the formatted post
        formatted = f"""
    Post ID: {post_id}
    Author: {author} (ID: {author_id}, tripcode: {tripcode})
    Source: {board} on {site}
    Date: {date_str}
    Text:
    {text}
    {images_section}
    {refs_section}
    """
        return formatted.strip()

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/jkingsman/qanon-mcp-server'

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