get_summary
Retrieve a concise summary and title of any Wikipedia article by providing its title.
Instructions
Get a summary of a Wikipedia article.
Returns a dictionary with the title and summary string. On error, includes an error message instead of a summary.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| summary | No | ||
| error | No |
Implementation Reference
- wikipedia_mcp/server.py:260-272 (handler)The main handler function for the 'get_summary' tool. Decorated with @register_tool, it takes a title string, calls wikipedia_client.get_summary(), and returns a dictionary with title/summary/error.
@register_tool("get_summary", model_output_schema(SummaryResponse)) def get_summary(title: str): """ Get a summary of a Wikipedia article. Returns a dictionary with the title and summary string. On error, includes an error message instead of a summary. """ logger.info("Tool: Getting summary for: %s", title) summary = wikipedia_client.get_summary(title) if summary and not summary.startswith("Error"): return {"title": title, "summary": summary} return {"title": title, "summary": None, "error": summary} - The low-level Wikipedia API call that fetches the summary using the wikipedia library (page.summary). Handles errors and non-existent pages.
def get_summary(self, title: str) -> str: """ Get a summary of a Wikipedia article. Args: title: The title of the Wikipedia article. Returns: The article summary. """ try: page = self.wiki.page(title) if not page.exists(): return f"No Wikipedia article found for '{title}'." return page.summary except Exception as e: logger.error(f"Error getting Wikipedia summary: {e}") return f"Error retrieving summary for '{title}': {str(e)}" - wikipedia_mcp/schemas.py:55-58 (schema)The SummaryResponse Pydantic model defining the output schema for the get_summary tool: title (str), summary (Optional[str]), error (Optional[str]).
class SummaryResponse(MCPBaseModel): title: str summary: Optional[str] = None error: Optional[str] = None - wikipedia_mcp/server.py:160-175 (registration)The register_tool decorator that registers the function under the name 'get_summary' (and also 'wikipedia_get_summary') with the MCP server, using the SummaryResponse output schema.
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 - Caching: get_summary is wrapped with lru_cache for performance when caching is enabled.
self.get_summary = functools.lru_cache(maxsize=128)(self.get_summary) # type: ignore[method-assign]