wikipedia
🚀 FastAPI + FastMCP + LangChain Wikipedia Agent
FastAPI、FastMCP、LangChain、LangGraph が連携して、モジュール式のツール使用型AIアプリケーションを構築する方法を示す、AI搭載のWikipediaリサーチエージェントです。
このプロジェクトは、MCP(Model Context Protocol)サーバーを通じてWikipediaの機能を公開し、LangChain/LangGraphエージェントがそれらのツールを自動的に発見して使用できるようにします。
🏗️ アーキテクチャ
┌──────────────────────┐
│ User │
│ Natural Language │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ FastAPI │
│ Application API │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ LangChain Agent │
│ LangGraph │
└──────────┬───────────┘
│
MCP Protocol
│
▼
┌──────────────────────┐
│ FastMCP │
│ MCP Server │
└──────────┬───────────┘
│
┌──────────┴───────────┐
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Wikipedia │ │ Wikipedia │
│ Search │ │ Page │
└──────────────┘ └──────────────┘Related MCP server: MCP Wikipedia Server
✨ 機能
🤖 LLM搭載のWikipediaリサーチ
🔌 Model Context Protocol(MCP)統合
⚡ FastAPIアプリケーション層
🧠 LangChainエージェント統合
🔄 LangGraph ReActエージェント
🔎 Wikipedia検索ツール
📄 Wikipediaページ取得ツール
🔗 MCPツール発見
📡 stdioベースのMCP通信
🧩 追加ツールを簡単にサポートできるモジュール式アーキテクチャ
🛠️ 技術スタック
Technology | Purpose |
Python | 中核プログラミング言語 |
FastAPI | API/アプリケーション層 |
FastMCP | MCPサーバーとツール実装 |
LangChain | LLMとツールの統合 |
LangGraph | エージェントワークフロー |
Requests | Wikipedia APIリクエスト |
Wikipedia REST API | 外部知識ソース |
🔧 MCPツール
FastMCPサーバーは2つのツールを公開します。
search_wikipedia
指定されたトピックについてWikipediaを検索します。
@mcp.tool
def search_wikipedia(query: str):
...例:
Search Wikipedia for Albert Einsteinエージェントは自動的に以下を呼び出すことを決定できます:
search_wikipedia("Albert Einstein")get_wikipedia_page
特定のWikipediaページのコンテンツを取得します。
@mcp.tool
def get_wikipedia_page(title: str):
...例:
Get the Wikipedia page for Artificial Intelligenceエージェントは以下を呼び出すことができます:
get_wikipedia_page("Artificial Intelligence")🔄 このプロジェクトでのMCPの仕組み
MCPサーバーは以下を使用して実行されます:
mcp.run(transport="stdio")LangChainクライアントはMCPサーバーに接続します:
client = MultiServerMCPClient(
{
"wikipedia": {
"command": "python",
"args": ["server.py"],
"transport": "stdio",
}
}
)クライアントは利用可能なMCPツールを発見します:
tools = await client.get_tools()これらのツールはLangGraphエージェントに渡されます:
agent = create_react_agent(
model,
tools
)LLMはユーザーのリクエストに基づいて使用するツールを決定できます。
⚙️ インストール
1. リポジトリをクローンする
git clone https://github.com/YOUR_USERNAME/langchain-mcp-wikipedia.gitcd langchain-mcp-wikipedia2. 仮想環境を作成する
Windows:
python -m venv venv
venv\Scripts\activateLinux/macOS:
python3 -m venv venv
source venv/bin/activate3. 依存関係をインストールする
pip install -r requirements.txt🔐 環境変数
.env ファイルを作成します:
OPENAI_API_KEY=your_openai_api_key🧠 MCPを使う理由
従来のツール統合は、LLMアプリケーションを個々のAPIと密に結合させることがよくあります。
MCPは、機能をツールとして公開する標準化された方法を提供します。
LLM
│
▼
LangChain / LangGraph
│
▼
MCP Client
│
▼
MCP Server
│
├── Wikipedia
├── Search
├── Database
├── APIs
└── Custom Toolsこの分離により、ツールはさまざまなAIアプリケーションやエージェント間で再利用可能になります。
📌 実証される主要コンセプト
このプロジェクトは以下の学習に役立ちます:
Model Context Protocol (MCP)
FastMCP
MCPサーバー
MCPクライアント
stdioトランスポート
LangChainツール統合
LangGraphエージェント
ReActエージェント
FastAPI
外部API統合
LLMツール呼び出し
モジュール式AIエージェントアーキテクチャ
This server cannot be deployed
Maintenance
Related MCP Connectors
Search Wikipedia, read summaries and full text, target sections, find nearby pages, list languages.
Google search, news, maps, scholar and public webpages for AI agents, with Markdown results.
Web search, point-in-time crypto market data, verified strategy track records and 160+ agent tools.
461Direct access to 60+ scraping and search tools. Extract structured data from Google (Search, Maps, Trends), Amazon, Airbnb, Social Media, and any web page directly into your AI agent.
Related MCP Servers
- AlicenseBqualityCmaintenanceA Model Context Protocol server that retrieves information from Wikipedia to provide context to LLMs, allowing users to search articles, get summaries, full content, sections, and links from Wikipedia.224,717 PyPI299MIT
- FlicenseNot gradedqualityDmaintenanceA production-ready server that provides Wikipedia search and content retrieval tools through the Model Context Protocol, enabling AI assistants to search for articles, list sections, and retrieve specific content.-
- AlicenseAqualityCmaintenanceEnables LLMs to search for keywords and fetch full page content from Wikipedia across various languages. It provides direct access to Wikipedia information through search and fetch tools.24MIT
- AlicenseNot gradedqualityFmaintenanceEnables AI agents to search, read, and explore Wikipedia articles via tools like summaries, categories, and random articles, with no API keys required.1MIT