Skip to main content
Glama

get_related_pages

Read-onlyIdempotent

Retrieve related pages linked from a Grokipedia article by providing its slug. Optionally limit the number of results, up to 50.

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 function that implements the get_related_pages tool. It fetches a page by slug using the API client, extracts linked pages, and returns them formatted as text output with structured content. Handles not-found, bad request, network, and API errors.
    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
  • Input parameter definitions: slug (string required) and limit (int, default 10, range 1-50) with Pydantic Field annotations.
    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,
  • The @mcp.tool() decorator that registers get_related_pages as an MCP tool with readOnlyHint, destructiveHint=False, and idempotentHint=True annotations.
    @mcp.tool(
        annotations=ToolAnnotations(
            readOnlyHint=True,
            destructiveHint=False,
            idempotentHint=True
        )
    )
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true, so the safety profile is clear. The description adds minimal behavioral context (only that it retrieves linked pages) but does not elaborate on what 'linked' means (e.g., forward links only, pagination, or ordering).

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 a single, clear sentence (8 words) that conveys the core purpose without unnecessary detail. It could be slightly longer to provide more context, but it remains efficient and front-loaded.

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 output schema, the description does not describe the return format or structure. For a tool that returns a list of pages, some indication of what fields are returned would improve completeness, but the description is adequate for basic usage.

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

Parameters3/5

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

Schema description coverage is 100% with both parameters (slug and limit) fully described in the schema. The description adds no extra meaning beyond what the schema provides, so baseline score of 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Get pages that are linked from the specified page' clearly states the verb 'Get' and the resource 'pages that are linked from the specified page', which distinguishes it from siblings like get_page (retrieves a single page) and search (full-text search).

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

Usage Guidelines3/5

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

The description implies when to use this tool (when you need pages linked from a given page) but provides no explicit guidance on when not to use it or how it compares to alternatives like search or get_page_citations.

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

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