wikipedia
Enables LLM agents to search Wikipedia and retrieve page content via Model Context Protocol tools, supporting natural language research.
README
🚀 FastAPI + FastMCP + LangChain Wikipedia Agent
An AI-powered Wikipedia research agent demonstrating how FastAPI, FastMCP, LangChain, and LangGraph can work together to build a modular tool-using AI application.
The project exposes Wikipedia capabilities through an MCP (Model Context Protocol) server and allows a LangChain/LangGraph agent to automatically discover and use those tools.
🏗️ Architecture
┌──────────────────────┐
│ User │
│ Natural Language │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ FastAPI │
│ Application API │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ LangChain Agent │
│ LangGraph │
└──────────┬───────────┘
│
MCP Protocol
│
▼
┌──────────────────────┐
│ FastMCP │
│ MCP Server │
└──────────┬───────────┘
│
┌──────────┴───────────┐
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Wikipedia │ │ Wikipedia │
│ Search │ │ Page │
└──────────────┘ └──────────────┘
✨ Features
- 🤖 LLM-powered Wikipedia research
- 🔌 Model Context Protocol (MCP) integration
- ⚡ FastAPI application layer
- 🧠 LangChain agent integration
- 🔄 LangGraph ReAct agent
- 🔎 Wikipedia search tool
- 📄 Wikipedia page retrieval tool
- 🔗 MCP tool discovery
- 📡 stdio-based MCP communication
- 🧩 Modular architecture that can easily support additional tools
🛠️ Tech Stack
| Technology | Purpose |
|---|---|
| Python | Core programming language |
| FastAPI | API/application layer |
| FastMCP | MCP server and tool implementation |
| LangChain | LLM and tool integration |
| LangGraph | Agent workflow |
| Requests | Wikipedia API requests |
| Wikipedia REST API | External knowledge source |
🔧 MCP Tools
The FastMCP server exposes two tools.
search_wikipedia
Searches Wikipedia for a given topic.
@mcp.tool
def search_wikipedia(query: str):
...
Example:
Search Wikipedia for Albert Einstein
The agent can automatically decide to call:
search_wikipedia("Albert Einstein")
get_wikipedia_page
Retrieves the content of a specific Wikipedia page.
@mcp.tool
def get_wikipedia_page(title: str):
...
Example:
Get the Wikipedia page for Artificial Intelligence
The agent can call:
get_wikipedia_page("Artificial Intelligence")
🔄 How MCP Works in This Project
The MCP server runs using:
mcp.run(transport="stdio")
The LangChain client connects to the MCP server:
client = MultiServerMCPClient(
{
"wikipedia": {
"command": "python",
"args": ["server.py"],
"transport": "stdio",
}
}
)
The client then discovers the available MCP tools:
tools = await client.get_tools()
These tools are passed to the LangGraph agent:
agent = create_react_agent(
model,
tools
)
The LLM can then decide which tool to use based on the user's request.
⚙️ Installation
1. Clone the repository
git clone https://github.com/YOUR_USERNAME/langchain-mcp-wikipedia.git
cd langchain-mcp-wikipedia
2. Create a virtual environment
Windows:
python -m venv venv
venv\Scripts\activate
Linux/macOS:
python3 -m venv venv
source venv/bin/activate
3. Install dependencies
pip install -r requirements.txt
🔐 Environment Variables
Create a .env file:
OPENAI_API_KEY=your_openai_api_key
🧠 Why MCP?
Traditional tool integration often tightly couples an LLM application with individual APIs.
MCP provides a standardized way to expose capabilities as tools.
LLM
│
▼
LangChain / LangGraph
│
▼
MCP Client
│
▼
MCP Server
│
├── Wikipedia
├── Search
├── Database
├── APIs
└── Custom Tools
This separation makes tools reusable across different AI applications and agents.
📌 Key Concepts Demonstrated
This project is useful for learning:
- Model Context Protocol (MCP)
- FastMCP
- MCP servers
- MCP clients
- stdio transport
- LangChain tool integration
- LangGraph agents
- ReAct agents
- FastAPI
- External API integration
- LLM tool calling
- Modular AI agent architecture
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.