get_post_by_id_tool
Retrieve a specific QAnon post using its unique ID for detailed analysis or research. Input the post_id to access targeted content from the MCP server database.
Instructions
Retrieve a specific post by its ID.
Args:
post_id: The ID of the post to retrieve
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| post_id | Yes |
Implementation Reference
- src/qanon_mcp/__init__.py:284-329 (handler)The main handler for the get_post_by_id_tool. Retrieves the post 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
- src/qanon_mcp/__init__.py:49-55 (helper)Core helper function that searches the posts list to find and return the post dict by matching post_metadata.id.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
- src/qanon_mcp/__init__.py:96-154 (helper)Helper function to format a post dictionary into a human-readable string including metadata, text, images, and references.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()