维基百科MCP服务器
](https://smithery.ai/server/@Rudra-ravi/wikipedia-mcp)  
一种模型上下文协议(MCP)服务器,从维基百科检索信息,为大型语言模型(LLM)提供上下文。该工具可帮助人工智能助手从维基百科访问事实信息,以将他们的反应建立在可靠的来源上。
概述
维基百科MCP服务器通过标准化的模型上下文协议接口提供对维基百科信息的实时访问。这允许LLM直接从维基百科检索准确和最新的信息,以增强他们的响应。
已验证
](https://mseep.ai/app/rudra-ravi-wikipedia-mcp)
特性
- 搜索维基百科:查找与具有增强诊断功能的特定查询相匹配的文章
- 检索文章内容:获取包含所有信息的全文
- 文章摘要:获取文章的简明摘要
- 剖面提取:从文章中检索特定部分
- 链接发现:在文章中查找相关主题的链接
- 相关主题:发现与特定文章相关的主题
- 多语言支持:通过指定以下内容访问不同语言的维基百科
--language或-l在运行服务器时的参数(例如。,wikipedia-mcp --language ta泰米尔语)。 - 国家/地区支持:使用直观的国家代码,如
--country US,--country China,或--country TW而不是语言代码。自动映射到相应的维基百科语言变体。 - 语言变体支持:支持中文繁体/简体等语言变体(例如。,
zh-hans对于简体中文,zh-tw繁体中文),塞尔维亚文字(sr-latn,sr-cyrl),以及其他区域变体。 - 可选缓存:使用--enable-Cache缓存API响应以提高性能
- 现代MCP传输支持:支持
stdio,http,以及streamable-http(有遗产sse兼容性)。 - 可选MCP传输认证:安全的网络传输
--auth-mode static或--auth-mode jwt. - 谷歌ADK兼容性:与Google ADK代理和其他使用严格函数调用模式的AI框架完全兼容
安装
使用pipx(建议用于Claude Desktop)
安装Claude Desktop的最佳方法是使用pipx,它全局安装命令:
# Install pipx if you don't have it
pip install pipx
pipx ensurepath
# Install the Wikipedia MCP server
pipx install wikipedia-mcp这确保了 wikipedia-mcp 命令在Claude Desktop的PATH中可用。
通过史密瑟里安装
通过以下方式自动安装Claude Desktop的维基百科mcp 铁匠铺:
npx -y @smithery/cli install @Rudra-ravi/wikipedia-mcp --client claude来自PyPI(备选方案)
您也可以直接从PyPI安装:
pip install wikipedia-mcp备注:如果您使用此方法并遇到与Claude Desktop的连接问题,您可能需要在配置中使用该命令的完整路径。看 配置 详情请参阅第节。
使用虚拟环境
# Create a virtual environment
python3 -m venv venv
# Activate the virtual environment
source venv/bin/activate
# Install the package
pip install git+https://github.com/rudra-ravi/wikipedia-mcp.git来源
# Clone the repository
git clone https://github.com/rudra-ravi/wikipedia-mcp.git
cd wikipedia-mcp
# Create a virtual environment
python3 -m venv wikipedia-mcp-env
source wikipedia-mcp-env/bin/activate
# Install in development mode
pip install -e .用法
运行服务器
# If installed with pipx
wikipedia-mcp
# If installed in a virtual environment
source venv/bin/activate
wikipedia-mcp
# Specify transport protocol (default: stdio)
wikipedia-mcp --transport stdio # For Claude Desktop
wikipedia-mcp --transport http --host 0.0.0.0 --port 8080 --path /mcp
wikipedia-mcp --transport streamable-http --host 0.0.0.0 --port 8080 --path /mcp
wikipedia-mcp --transport sse # Legacy compatibility transport
# Specify language (default: en for English)
wikipedia-mcp --language ja # Example for Japanese
wikipedia-mcp --language zh-hans # Example for Simplified Chinese
wikipedia-mcp --language zh-tw # Example for Traditional Chinese (Taiwan)
wikipedia-mcp --language sr-latn # Example for Serbian Latin script
# Specify country/locale (alternative to language codes)
wikipedia-mcp --country US # English (United States)
wikipedia-mcp --country China # Chinese Simplified
wikipedia-mcp --country Taiwan # Chinese Traditional (Taiwan)
wikipedia-mcp --country Japan # Japanese
wikipedia-mcp --country Germany # German
wikipedia-mcp --country france # French (case insensitive)
# List all supported countries
wikipedia-mcp --list-countries
# Optional: Specify host/port/path for network transport (use 0.0.0.0 for containers)
wikipedia-mcp --transport http --host 0.0.0.0 --port 8080 --path /mcp
# Optional: Enable caching
wikipedia-mcp --enable-cache
# Optional: Use Personal Access Token to avoid rate limiting (403 errors)
wikipedia-mcp --access-token your_wikipedia_token_here
# Or set via environment variable
export WIKIPEDIA_ACCESS_TOKEN=your_wikipedia_token_here
wikipedia-mcp
# Optional: Secure incoming MCP network requests with static bearer token
wikipedia-mcp --transport http --auth-mode static --auth-token your_mcp_token --host 0.0.0.0 --port 8080
# Optional: Secure incoming MCP network requests with JWT validation
wikipedia-mcp --transport http --auth-mode jwt --auth-jwks-uri https://issuer/.well-known/jwks.json --auth-issuer https://issuer
# Security note: prefer http/streamable-http + auth-mode for exposed network transport.
# Combine options
wikipedia-mcp --country Taiwan --enable-cache --access-token your_wikipedia_token --transport http --path /mcp --port 8080
### Docker/Kubernetes
When running inside containers, bind the HTTP MCP server to all interfaces and map
the container port to the host or service:
Build and run with Docker
docker build -t wikipedia-mcp . docker run --rm -p 8080:8080 wikipedia-mcp --transport http --host 0.0.0.0 --port 8080 --path /mcp
Kubernetes示例(最小):
apiVersion: apps/v1 kind: Deployment metadata: name: wikipedia-mcp spec: replicas: 1 selector: matchLabels: app: wikipedia-mcp template: metadata: labels: app: wikipedia-mcp spec: containers: - name: server image: your-repo/wikipedia-mcp:latest args: ["--transport", "http", "--host", "0.0.0.0", "--port", "8080", "--path", "/mcp"] ports: - containerPort: 8080
apiVersion: v1 kind: Service metadata: name: wikipedia-mcp spec: selector: app: wikipedia-mcp ports: - name: http port: 8080 targetPort: 8080
Configuration for Claude Desktop
Add the following to your Claude Desktop configuration file:
Option 1: Using command name (requires wikipedia-mcp to be in PATH)
{
"mcpServers": {
"wikipedia": {
"command": "wikipedia-mcp"
}
}
}选项2:使用完整路径(如果您遇到连接错误,建议使用)
{
"mcpServers": {
"wikipedia": {
"command": "/full/path/to/wikipedia-mcp"
}
}
}选项3:有国家/语言规范
{
"mcpServers": {
"wikipedia-us": {
"command": "wikipedia-mcp",
"args": ["--country", "US"]
},
"wikipedia-taiwan": {
"command": "wikipedia-mcp",
"args": ["--country", "TW"]
},
"wikipedia-japan": {
"command": "wikipedia-mcp",
"args": ["--country", "Japan"]
}
}
}要查找完整路径,请运行: which wikipedia-mcp
配置文件位置:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - 窗户:
%APPDATA%/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
备注:如果遇到连接错误,请参阅 故障排除 解决方案部分。
文档索引
- CLI用法和选项:请参阅
docs/CLI.md - API和MCP工具/资源:请参阅
docs/API.md - 架构概述:请参见
docs/ARCHITECTURE.md - 用户指南和故障排除:请参阅
docs/USER_GUIDE.md - 开发指南:见
docs/DEVELOPMENT.md - 测试指南:见
docs/TESTING.md
可用的MCP工具
维基百科MCP服务器为LLM与维基百科交互提供了以下工具:
每个工具还暴露有 wikipedia_-前缀别名(例如, wikipedia_get_article)以提高跨服务器的可发现性。
search_wikipedia
在维基百科中搜索与查询匹配的文章。
参数:
query(string):搜索词limit(整数,可选):返回的最大结果数(默认值:10)
退货:
- 包含标题、片段和元数据的搜索结果列表
get_article
获取维基百科文章的完整内容。
参数:
title(string):维基百科文章的标题
退货:
- 文章内容包括文本、摘要、章节、链接和类别
get_summary
获取维基百科文章的简明摘要。
参数:
title(string):维基百科文章的标题
退货:
- 文章的文本摘要
get_sections
获取维基百科文章的章节。
参数:
title(string):维基百科文章的标题
退货:
- 文章章节及其内容的结构化列表
get_links
获取维基百科文章中包含的链接。
参数:
title(string):维基百科文章的标题
退货:
- 其他维基百科文章的链接列表
get_coordinates
获取维基百科文章的坐标。
参数:
title(string):维基百科文章的标题
退货:
- 一种包含坐标信息的词典,包括:
- title:文章标题 - pageid:页面ID - coordinates:包含纬度、经度和元数据的坐标对象列表 - exists:文章是否存在 - error:如果检索失败,则显示任何错误消息
get_related_topics
根据链接和类别获取与维基百科文章相关的主题。
参数:
title(string):维基百科文章的标题limit(整数,可选):相关主题的最大数量(默认值:10)
退货:
- 包含相关信息的相关主题列表
summarize_article_for_query
获取针对特定查询量身定制的维基百科文章摘要。
参数:
title(string):维基百科文章的标题query(string):用于集中摘要的查询max_length(整数,可选):摘要的最大长度(默认值:250)
退货:
- 包含标题、查询和重点摘要的词典
summarize_article_section
获取维基百科文章特定部分的摘要。
参数:
title(string):维基百科文章的标题section_title(string):要总结的部分的标题max_length(整数,可选):摘要的最大长度(默认值:150)
退货:
- 包含标题、章节标题和章节摘要的词典
extract_key_facts
从维基百科文章中提取关键事实,可以选择关注文章中的特定主题。
参数:
title(string):维基百科文章的标题topic_within_article(字符串,可选):文章中的一个特定主题,用于重点提取事实count(整数,可选):要提取的关键事实数(默认值:5)
退货:
- 包含标题、主题和提取事实列表的词典
国家/地区支持
维基百科MCP服务器支持直观的国家和地区代码,作为语言代码的替代方案。这使得访问特定地区的维基百科内容变得更加容易,而不需要知道语言代码。
支持的国家和地区
使用 --list-countries 查看所有支持的国家:
wikipedia-mcp --list-countries这将显示按语言组织的国家,例如:
Supported Country/Locale Codes:
========================================
en: US, USA, United States, UK, GB, Canada, Australia, ...
zh-hans: CN, China
zh-tw: TW, Taiwan
ja: JP, Japan
de: DE, Germany
fr: FR, France
es: ES, Spain, MX, Mexico, AR, Argentina, ...
pt: PT, Portugal, BR, Brazil
ru: RU, Russia
ar: SA, Saudi Arabia, AE, UAE, EG, Egypt, ...用法示例
# Major countries by code
wikipedia-mcp --country US # United States (English)
wikipedia-mcp --country CN # China (Simplified Chinese)
wikipedia-mcp --country TW # Taiwan (Traditional Chinese)
wikipedia-mcp --country JP # Japan (Japanese)
wikipedia-mcp --country DE # Germany (German)
wikipedia-mcp --country FR # France (French)
wikipedia-mcp --country BR # Brazil (Portuguese)
wikipedia-mcp --country RU # Russia (Russian)
# Countries by full name (case insensitive)
wikipedia-mcp --country "United States"
wikipedia-mcp --country China
wikipedia-mcp --country Taiwan
wikipedia-mcp --country Japan
wikipedia-mcp --country Germany
wikipedia-mcp --country france # Case insensitive
# Regional variants
wikipedia-mcp --country HK # Hong Kong (Traditional Chinese)
wikipedia-mcp --country SG # Singapore (Simplified Chinese)
wikipedia-mcp --country "Saudi Arabia" # Arabic
wikipedia-mcp --country Mexico # Spanish国家到语言映射
服务器会自动将国家代码映射到相应的维基百科语言版本:
- 讲英语:美国、英国、加拿大、澳大利亚、新西兰、爱尔兰、南非→
en - 中国地区:
- CN,中国→ zh-hans (简体中文) - 台湾TW→ zh-tw (繁体中文-台湾) - 香港→ zh-hk (繁体中文-香港) - 新加坡SG→ zh-sg (简体中文-新加坡)
- 主要语言: JP→
ja, DE→de, FR→fr, ES→es, IT→it, RU→ru等等。 - 区域变体:支持140多个国家和地区
错误处理
如果您指定了一个不受支持的国家/地区,您将收到一条有用的错误消息:
$ wikipedia-mcp --country INVALID
Error: Unsupported country/locale: 'INVALID'.
Supported country codes include: US, USA, UK, GB, CA, AU, NZ, IE, ZA, CN.
Use --language parameter for direct language codes instead.
Use --list-countries to see supported country codes.语言变体
维基百科MCP服务器支持具有多种书写系统或地区差异的语言变体。此功能对于中文、塞尔维亚语、库尔德语和其他具有多种文字或地区差异的语言特别有用。
支持的语言变体
汉语变体
zh-hans-简体中文zh-hant-繁体中文zh-tw-繁体中文(台湾)zh-hk-繁体中文(香港)zh-mo-繁体中文(澳门)zh-cn-简体中文(中国)zh-sg-简体中文(新加坡)zh-my-简体中文(马来西亚)
塞尔维亚语变体
sr-latn-塞尔维亚拉丁字母sr-cyrl-塞尔维亚西里尔字母
库尔德语变体
ku-latn-库尔德语拉丁字母ku-arab-库尔德语阿拉伯文字
挪威语变体
no-挪威语(自动映射到博克马尔)
用法示例
# Access Simplified Chinese Wikipedia
wikipedia-mcp --language zh-hans
# Access Traditional Chinese Wikipedia (Taiwan)
wikipedia-mcp --language zh-tw
# Access Serbian Wikipedia in Latin script
wikipedia-mcp --language sr-latn
# Access Serbian Wikipedia in Cyrillic script
wikipedia-mcp --language sr-cyrl语言变体是如何工作的
当您指定一种语言变体时,例如 zh-hans,服务器:
- 将变体映射到基础维基百科语言(例如。,
zh对于中文变体) - 使用基本语言连接到维基百科服务器的API
- 在API请求中包含变体参数以获取特定变体中的内容
- 返回根据指定变量的约定格式化的内容
这种方法确保了与维基百科API的最佳兼容性,同时提供了对各种特定内容和格式的访问。
示例提示
一旦服务器运行并配置了Claude Desktop,您可以使用以下提示:
维基百科的一般查询:
- “使用维基百科信息告诉我量子计算的情况。”
- “根据维基百科总结人工智能的历史。”
- “维基百科对气候变化有什么看法?”
- “查找与机器学习相关的维基百科文章。”
- “给我维基百科上关于神经网络的文章的介绍部分。”
- “埃菲尔铁塔的坐标是多少?”
- “从维基百科上找到珠穆朗玛峰的纬度和经度。”
- “获取巴黎著名地标的坐标信息。”
使用特定国家的维基百科:
- “在维基百科中国搜索有关长城的信息。”(使用中文维基百科)
- “跟我说说日本维基百科上的东京吧。”
- “德语维基百科对柏林墙有什么看法?”
- “从法语维基百科中查找有关埃菲尔铁塔的信息。”
- “获取台湾维基百科关于台湾美食的文章。”
语言变体示例:
- “在繁体中文维基百科上搜索有关台湾的信息。”
- “查找有关现代中国的简体中文文章。”
- “从塞尔维亚语拉丁语维基百科获取有关贝尔格莱德的信息。”
MCP资源
服务器还提供MCP资源(类似于HTTP端点,但用于MCP):
search/{query}:在维基百科中搜索与查询匹配的文章article/{title}:获取维基百科文章的全部内容summary/{title}:获取维基百科文章的摘要sections/{title}:获取维基百科文章的章节links/{title}:获取维基百科文章中的链接coordinates/{title}:获取维基百科文章的坐标summary/{title}/query/{query}/length/{max_length}:获取以查询为中心的文章摘要summary/{title}/section/{section_title}/length/{max_length}:获取特定文章部分的摘要facts/{title}/topic/{topic_within_article}/count/{count}:从文章中提取关键事实
发展
地方发展设置
# Clone the repository
git clone https://github.com/rudra-ravi/wikipedia-mcp.git
cd wikipedia-mcp
# Create a virtual environment
python3 -m venv venv
source venv/bin/activate
# Install the package in development mode
pip install -e .
# Install development and test dependencies
pip install -r requirements-dev.txt
# Run the server
wikipedia-mcp项目结构
wikipedia_mcp/:主包
- __main__.py:包裹的入口点 - server.py:MCP服务器实现 - wikipedia_client.py:维基百科API客户端 - api/:API实现 - core/:核心功能 - utils/:实用功能
tests/:测试套件
- test_basic.py:基本包装测试 - test_cli.py:命令行界面测试 - test_server_tools.py:全面的服务器和工具测试
测试
该项目包括一个全面的测试套件,以确保可靠性和功能性。
测试结构
测试套件按以下方式组织 tests/ 包含以下测试文件的目录:
test_basic.py:基本软件包功能测试test_cli.py:命令行界面和传输测试test_server_tools.py:对所有MCP工具和维基百科客户端功能进行全面测试
运行测试
运行所有测试
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
python -m pytest tests/ -v
# Run tests with coverage
python -m pytest tests/ --cov=wikipedia_mcp --cov-report=html运行特定测试类别
# Run only unit tests (excludes integration tests)
python -m pytest tests/ -v -m "not integration"
# Run only integration tests (requires internet connection)
python -m pytest tests/ -v -m "integration"
# Run specific test file
python -m pytest tests/test_server_tools.py -v测试类别
单元测试
- 维基百科客户端测试:所有客户端方法的基于模拟的测试
- 搜索功能 - 文章检索 - 摘要提取 - 节解析 - 链接提取 - 相关主题发现
- 服务器测试:MCP服务器创建和工具注册
- CLI测试:命令行界面功能
集成测试
- 真正的API测试:对维基百科API进行实际调用的测试
- 端到端测试:完成工作流程测试
测试配置
该项目使用 pytest.ini 对于测试配置:
[pytest]
markers =
integration: marks tests as integration tests (may require network access)
slow: marks tests as slow running
testpaths = tests
addopts = -v --tb=short持续集成
所有测试旨在:
- 在CI/CD环境中可靠运行
- 优雅地处理网络故障
- 提供清晰的错误信息
- 覆盖边缘情况和错误条件
添加新测试
在贡献新功能时:
- 为新功能添加单元测试
- 包括成功和失败的场景
- 模拟外部依赖(维基百科API)
- 添加集成测试以进行端到端验证
- 遵循现有的测试模式和命名约定
故障排除
常见问题
Claude桌面连接问题
问题:Claude Desktop显示以下错误 spawn wikipedia-mcp ENOENT 或者找不到命令。
原因:当 wikipedia-mcp 命令安装在用户特定的位置(如 ~/.local/bin/)这不在Claude Desktop的PATH中。
解决方案:
- 使用命令的完整路径 (推荐):
{
"mcpServers": {
"wikipedia": {
"command": "/home/username/.local/bin/wikipedia-mcp"
}
}
}要找到您的确切路径,请运行: which wikipedia-mcp
- 使用pipx安装以实现全局访问:
pipx install wikipedia-mcp然后使用标准配置:
{
"mcpServers": {
"wikipedia": {
"command": "wikipedia-mcp"
}
}
}- 创建指向全局位置的符号链接:
sudo ln -s ~/.local/bin/wikipedia-mcp /usr/local/bin/wikipedia-mcp其他问题
- 文章未找到:检查文章标题的准确拼写
- 速率限制:维基百科API有费率限制;考虑在请求之间增加延迟
- 大型文章:一些维基百科文章非常大,可能超过令牌限制
搜索问题疑难解答
如果您遇到空的搜索结果,请使用新的诊断工具:
1.测试连接性
使用 test_wikipedia_connectivity 工具来检查您是否可以访问维基百科的API:
{
"tool": "test_wikipedia_connectivity"
}这将返回诊断结果,包括:
- 连接状态(
success或failed) - 响应时间(毫秒)
- 成功时的站点/主机信息
- 连接失败时的错误详细信息
2.增强的搜索错误信息
这 search_wikipedia 工具现在返回详细的元数据:
{
"tool": "search_wikipedia",
"arguments": {
"query": "Ada Lovelace",
"limit": 10
}
}示例响应:
{
"query": "Ada Lovelace",
"results": [...],
"count": 5,
"status": "success",
"language": "en"
}如果未找到结果,您将收到:
{
"query": "nonexistent",
"results": [],
"status": "no_results",
"count": 0,
"language": "en",
"message": "No search results found. This could indicate connectivity issues, API errors, or simply no matching articles."
}3.常见搜索问题及解决方案
- 空结果:运行连接测试,验证查询拼写,尝试更广泛的术语。
- 连接错误:检查防火墙或代理设置,确保
*.wikipedia.org是可达的。 - API限值:请求
limit > 500自动封顶;负值重置为默认值(10)。
4.使用详细日志进行调试
启动带有调试日志的服务器以获得更深入的了解:
wikipedia-mcp --log-level DEBUG这会发出请求参数、响应状态代码以及API返回的任何警告。
理解模型上下文协议(MCP)
模型上下文协议(MCP)不是传统的HTTP API,而是用于LLM与外部工具之间通信的专用协议。主要特征:
- 使用stdio进行本地集成,使用流式HTTP进行网络集成(
sse保留以保持传统兼容性) - 专为AI模型交互而设计
- 为工具、资源和提示提供标准化格式
- 直接与Claude和其他MCP兼容的AI系统集成
Claude Desktop充当MCP客户端,而此服务器提供Claude可以用来访问维基百科信息的工具和资源。
贡献
欢迎投稿!请看 贡献.md 作为指导方针。
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
与作者联系
- 🌐 文件夹: 拉维库马尔诉我
- 📝 博客: 中等
- 💼 领英: in/ravi-kumar-e
- 🐦 推特: @拉维库马尔_d3v

