Skip to main content
Glama
JOBIN456

wikipedia

by JOBIN456

🚀 FastAPI + FastMCP + LangChain Wikipedia Agent

一个由 AI 驱动的 Wikipedia 研究代理,演示了 FastAPI、FastMCP、LangChain 和 LangGraph 如何协同工作,构建一个模块化的工具使用型 AI 应用。

该项目通过 MCP(模型上下文协议)服务器 暴露 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 研究

  • 🔌 模型上下文协议(MCP)集成

  • ⚡ FastAPI 应用层

  • 🧠 LangChain 代理集成

  • 🔄 LangGraph ReAct 代理

  • 🔎 Wikipedia 搜索工具

  • 📄 Wikipedia 页面检索工具

  • 🔗 MCP 工具发现

  • 📡 基于 stdio 的 MCP 通信

  • 🧩 模块化架构,可轻松支持更多工具


🛠️ 技术栈

技术

用途

Python

核心编程语言

FastAPI

API/应用层

FastMCP

MCP 服务器与工具实现

LangChain

LLM 与工具集成

LangGraph

代理工作流

Requests

Wikipedia API 请求

Wikipedia REST API

外部知识源


🔧 MCP 工具

FastMCP 服务器暴露了两个工具。

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.git
cd langchain-mcp-wikipedia

2. 创建虚拟环境

Windows:

python -m venv venv
venv\Scripts\activate

Linux/macOS:

python3 -m venv venv
source venv/bin/activate

3. 安装依赖

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 应用和代理之间复用。


📌 演示的关键概念

该项目有助于学习:

  • 模型上下文协议(MCP)

  • FastMCP

  • MCP 服务器

  • MCP 客户端

  • stdio 传输

  • LangChain 工具集成

  • LangGraph 代理

  • ReAct 代理

  • FastAPI

  • 外部 API 集成

  • LLM 工具调用

  • 模块化 AI 代理架构

F
license - not found
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    B
    maintenance
    A 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.
    22
    285
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A 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.
  • A
    license
    A
    quality
    C
    maintenance
    Enables 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.
    2
    3
    MIT
  • A
    license
    Not graded
    quality
    F
    maintenance
    Enables AI agents to search, read, and explore Wikipedia articles via tools like summaries, categories, and random articles, with no API keys required.
    1
    MIT

View all related MCP servers

Related MCP Connectors

  • Real-time Amazon, WIPO & PACER data for AI agents — 19 tools via the MCP protocol.

  • Web research for agents: quality-scored Google search, webpage extraction, and deep research.

  • LLM-ready web search + instant answers + URL-to-clean-text fetch for agents and RAG.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/JOBIN456/wikipedia-mcp-agent'

If you have feedback or need assistance with the MCP directory API, please join our Discord server