Skip to main content
Glama

get_page_citations

Read-onlyIdempotent

Retrieve citations for a Grokipedia page using its unique slug. Optionally limit the number of citations returned.

Instructions

Get the citations list for a specific page.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
slugYesUnique slug identifier of page to retrieve citations from
limitNoMaximum number of citations to return (optional, returns all if not specified)

Implementation Reference

  • The main handler function that executes the get_page_citations tool logic. It fetches citations for a page by slug from the Grokipedia API, formats them as text and structured output, and handles various error cases.
    @mcp.tool(
        annotations=ToolAnnotations(
            readOnlyHint=True,
            destructiveHint=False,
            idempotentHint=True
        )
    )
    async def get_page_citations(
        slug: Annotated[str, Field(description="Unique slug identifier of page to retrieve citations from")],
        limit: Annotated[int | None, Field(description="Maximum number of citations to return (optional, returns all if not specified)", ge=1)] = None,
        ctx: Context[ServerSession, AppContext] | None = None,
    ) -> CallToolResult:
        """Get the citations list for a specific page."""
        if ctx is None:
            raise ValueError("Context is required")
    
        await ctx.debug(f"Fetching citations 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
            all_citations = page.citations or []
            total_count = len(all_citations)
            
            citations = all_citations[:limit] if limit else all_citations
            is_limited = limit and total_count > limit
            
            await ctx.info(
                f"Retrieved {len(citations)} of {total_count} citations for: '{page.title}'"
            )
            
            if not all_citations:
                text_output = f"# {page.title}\n\nNo citations found."
                structured = {
                    "slug": page.slug,
                    "title": page.title,
                    "citations": [],
                    "total_count": 0,
                    "returned_count": 0,
                }
            else:
                header = f"# {page.title}\n\n"
                if is_limited:
                    header += f"Showing {len(citations)} of {total_count} citations:\n"
                else:
                    header += f"Found {total_count} citations:\n"
                
                text_parts = [header]
                for i, citation in enumerate(citations, 1):
                    text_parts.append(f"{i}. **{citation.title}**")
                    text_parts.append(f"   URL: {citation.url}")
                    if citation.description:
                        text_parts.append(f"   Description: {citation.description}")
                    text_parts.append("")
                
                if is_limited:
                    text_parts.append(f"... and {total_count - len(citations)} more citations")
                
                text_output = "\n".join(text_parts)
                structured = {
                    "slug": page.slug,
                    "title": page.title,
                    "citations": [c.model_dump() for c in citations],
                    "total_count": total_count,
                    "returned_count": len(citations),
                }
                
                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 schema for get_page_citations: requires 'slug' (string) and optional 'limit' (positive integer). Uses Pydantic Field for validation and description.
    async def get_page_citations(
        slug: Annotated[str, Field(description="Unique slug identifier of page to retrieve citations from")],
        limit: Annotated[int | None, Field(description="Maximum number of citations to return (optional, returns all if not specified)", ge=1)] = None,
        ctx: Context[ServerSession, AppContext] | None = None,
  • Registration of get_page_citations as an MCP tool via the @mcp.tool() decorator with annotations marking it as read-only, non-destructive, and idempotent.
    @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 provide readOnlyHint=true, destructiveHint=false, and idempotentHint=true. The description is consistent but adds no additional behavioral details beyond what annotations provide, such as what a citation represents or how the limit parameter affects the output.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no unnecessary words. It is efficiently front-loaded and avoids redundancy.

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?

For a simple read operation with two parameters and no output schema, the description is minimally adequate. It does not explain what a 'citation' is or how the results are structured, which could be helpful for an AI agent.

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?

Both parameters (slug, limit) have complete descriptions in the input schema. The description does not add meaning beyond the schema, so it meets the baseline expectation without improvement.

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 the citations list for a specific page' clearly states the verb (get), specific resource (citations list), and scope (for a specific page), effectively distinguishing it from sibling tools like get_page or get_page_content.

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 does not provide explicit guidance on when to use this tool versus alternatives, such as search or get_related_pages. For a tool with multiple siblings, some context on when citations are needed would improve clarity.

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