get_related_pages
Read-onlyIdempotent
Find related Grokipedia articles linked from a specific page to explore connected topics, build knowledge graphs, or conduct follow-up research.
Instructions
Discover related Grokipedia pages linked from an article.
Use for: exploring connected topics, building knowledge graphs, follow-up research. Returns: list of related pages with titles and slugs. Tips: Use returned slugs with get_page to dive into related topics.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| slug | Yes | Unique slug identifier of page to find related pages for | |
| limit | No | Maximum number of related pages to return (default: 10) |
Implementation Reference
- grokipedia_mcp/server.py:405-485 (handler)The get_related_pages tool handler implementation, which retrieves related pages for a given Grokipedia page slug.
async def get_related_pages( slug: Annotated[str, Field(description="Unique slug identifier of page to find related pages for")], limit: Annotated[int, Field(description="Maximum number of related pages to return (default: 10)", ge=1, le=50)] = 10, ctx: Context[ServerSession, AppContext] | None = None, ) -> CallToolResult: """Discover related Grokipedia pages linked from an article. Use for: exploring connected topics, building knowledge graphs, follow-up research. Returns: list of related pages with titles and slugs. Tips: Use returned slugs with get_page to dive into related topics. """ if ctx is None: raise ValueError("Context is required") await ctx.debug(f"Fetching related pages for: '{slug}' (limit={limit})") try: client = ctx.request_context.lifespan_context.client result = await client.get_page(slug=slug, include_content=False) if not result.found or result.page is None: await ctx.warning(f"Page not found: '{slug}'") raise ValueError(f"Page not found: {slug}") page = result.page linked_pages = page.linked_pages or [] total_count = len(linked_pages) related = linked_pages[:limit] if limit else linked_pages is_limited = limit and total_count > limit await ctx.info(f"Found {len(related)} of {total_count} related pages for: '{page.title}'") if not linked_pages: text_output = f"# {page.title}\n\nNo related pages found." structured = { "slug": page.slug, "title": page.title, "related_pages": [], "total_count": 0, "returned_count": 0, } else: header = f"# {page.title}\n\n" if is_limited: header += f"Showing {len(related)} of {total_count} related pages:\n\n" else: header += f"Found {total_count} related pages:\n\n" text_parts = [header] for i, rel_page in enumerate(related, 1): if isinstance(rel_page, dict): title = rel_page.get("title", "Unknown") slug_val = rel_page.get("slug", "") else: title = str(rel_page) slug_val = "" text_parts.append(f"{i}. {title}") if slug_val: text_parts.append(f" Slug: {slug_val}") text_parts.append("") if is_limited: text_parts.append(f"... and {total_count - len(related)} more") text_output = "\n".join(text_parts) structured = { "slug": page.slug, "title": page.title, "related_pages": related, "total_count": total_count, "returned_count": len(related), } if is_limited: structured["_limited"] = True return CallToolResult( content=[TextContent(type="text", text=text_output)], structuredContent=structured, ) - grokipedia_mcp/server.py:398-404 (registration)Registration of the get_related_pages tool using the @mcp.tool decorator.
@mcp.tool( annotations=ToolAnnotations( readOnlyHint=True, destructiveHint=False, idempotentHint=True ) )