summarize_article_section
Extract concise summaries of specific sections from Wikipedia articles by specifying the title and section. Ideal for quick insights without reading the full content.
Instructions
Get a summary of a specific section of a Wikipedia article.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_length | No | ||
| section_title | Yes | ||
| title | Yes |
Implementation Reference
- wikipedia_mcp/server.py:107-117 (handler)The tool handler for 'summarize_article_section', registered via @server.tool(). Defines input schema via type annotations and delegates core logic to WikipediaClient.summarize_section.@server.tool() def summarize_article_section( title: str, section_title: str, max_length: Annotated[int, Field(title="Max Length")] = 150, ) -> Dict[str, Any]: """Get a summary of a specific section of a Wikipedia article.""" logger.info(f"Tool: Getting summary for section: {section_title} in article: {title}") # Assuming wikipedia_client has a method like summarize_section summary = wikipedia_client.summarize_section(title, section_title, max_length=max_length) return {"title": title, "section_title": section_title, "summary": summary}
- Core helper method implementing the section summarization logic: recursively finds the section using wikipediaapi, truncates its text to max_length, with error handling.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)}"