Skip to main content
Glama
Rudra-ravi

Wikipedia MCP Server

by Rudra-ravi

summarize_article_section

Read-onlyIdempotent

Get a summary of a specific section from a Wikipedia article by providing the article title and section name.

Instructions

Get a summary of a specific section of a Wikipedia article.

Returns a dictionary containing the section summary or an error.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYes
section_titleYes
max_lengthNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
titleYes
section_titleYes
summaryYes

Implementation Reference

  • The tool handler function that executes the 'summarize_article_section' logic. It receives title, section_title, and max_length, logs the call, and delegates to wikipedia_client.summarize_section().
    def summarize_article_section(
        title: str,
        section_title: str,
        max_length: Annotated[int, Field(title="Max Length")] = 150,
    ):
        """
        Get a summary of a specific section of a Wikipedia article.
    
        Returns a dictionary containing the section summary or an error.
        """
        logger.info("Tool: Getting summary for section: %s in article: %s", section_title, title)
        summary = wikipedia_client.summarize_section(title, section_title, max_length=max_length)
        return {"title": title, "section_title": section_title, "summary": summary}
  • The SectionSummaryResponse Pydantic model defining the output schema (title, section_title, summary).
    class SectionSummaryResponse(MCPBaseModel):
        title: str
        section_title: str
        summary: str
  • The register_tool decorator that wires the handler to FastMCP server.tool() under both the original name and 'wikipedia_' prefix.
    def register_tool(name: str, output_schema: dict[str, Any]):
        def decorator(func):
            server.tool(
                func,
                name=name,
                annotations=_READ_ONLY_TOOL_ANNOTATIONS,
                output_schema=output_schema,
            )
            server.tool(
                func,
                name=f"wikipedia_{name}",
                annotations=_READ_ONLY_TOOL_ANNOTATIONS,
                output_schema=output_schema,
            )
            return func
    
        return decorator
  • The @register_tool decorator line that registers 'summarize_article_section' with the SectionSummaryResponse output schema.
    @register_tool("summarize_article_section", model_output_schema(SectionSummaryResponse))
  • The WikipediaClient.summarize_section() helper that fetches the page, finds the target section recursively, and returns a truncated summary.
    def summarize_section(self, title: str, section_title: str, max_length: int = 150) -> str:
        """
        Get a summary of a specific section of a Wikipedia article.
    
        Args:
            title: The title of the Wikipedia article.
            section_title: The title of the section to summarize.
            max_length: The maximum length of the summary.
    
        Returns:
            A summary of the specified section.
        """
        try:
            page = self.wiki.page(title)
            if not page.exists():
                return f"No Wikipedia article found for '{title}'."
    
            target_section = None
    
            # Helper function to find the section
            def find_section_recursive(sections_list, target_title):
                for sec in sections_list:
                    if sec.title.lower() == target_title.lower():
                        return sec
                    # Check subsections
                    found_in_subsection = find_section_recursive(sec.sections, target_title)
                    if found_in_subsection:
                        return found_in_subsection
                return None
    
            target_section = find_section_recursive(page.sections, section_title)
    
            if not target_section or not target_section.text:
                return f"Section '{section_title}' not found or is empty in article '{title}'."
    
            summary = target_section.text[:max_length]
            return summary + "..." if len(target_section.text) > max_length else summary
    
        except Exception as e:
            logger.error(f"Error summarizing section '{section_title}' for article '{title}': {e}")
            return f"Error summarizing section '{section_title}': {str(e)}"

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv2.0.1
  2. Removedv1.5.8
  3. Changed3 schema fields changedv1.0.0
    • removedInput schema / properties / max_length / title
      Removed value: -"Max Length"
    • removedInput schema / properties / section_title / title
      Removed value: -"Section Title"
    • removedInput schema / properties / title / title
      Removed value: -"Title"
  4. First observed

TDQS

B3.4/5.0
Behavior4/5

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

Annotations already cover read-only, idempotent, and non-destructive behavior. The description adds the return behavior ('Returns a dictionary containing the section summary or an error'), which goes beyond the annotations. It doesn't mention max_length effects, but the annotation coverage lowers the required burden.

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?

Two concise sentences, front-loaded with the primary purpose, and no filler or 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?

The tool has annotations and an output schema, and the description states purpose and return type. However, it lacks parameter semantics, usage guidelines versus siblings, and any mention of max_length or error handling nuances, leaving meaningful gaps for a 3-parameter tool.

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

Parameters1/5

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

Schema coverage is 0% and the description provides no explanation for the parameters (title, section_title, max_length). It does not compensate for the missing schema descriptions, leaving parameter semantics entirely to the agent's inference from names.

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 uses a specific verb ('Get') and resource ('a specific section of a Wikipedia article'), clearly distinguishing it from siblings like get_summary (whole article summary) and get_sections (list sections). It also states the return type.

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?

No guidance is provided on when to use this tool versus alternatives such as get_summary or summarize_article_for_query. The usage is only implied by the phrase 'specific section', with no explicit when/when-not or sibling differentiation.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.