summarize_article_section
Extract concise summaries from specific sections of Wikipedia articles to quickly understand targeted information without reading entire pages.
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
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| section_title | Yes | ||
| max_length | No |
Implementation Reference
- wikipedia_mcp/server.py:174-187 (handler)The @server.tool()-decorated handler function for 'summarize_article_section', defining the tool schema via parameters and executing the logic by calling 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. Returns a dictionary containing the section summary or an error. """ logger.info(f"Tool: Getting summary for section: {section_title} in article: {title}") summary = wikipedia_client.summarize_section(title, section_title, max_length=max_length) return {"title": title, "section_title": section_title, "summary": summary}
- Supporting method in WikipediaClient that performs the actual section summarization: retrieves the page, recursively finds the target section, extracts and truncates text to max_length.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)}"