Skip to main content
Glama
ferdousbhai

WSB Analyst MCP Server

fetch_post_details

Retrieve detailed WallStreetBets post information including comments and extracted links for market analysis. Caches results for 5 minutes.

Instructions

Fetch detailed information about a specific WSB post including top comments. Caches results for 5 minutes.

Args:
    post_id: Reddit post ID

Returns:
    Detailed post data including comments and extracted links

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYes

Implementation Reference

  • server.py:212-212 (registration)
    Registers the fetch_post_details tool using the @mcp.tool() decorator, which handles schema inference from type hints and docstring.
    @mcp.tool()
  • The core handler function for the fetch_post_details tool. Fetches a Reddit submission by post_id, loads top comments, extracts valid external links from post content and comments, implements caching with 5-minute TTL, and returns structured post details.
    async def fetch_post_details(post_id: str, ctx: Context = None) -> dict:
        """
        Fetch detailed information about a specific WSB post including top comments. Caches results for 5 minutes.
    
        Args:
            post_id: Reddit post ID
    
        Returns:
            Detailed post data including comments and extracted links
        """
        # --- Cache Check ---
        cache_key = f"fetch_post_details:{post_id}"
        current_time = time.time()
        if cache_key in CACHE_DATA and current_time < CACHE_EXPIRY.get(cache_key, 0):
            logger.info(f"Cache hit for {cache_key}")
            return CACHE_DATA[cache_key]
        logger.info(f"Cache miss for {cache_key}")
        # --- End Cache Check ---
    
        try:
            if ctx:
                await ctx.report_progress(0, 3)
    
            reddit = await get_reddit_client()
            if not reddit:
                return {"error": "Unable to connect to Reddit API. Check your credentials."}
    
            try:
                if ctx:
                    await ctx.report_progress(1, 3)
    
                submission = await reddit.submission(id=post_id)
    
                # Load comments
                if ctx:
                    await ctx.report_progress(2, 3)
    
                await submission.comments.replace_more(limit=0)
                comments = await submission.comments.list()
                top_comments = sorted(comments, key=lambda c: c.score, reverse=True)[:10]
    
                # Extract links
                content_links = []
                if not submission.is_self and is_valid_external_link(submission.url):
                    content_links.append(submission.url)
                elif submission.is_self:
                    content_links.extend(extract_valid_links(submission.selftext))
    
                # Process comments
                comment_links = []
                comment_data = []
                for comment in top_comments:
                    try:
                        author_name = comment.author.name if comment.author else "[deleted]"
                        links_in_comment = extract_valid_links(comment.body)
                        if links_in_comment:
                            comment_links.extend(links_in_comment)
    
                        comment_data.append({
                            "content": comment.body,
                            "score": comment.score,
                            "author": author_name
                        })
                    except Exception as e:
                        logger.warning(f"Error processing comment: {str(e)}")
    
                # Combine all found links
                all_links = list(set(content_links + comment_links))
    
                result = {
                    "post_id": post_id,
                    "url": f"https://www.reddit.com{submission.permalink}",
                    "title": submission.title,
                    "selftext": submission.selftext if submission.is_self else "",
                    "upvote_ratio": submission.upvote_ratio,
                    "score": submission.score,
                    "link_flair_text": submission.link_flair_text or "",
                    "top_comments": comment_data,
                    "extracted_links": all_links
                }
    
                # --- Cache Store ---
                CACHE_DATA[cache_key] = result
                CACHE_EXPIRY[cache_key] = current_time + CACHE_TTL
                logger.info(f"Cached result for {cache_key} with TTL {CACHE_TTL}s")
                # --- End Cache Store ---
    
                if ctx:
                    await ctx.report_progress(3, 3)
    
                return result
            finally:
                await reddit.close()
        except Exception as e:
            logger.error(f"Error in fetch_post_details: {str(e)}")
            return {"error": f"Failed to fetch post details: {str(e)}"}
Behavior3/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 discloses caching behavior ('Caches results for 5 minutes'), which is useful context beyond basic functionality. However, it lacks details on error handling, rate limits, authentication needs, or what happens if the post_id is invalid.

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 and front-loaded, with the core purpose stated first, followed by caching info and parameter/return details. Every sentence adds value, though the structure could be slightly improved by integrating caching into the main sentence for better flow.

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

Completeness3/5

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

Given no annotations and no output schema, the description does a decent job by explaining the parameter and return value in general terms. However, for a tool with caching and potential complexity in returns, it should provide more detail on output structure, error cases, or limitations to be fully complete.

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

Parameters4/5

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

With 0% schema description coverage and only one parameter, the description adds significant value by explaining that 'post_id' is a 'Reddit post ID', clarifying its format and source. This compensates well for the lack of schema documentation, though it could specify format constraints like length or pattern.

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 ('Fetch') and resource ('detailed information about a specific WSB post including top comments'), making the purpose explicit. However, it doesn't distinguish this tool from its siblings like 'fetch_detailed_wsb_posts' or 'fetch_batch_post_details', which likely have overlapping functionality.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'fetch_batch_post_details' and 'fetch_detailed_wsb_posts', there's no indication of differences in scope, filtering, or use cases, leaving the agent without contextual direction.

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/ferdousbhai/wsb-analyst-mcp'

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