get_links
Extract all links from a Wikipedia article by providing its title. This tool helps users quickly access and analyze referenced content within articles, supporting research and information gathering.
Instructions
Get the links contained within a Wikipedia article.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes |
Implementation Reference
- wikipedia_mcp/server.py:151-156 (handler)Handler function for the 'get_links' MCP tool. Registered via @server.tool() decorator. Wraps WikipediaClient.get_links() and formats the response.@server.tool() def get_links(title: str) -> Dict[str, Any]: """Get the links contained within a Wikipedia article.""" logger.info(f"Tool: Getting links for: {title}") links = wikipedia_client.get_links(title) return {"title": title, "links": links}
- Core helper method in WikipediaClient that implements the logic to fetch Wikipedia page links using wikipediaapi library.def get_links(self, title: str) -> List[str]: """Get the links in a Wikipedia article. Args: title: The title of the Wikipedia article. Returns: A list of links. """ try: page = self.wiki.page(title) if not page.exists(): return [] return [link for link in page.links.keys()] except Exception as e: logger.error(f"Error getting Wikipedia links: {e}") return []
- wikipedia_mcp/server.py:151-156 (registration)The @server.tool() decorator registers the get_links function as an MCP tool in the FastMCP server.@server.tool() def get_links(title: str) -> Dict[str, Any]: """Get the links contained within a Wikipedia article.""" logger.info(f"Tool: Getting links for: {title}") links = wikipedia_client.get_links(title) return {"title": title, "links": links}
- LRU cache decorator applied to get_links method when caching is enabled, improving performance for repeated calls.self.get_links = functools.lru_cache(maxsize=128)(self.get_links)