mirror of
https://github.com/Tencent/WeKnora.git
synced 2026-10-30 19:33:05 +08:00
MCP Python SDK 2.0 removed the low-level Server decorator API (@app.list_tools() / @app.call_tool() / app.get_capabilities()), so the server crashed at startup with: AttributeError: 'Server' object has no attribute 'list_tools' The released PyPI package weknora-mcp==1.0.1 declared 'mcp>=1.0.0' with no upper bound, so uvx resolved to the latest 2.0.0 and the plugin's weknora MCP server could no longer connect. Fix: rewrite the server on top of the mcp 2.x high-level MCPServer API (formerly FastMCP), and cap the dependency at 'mcp>=2,<3'. - weknora_mcp_server.py: replace @app.list_tools()/@app.call_tool() with 28 @mcp.tool() function-signature tools (input schema auto-generated from type hints, descriptions from docstrings, plain return values serialized by the framework). Transports use run_stdio_async() / sse_app() / streamable_http_app(). WeKnoraClient business logic is unchanged. - deps: mcp>=2,<3 in pyproject.toml / requirements.txt / setup.py; commit uv.lock pinning mcp 2.0.0. - version bump to 1.1.0 (pyproject, setup, __init__, main --version, server_version). - check_imports.py: validate MCPServer / ToolError / mcp_types imports. - ci(.github/workflows/mcp-server.yml): publish on merge to main + manual dispatch, not only on tags; add PyPI version-dedup check so re-runs on an unchanged version stay green (absorbed from PR #2399). Verified: stdio initialize + tools/list returns all 28 tools; no list_tools AttributeError; tool dispatch + error wrapping confirmed. Co-authored-by: wizardchen <wizardchen@tencent.com>
WeKnora MCP Server
这是一个 Model Context Protocol (MCP) 服务器,提供对 WeKnora 知识管理 API 的访问。
快速开始
推荐直接参考 MCP配置说明,无需进行以下操作。
1. 安装依赖
pip install -r requirements.txt
2. 配置环境变量
# Linux/macOS
export WEKNORA_BASE_URL="http://localhost:8080/api/v1"
export WEKNORA_API_KEY="your_api_key_here"
# Windows PowerShell
$env:WEKNORA_BASE_URL="http://localhost:8080/api/v1"
$env:WEKNORA_API_KEY="your_api_key_here"
# Windows CMD
set WEKNORA_BASE_URL=http://localhost:8080/api/v1
set WEKNORA_API_KEY=your_api_key_here
3. 运行服务器
推荐方式 - 使用主入口点:
python main.py
其他运行方式:
# 使用原始启动脚本
python run_server.py
# 使用便捷脚本
python run.py
# 直接运行服务器模块
python weknora_mcp_server.py
# 作为 Python 模块运行
python -m weknora_mcp_server
4. 命令行选项
python main.py --help # 显示帮助信息
python main.py --check-only # 仅检查环境配置
python main.py --verbose # 启用详细日志
python main.py --version # 显示版本信息
安装为 Python 包
从 PyPI 安装
pip install weknora-mcp
PyPI 包名为
weknora-mcp(请勿与第三方包weknora-mcp-server混淆)。 安装后命令行入口仍为weknora-mcp-server/weknora-server。
开发模式安装
pip install -e .
安装后可以使用命令行工具:
weknora-mcp-server
# 或
weknora-server
生产模式安装
pip install .
构建分发包
# 使用 setuptools
python setup.py sdist bdist_wheel
# 使用现代构建工具
pip install build
python -m build
测试模组
运行测试脚本验证模组是否正常工作:
python test_module.py
功能特性
该 MCP 服务器提供以下工具:
空间管理
create_tenant- 创建新空间list_tenants- 列出所有空间
知识库管理
create_knowledge_base- 创建知识库list_knowledge_bases- 列出知识库get_knowledge_base- 获取知识库详情delete_knowledge_base- 删除知识库hybrid_search- 混合搜索
知识管理
create_knowledge_from_url- 从 URL 创建知识list_knowledge- 列出知识get_knowledge- 获取知识详情delete_knowledge- 删除知识
模型管理
create_model- 创建模型list_models- 列出模型get_model- 获取模型详情
会话管理
create_session- 创建聊天会话get_session- 获取会话详情list_sessions- 列出会话delete_session- 删除会话
聊天功能
chat- 发送聊天消息
块管理
list_chunks- 列出知识块delete_chunk- 删除知识块
故障排除
如果遇到导入错误,请确保:
- 已安装所有必需的依赖包
- Python 版本兼容(推荐 3.10+)
- 没有文件名冲突(避免使用
mcp.py作为文件名)