summarize_article_section
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
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| section_title | Yes | ||
| max_length | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| section_title | Yes | ||
| summary | Yes |
Implementation Reference
- wikipedia_mcp/server.py:291-303 (handler)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} - wikipedia_mcp/schemas.py:67-70 (schema)The SectionSummaryResponse Pydantic model defining the output schema (title, section_title, summary).
class SectionSummaryResponse(MCPBaseModel): title: str section_title: str summary: str - wikipedia_mcp/server.py:160-176 (registration)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 - wikipedia_mcp/server.py:290-290 (registration)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)}"