使用说明
维基百科MCP服务器
一个模型上下文协议(MCP)服务器,通过10个工具提供对维基百科的访问:搜索、检索文章、总结内容、提取事实、获取坐标等。
特性
- 100%测试覆盖率 -31个测试用例,完整的模式验证
- 多语言支持 -访问不同的维基百科版本
- 稳健的错误处理 -优雅的API错误处理
可用工具
| 工具 | 说明 |
|---|---|
search_wikipedia |
搜索与查询匹配的文章 |
get_article |
获取完整的文章内容 |
get_summary |
获取文章摘要 |
summarize_article_for_query |
获取以查询为中心的摘要 |
summarize_article_section |
总结具体章节 |
extract_key_facts |
从文章中提取关键事实 |
get_related_topics |
查找相关文章和类别 |
get_sections |
获取文章结构和章节 |
get_links |
获取文章中的所有链接 |
get_coordinates |
获取地理坐标 |
安装
# Install with uvx
uvx --from git+https://github.com/yourusername/wikipedia-mcp-server wikipedia-mcp-server
# Or local development
git clone https://github.com/yourusername/wikipedia-mcp-server.git
cd wikipedia-mcp-server && uv sync
用法
Claude桌面配置
{
"mcpServers": {
"wikipedia": {
"command": "uvx",
"args": ["--from", "git+https://github.com/yourusername/wikipedia-mcp-server", "wikipedia-mcp-server"]
}
}
}
测试
uv run python test_server.py # 31 tests, 100% pass rate
示例用法
搜索:
{"tool": "search_wikipedia", "arguments": {"query": "AI"}}
获取文章:
{"tool": "get_article", "arguments": {"title": "Python (programming language)"}}
提取事实:
{"tool": "extract_key_facts", "arguments": {"title": "Marie Curie", "topic_within_article": "Nobel Prize"}}
🎯 参数和类型处理规则
此服务器遵循特定的设计模式来处理参数和数据类型,以确保一致性和可预测性。
输入参数设计
模式模式:所有输入参数均标记为 required JSON模式
{
"required": ["title", "query", "max_length"]
}
处理器模式:函数可以有默认值的可选参数
async def summarize_article_for_query(
title: str,
query: str,
max_length: int = 250 # Default provided in handler
) -> Dict[str, Any]:
益处:
- 明确客户期望:MCP客户端必须提供所有记录的参数
- 实施灵活性:处理程序可以在适当的时候使用合理的默认值
- 未来可扩展性:架构可以在不破坏现有实现的情况下进行扩展
输出类型设计
可为空的字段:使用 ["type", "null"] 只有当数据真正不存在时
{
"coordinates": { "type": ["array", "null"] }, // May not exist for non-geographic articles
"pageid": { "type": ["number", "null"] }, // May be null if article doesn't exist
"error": { "type": ["string", "null"] } // Null on success, string on error
}
非空集合:始终返回空数组而不是null
{
"links": { "type": "array" }, // Returns [] if no links found
"facts": { "type": "array" }, // Returns [] if no facts extracted
"sections": { "type": "array" } // Returns [] if no sections found
}
非空字符串:始终返回空字符串而不是null
{
"summary": { "type": "string" }, // Returns "" if no summary available
"text": { "type": "string" }, // Returns "" if no content available
"title": { "type": "string" } // Always present, never null
}
设计原则
- 语义无效性:仅在表示“此数据不存在”而不是“此数据为空”时使用null
- 可预测类型:数组始终是数组,字符串始终是字符串(除非显式可以为null)
- 客户安全:客户端可以安全地迭代数组和连接字符串,而无需进行null检查
- 明确意图:可为空的字段具有明确的语义含义(非位置的坐标、成功时的错误等)
例子
地理数据 (适当时可以为空):
{
"title": "Programming", // Always string
"coordinates": null, // Null - programming isn't a place
"pageid": 12345, // Number when article exists
"error": null // Null on success
}
内容集合 (无数据时为空):
{
"title": "Stub Article", // Always string
"links": [], // Empty array - no links found
"facts": [], // Empty array - no facts extracted
"summary": "" // Empty string - no summary available
}
这种设计确保了所有工具的类型安全、可预测的行为和清晰的语义含义。
发展
依赖项: mcp>=1.6.0, wikipedia-api>=0.6.0, requests>=2.31.0, jsonschema>=4.0.0
# Local development
git clone repo && cd wikipedia-mcp-server
uv sync && uv run python test_server.py
生产准备就绪 维基百科MCP服务器,100%测试覆盖率。