Skip to main content
Glama

get_related_pages

Find linked pages from any Grokipedia article to discover related content and expand your research with relevant connections.

Instructions

Get pages that are linked from the specified page.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
slugYesUnique slug identifier of page to find related pages for
limitNoMaximum number of related pages to return (default: 10)

Implementation Reference

  • The async handler function that executes the tool logic: fetches the page, extracts linked_pages, applies limit, generates formatted text output and structured JSON with related pages list.
    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: """Get pages that are linked from the specified page.""" 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, ) except GrokipediaNotFoundError as e: await ctx.error(f"Page not found: {e}") raise ValueError(f"Page not found: {slug}") from e except GrokipediaBadRequestError as e: await ctx.error(f"Bad request: {e}") raise ValueError(f"Invalid page slug: {e}") from e except GrokipediaNetworkError as e: await ctx.error(f"Network error: {e}") raise RuntimeError(f"Failed to connect to Grokipedia API: {e}") from e except GrokipediaAPIError as e: await ctx.error(f"API error: {e}") raise RuntimeError(f"Grokipedia API error: {e}") from e
  • Registers the get_related_pages tool in the FastMCP server using the @mcp.tool decorator, which automatically uses the function name as tool name and derives schema from signature.
    @mcp.tool( annotations=ToolAnnotations( readOnlyHint=True, destructiveHint=False, idempotentHint=True ) )
  • Input schema defined via Pydantic Annotated types and Field descriptions for parameters slug (required str) and limit (optional int, default 10, range 1-50). Output is CallToolResult.
    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: """Get pages that are linked from the specified page."""

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/skymoore/grokipedia-mcp'

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