get_links
Extract all hyperlinks from a Wikipedia article to identify related topics and references for research or content analysis.
Instructions
Get the links contained within a Wikipedia article.
Returns a dictionary with the article title and list of links.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes |
Implementation Reference
- wikipedia_mcp/server.py:239-248 (handler)MCP tool handler for get_links, decorated with @server.tool() for registration. Takes article title as input, calls WikipediaClient.get_links, and returns dict with title and list of links.@server.tool() def get_links(title: str) -> Dict[str, Any]: """ Get the links contained within a Wikipedia article. Returns a dictionary with the article title and list of links. """ 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 get_links by fetching the Wikipedia page via wikipediaapi.Wikipedia.page() and extracting page.links.keys() as list of link titles.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:239-239 (registration)The @server.tool() decorator registers the get_links function as an MCP tool.@server.tool()
- wikipedia_mcp/server.py:240-245 (schema)Type hints and docstring define the input schema (title: str) and output schema (Dict[str, Any] with title and links).def get_links(title: str) -> Dict[str, Any]: """ Get the links contained within a Wikipedia article. Returns a dictionary with the article title and list of links. """