refactor: 项目更名 WeKnora → Academy
Build & Publish (dsh-academy) / End-to-end inside dsh (latest, advisory) (push) Skipped
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Frontend / Docker multi-stage image (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-academy) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-academy) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-academy) / Publish to npm (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Helm / chart (push) Canceled after 0s

- 全量替换代码/配置/文档中的项目名(保留上游 GitHub 链接、weixin 文档域名、Docker Hub 镜像名)
- 重命名 32 个含项目名的文件/目录;Go module 路径改为 academy(含 client/cli 子模块)
- docreader proto 描述符采用等长替换,保持序列化字节布局有效
- Dockerfile.app 构建网络修复: browserskill 离线产物通道、PyPI/apt 国内镜像
- 运行验证: go build ✓ docker compose up ✓ 健康检查 ✓
This commit is contained in:
runny committed 2026-11-13 20:52:51 +08:00
1 parent 9097ee699d
commit 9058149576
3136 files changed
+18018 -18004

No files matched your search

+14 -14
View File
@@ -15,15 +15,15 @@
## [1.1.1] - 2026-07-30
### 变更
- 官方 PyPI 包名改为 **`tencent-weknora-mcp`**(由 Tencent/WeKnora 仓库 CI 通过 Trusted Publishing 发布)。
原社区包 `weknora-mcp` 非官方维护,请迁移安装命令。
- 官方 PyPI 包名改为 **`tencent-academy-mcp`**(由 Tencent/WeKnora 仓库 CI 通过 Trusted Publishing 发布)。
原社区包 `academy-mcp` 非官方维护,请迁移安装命令。
- 项目 URL 指向 [Tencent/WeKnora](https://github.com/Tencent/WeKnora) 官方仓库(`mcp-server/` 目录)。
### 修复
- HTTP 传输恢复 `stateless_http=True`,与迁移前 `StreamableHTTPSessionManager(stateless=True)` 行为一致。
- SSE 传输恢复消息端点 `/sse/messages/`,与迁移前路由一致。
- `WeKnoraClient` 使用线程本地 `requests.Session`,避免 MCP 2.x 在线程池中并发调用时出现 Session 竞态。
- 文件上传(`create_knowledge_from_file`)尊重 `WEKNORA_VERIFY_SSL` 设置。
- `AcademyClient` 使用线程本地 `requests.Session`,避免 MCP 2.x 在线程池中并发调用时出现 Session 竞态。
- 文件上传(`create_knowledge_from_file`)尊重 `ACADEMY_VERIFY_SSL` 设置。
### 注意
- 工具执行失败时,MCPServer 2.x 返回 `CallToolResult(isError=True)`(`ToolError`),
@@ -42,7 +42,7 @@
- 28 个工具重写为 `@mcp.tool()` 函数签名式:输入参数走类型标注(schema 由框架自动生成),
描述走 docstring,返回纯 Python 值由框架序列化。
- 传输层改用 `run_stdio_async()` / `sse_app()` / `streamable_http_app()`,鉴权仍由 `MCPAuthMiddleware` 包裹。
- `WeKnoraClient` 业务逻辑(REST/SSE 调用、resolve_*、wiki)保持不变。
- `AcademyClient` 业务逻辑(REST/SSE 调用、resolve_*、wiki)保持不变。
- 依赖上限调整为 `mcp>=2,<3`(发布包与开发环境一致,避免再次因无上限被解析到未来破坏性版本)。
### 注意
@@ -56,15 +56,15 @@
- 将 `__init__.py` 改为绝对导入,修复 unittest/pytest 收集测试时的包导入错误
### 变更
- PyPI 分发包名统一为 `weknora-mcp`(命令行入口 `weknora-mcp-server` / `weknora-server` 不变)
- PyPI 分发包名统一为 `academy-mcp`(命令行入口 `academy-mcp-server` / `academy-server` 不变)
- 新增 CI workflow(`.github/workflows/mcp-server.yml`),发布 tag 格式为 `mcp-server-v*`
## [1.0.0] - 2024-01-XX
### 新增
- 初始版本发布
- WeKnora MCP Server 核心功能
- 完整的 WeKnora API 集成
- Academy MCP Server 核心功能
- 完整的 Academy API 集成
- 空间管理工具
- 知识库管理工具
- 知识管理工具
@@ -104,12 +104,12 @@
### 文件结构
```
WeKnora/mcp-server/
Academy/mcp-server/
├── __init__.py # 包初始化文件
├── main.py # 主入口点 (推荐)
├── run.py # 便捷启动脚本
├── run_server.py # 原始启动脚本
├── weknora_mcp_server.py # MCP 服务器实现
├── academy_mcp_server.py # MCP 服务器实现
├── test_module.py # 模组测试脚本
├── requirements.txt # 依赖列表
├── setup.py # 安装脚本 (传统)
@@ -125,10 +125,10 @@ WeKnora/mcp-server/
1. `python main.py` - 主入口点 (推荐)
2. `python run_server.py` - 原始启动脚本
3. `python run.py` - 便捷启动脚本
4. `python weknora_mcp_server.py` - 直接运行
5. `python -m weknora_mcp_server` - 模块运行
6. `weknora-mcp-server` - 安装后命令行工具
7. `weknora-server` - 安装后命令行工具 (别名)
4. `python academy_mcp_server.py` - 直接运行
5. `python -m academy_mcp_server` - 模块运行
6. `academy-mcp-server` - 安装后命令行工具
7. `academy-server` - 安装后命令行工具 (别名)
### 技术特性
- 基于 Model Context Protocol (MCP) 1.0.0+
+2 -2
View File
@@ -9,9 +9,9 @@ RUN pip install --no-cache-dir -e .
ENV MCP_HOST=0.0.0.0
ENV MCP_PORT=8000
ENV WEKNORA_BASE_URL=http://app:8080/api/v1
ENV ACADEMY_BASE_URL=http://app:8080/api/v1
# Set MCP_SERVER_AUTH_TOKEN at runtime; HTTP transport refuses to start without it.
EXPOSE 8000
CMD ["weknora-mcp-server", "--transport", "http", "--host", "0.0.0.0", "--port", "8000"]
CMD ["academy-mcp-server", "--transport", "http", "--host", "0.0.0.0", "--port", "8000"]
+12 -12
View File
@@ -1,6 +1,6 @@
# WeKnora MCP Server 使用示例
# Academy MCP Server 使用示例
本文档提供了 WeKnora MCP Server 的详细使用示例。
本文档提供了 Academy MCP Server 的详细使用示例。
## 基本使用
@@ -21,12 +21,12 @@ python main.py --verbose
```bash
# 设置环境变量
export WEKNORA_BASE_URL="http://localhost:8080/api/v1"
export WEKNORA_API_KEY="your_api_key_here"
export ACADEMY_BASE_URL="http://localhost:8080/api/v1"
export ACADEMY_API_KEY="your_api_key_here"
# 或者在 .env 文件中设置
echo "WEKNORA_BASE_URL=http://localhost:8080/api/v1" > .env
echo "WEKNORA_API_KEY=your_api_key_here" >> .env
echo "ACADEMY_BASE_URL=http://localhost:8080/api/v1" > .env
echo "ACADEMY_API_KEY=your_api_key_here" >> .env
```
## MCP 工具使用示例
@@ -350,7 +350,7 @@ python main.py --verbose
```json
{
"error": "Connection refused",
"solution": "检查 WEKNORA_BASE_URL 是否正确,确认服务正在运行"
"solution": "检查 ACADEMY_BASE_URL 是否正确,确认服务正在运行"
}
```
@@ -358,7 +358,7 @@ python main.py --verbose
```json
{
"error": "Unauthorized",
"solution": "检查 WEKNORA_API_KEY 是否设置正确"
"solution": "检查 ACADEMY_API_KEY 是否设置正确"
}
```
@@ -413,12 +413,12 @@ python main.py --verbose
```json
{
"mcpServers": {
"weknora": {
"academy": {
"command": "python",
"args": ["path/to/main.py"],
"env": {
"WEKNORA_BASE_URL": "http://localhost:8080/api/v1",
"WEKNORA_API_KEY": "your_api_key"
"ACADEMY_BASE_URL": "http://localhost:8080/api/v1",
"ACADEMY_API_KEY": "your_api_key"
}
}
}
@@ -435,5 +435,5 @@ python main.py --verbose
如果遇到问题:
1. 运行 `python main.py --check-only` 检查环境
2. 使用 `python main.py --verbose` 查看详细日志
3. 检查 WeKnora 服务是否正常运行
3. 检查 Academy 服务是否正常运行
4. 验证网络连接和防火墙设置
+31 -31
View File
@@ -1,4 +1,4 @@
# WeKnora MCP Server 安装和使用指南
# Academy MCP Server 安装和使用指南
## 快速开始
@@ -10,16 +10,16 @@ pip install -r requirements.txt
### 2. 设置环境变量
```bash
# Linux/macOS
export WEKNORA_BASE_URL="http://localhost:8080/api/v1"
export WEKNORA_API_KEY="your_api_key_here"
export ACADEMY_BASE_URL="http://localhost:8080/api/v1"
export ACADEMY_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"
$env:ACADEMY_BASE_URL="http://localhost:8080/api/v1"
$env:ACADEMY_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
set ACADEMY_BASE_URL=http://localhost:8080/api/v1
set ACADEMY_API_KEY=your_api_key_here
```
### 3. 运行服务器
@@ -38,12 +38,12 @@ python run_server.py
#### 方式 3: 直接运行服务器模块
```bash
python weknora_mcp_server.py
python academy_mcp_server.py
```
#### 方式 4: 作为 Python 模块运行
```bash
python -m weknora_mcp_server
python -m academy_mcp_server
```
## 作为 Python 包安装
@@ -55,9 +55,9 @@ pip install -e .
安装后可以使用命令行工具:
```bash
weknora-mcp-server
academy-mcp-server
# 或
weknora-server
academy-server
```
### 生产模式安装
@@ -94,7 +94,7 @@ python main.py --check-only
```
这将显示:
- WeKnora API 基础 URL 配置
- Academy API 基础 URL 配置
- API 密钥设置状态
- 依赖包安装状态
@@ -107,14 +107,14 @@ python main.py --check-only
- 没有文件名冲突
### 2. 连接错误
如果无法连接到 WeKnora API:
- 检查 `WEKNORA_BASE_URL` 是否正确
- 确认 WeKnora 服务正在运行
如果无法连接到 Academy API:
- 检查 `ACADEMY_BASE_URL` 是否正确
- 确认 Academy 服务正在运行
- 验证网络连接
### 3. 认证错误
如果遇到认证问题:
- 检查 `WEKNORA_API_KEY` 是否设置
- 检查 `ACADEMY_API_KEY` 是否设置
- 确认 API 密钥有效
- 验证权限设置
@@ -122,14 +122,14 @@ python main.py --check-only
### 项目结构
```
WeKnora/mcp-server/
Academy/mcp-server/
├── __init__.py # 包初始化文件
├── main.py # 主入口点
├── run_server.py # 原始启动脚本
├── weknora_mcp_server.py # MCP 服务器实现
├── academy_mcp_server.py # MCP 服务器实现
├── requirements.txt # 依赖列表
├── setup.py # 安装脚本
├── pyproject.toml # 项目元数据(PyPI: tencent-weknora-mcp)
├── pyproject.toml # 项目元数据(PyPI: tencent-academy-mcp)
├── MANIFEST.in # 包含文件清单
├── LICENSE # 许可证
├── README.md # 项目说明
@@ -137,7 +137,7 @@ WeKnora/mcp-server/
```
### 添加新功能
1. 在 `WeKnoraClient` 类中添加新的 API 方法
1. 在 `AcademyClient` 类中添加新的 API 方法
2. 用 `@mcp.tool()` 装饰器注册一个新工具函数:参数用类型标注(schema 自动生成),描述写在 docstring 里,函数体调用上面新增的客户端方法
3. 更新文档和测试
@@ -167,26 +167,26 @@ RUN pip install -r requirements.txt
COPY . .
RUN pip install -e .
ENV WEKNORA_BASE_URL=http://localhost:8080/api/v1
ENV ACADEMY_BASE_URL=http://localhost:8080/api/v1
EXPOSE 8000
CMD ["weknora-mcp-server"]
CMD ["academy-mcp-server"]
```
### 系统服务
创建 systemd 服务文件 `/etc/systemd/system/weknora-mcp.service`:
创建 systemd 服务文件 `/etc/systemd/system/academy-mcp.service`:
```ini
[Unit]
Description=WeKnora MCP Server
Description=Academy MCP Server
After=network.target
[Service]
Type=simple
User=weknora
WorkingDirectory=/opt/weknora-mcp
Environment=WEKNORA_BASE_URL=http://localhost:8080/api/v1
Environment=WEKNORA_API_KEY=your_api_key
ExecStart=/usr/local/bin/weknora-mcp-server
User=academy
WorkingDirectory=/opt/academy-mcp
Environment=ACADEMY_BASE_URL=http://localhost:8080/api/v1
Environment=ACADEMY_API_KEY=your_api_key
ExecStart=/usr/local/bin/academy-mcp-server
Restart=always
[Install]
@@ -195,8 +195,8 @@ WantedBy=multi-user.target
启用服务:
```bash
sudo systemctl enable weknora-mcp
sudo systemctl start weknora-mcp
sudo systemctl enable academy-mcp
sudo systemctl start academy-mcp
```
## 支持
+1 -1
View File
@@ -1,6 +1,6 @@
MIT License
Copyright (c) 2024 WeKnora Team
Copyright (c) 2024 Academy Team
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+18 -18
View File
@@ -1,8 +1,8 @@
# 使用 uv 运行 WeKnora MCP 服务器
# 使用 uv 运行 Academy MCP 服务器
> 更推荐使用`uv`来运行基于python的MCP服务。
>
> 也可通过 PyPI 安装:`pip install tencent-weknora-mcp`,或使用 `uvx --from tencent-weknora-mcp weknora-mcp-server`(官方包名 `tencent-weknora-mcp`,由 [Tencent/WeKnora](https://github.com/Tencent/WeKnora) 维护)。
> 也可通过 PyPI 安装:`pip install tencent-academy-mcp`,或使用 `uvx --from tencent-academy-mcp academy-mcp-server`(官方包名 `tencent-academy-mcp`,由 [Tencent/WeKnora](https://github.com/Tencent/WeKnora) 维护)。
## 1. 安装 uv
@@ -26,17 +26,17 @@ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | ie
```json
{
"mcpServers": {
"weknora": {
"academy": {
"args": [
"--directory",
"/path/WeKnora/mcp-server",
"/path/Academy/mcp-server",
"run",
"run_server.py"
],
"command": "uv",
"env": {
"WEKNORA_API_KEY": "your_api_key_here",
"WEKNORA_BASE_URL": "http://localhost:8080/api/v1"
"ACADEMY_API_KEY": "your_api_key_here",
"ACADEMY_BASE_URL": "http://localhost:8080/api/v1"
}
}
}
@@ -50,17 +50,17 @@ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | ie
```json
{
"mcpServers": {
"weknora": {
"academy": {
"command": "uv",
"args": [
"--directory",
"/path/WeKnora/mcp-server",
"/path/Academy/mcp-server",
"run",
"run_server.py"
],
"env": {
"WEKNORA_API_KEY": "your_api_key_here",
"WEKNORA_BASE_URL": "http://localhost:8080/api/v1"
"ACADEMY_API_KEY": "your_api_key_here",
"ACADEMY_BASE_URL": "http://localhost:8080/api/v1"
}
}
}
@@ -74,17 +74,17 @@ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | ie
```json
{
"mcpServers": {
"weknora": {
"academy": {
"command": "uv",
"args": [
"--directory",
"/path/WeKnora/mcp-server",
"/path/Academy/mcp-server",
"run",
"run_server.py"
],
"env": {
"WEKNORA_API_KEY": "your_api_key_here",
"WEKNORA_BASE_URL": "http://localhost:8080/api/v1"
"ACADEMY_API_KEY": "your_api_key_here",
"ACADEMY_BASE_URL": "http://localhost:8080/api/v1"
}
}
}
@@ -98,17 +98,17 @@ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | ie
```json
{
"mcpServers": {
"weknora": {
"academy": {
"command": "uv",
"args": [
"--directory",
"/path/WeKnora/mcp-server",
"/path/Academy/mcp-server",
"run",
"run_server.py"
],
"env": {
"WEKNORA_API_KEY": "your_api_key_here",
"WEKNORA_BASE_URL": "http://localhost:8080/api/v1"
"ACADEMY_API_KEY": "your_api_key_here",
"ACADEMY_BASE_URL": "http://localhost:8080/api/v1"
}
}
}
+27 -27
View File
@@ -1,4 +1,4 @@
# WeKnora MCP Server 可运行模组包 - 项目总结
# Academy MCP Server 可运行模组包 - 项目总结
## 🎉 项目完成状态
@@ -7,10 +7,10 @@
## 📁 项目结构
```
WeKnora/mcp-server/
Academy/mcp-server/
├── 📦 核心文件
│ ├── __init__.py # 包初始化文件
│ ├── weknora_mcp_server.py # MCP 服务器核心实现
│ ├── academy_mcp_server.py # MCP 服务器核心实现
│ └── requirements.txt # 项目依赖
│
├── 🚀 启动脚本 (多种方式)
@@ -63,25 +63,25 @@ python run.py
### 4. 直接运行服务器
```bash
python weknora_mcp_server.py
python academy_mcp_server.py
```
### 5. 作为模块运行
```bash
python -m weknora_mcp_server
python -m academy_mcp_server
```
### 6. 安装后命令行工具
```bash
pip install -e . # 开发模式安装
weknora-mcp-server # 主命令
weknora-server # 别名命令
academy-mcp-server # 主命令
academy-server # 别名命令
```
### 7. 生产环境安装
```bash
pip install . # 生产安装
weknora-mcp-server # 全局命令
academy-mcp-server # 全局命令
```
## 🔧 环境配置
@@ -89,16 +89,16 @@ weknora-mcp-server # 全局命令
### 必需环境变量
```bash
# Linux/macOS
export WEKNORA_BASE_URL="http://localhost:8080/api/v1"
export WEKNORA_API_KEY="your_api_key_here"
export ACADEMY_BASE_URL="http://localhost:8080/api/v1"
export ACADEMY_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"
$env:ACADEMY_BASE_URL="http://localhost:8080/api/v1"
$env:ACADEMY_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
set ACADEMY_BASE_URL=http://localhost:8080/api/v1
set ACADEMY_API_KEY=your_api_key_here
```
## 🛠️ 功能特性
@@ -130,8 +130,8 @@ set WEKNORA_API_KEY=your_api_key_here
pip install -r requirements.txt
# 2. 设置环境变量
export WEKNORA_BASE_URL="http://localhost:8080/api/v1"
export WEKNORA_API_KEY="your_api_key"
export ACADEMY_BASE_URL="http://localhost:8080/api/v1"
export ACADEMY_API_KEY="your_api_key"
# 3. 启动服务器
python main.py
@@ -140,13 +140,13 @@ python main.py
### 开发模式安装
```bash
pip install -e .
weknora-mcp-server
academy-mcp-server
```
### 生产模式安装
```bash
pip install .
weknora-mcp-server
academy-mcp-server
```
### 构建分发包
@@ -168,7 +168,7 @@ python test_module.py
### 测试结果
```
WeKnora MCP Server 模组测试
Academy MCP Server 模组测试
==================================================
✓ 模块导入测试通过
✓ 环境配置测试通过
@@ -215,7 +215,7 @@ python main.py --verbose
### 2. 生产环境
```bash
pip install .
weknora-mcp-server
academy-mcp-server
```
### 3. Docker 部署
@@ -224,25 +224,25 @@ FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install .
CMD ["weknora-mcp-server"]
CMD ["academy-mcp-server"]
```
### 4. 系统服务
```ini
[Unit]
Description=WeKnora MCP Server
Description=Academy MCP Server
[Service]
ExecStart=/usr/local/bin/weknora-mcp-server
Environment=WEKNORA_BASE_URL=http://localhost:8080/api/v1
ExecStart=/usr/local/bin/academy-mcp-server
Environment=ACADEMY_BASE_URL=http://localhost:8080/api/v1
```
## 🔧 故障排除
### 常见问题
1. **导入错误**: 运行 `pip install -r requirements.txt`
2. **连接错误**: 检查 `WEKNORA_BASE_URL` 设置
3. **认证错误**: 验证 `WEKNORA_API_KEY` 配置
2. **连接错误**: 检查 `ACADEMY_BASE_URL` 设置
3. **认证错误**: 验证 `ACADEMY_API_KEY` 配置
4. **环境检查**: 运行 `python main.py --check-only`
### 调试模式
@@ -273,6 +273,6 @@ python test_module.py # 运行测试
**项目状态**: ✅ 完成并可投入使用
**项目仓库**: https://github.com/Tencent/WeKnora/tree/main/mcp-server
**PyPI 包名**: `tencent-weknora-mcp`
**PyPI 包名**: `tencent-academy-mcp`
**最后更新**: 2025年10月
**版本**: 1.0.0
+19 -19
View File
@@ -1,12 +1,12 @@
# WeKnora MCP Server
# Academy MCP Server
> **⚠️ 已弃用(Deprecated)**
>
> WeKnora 现已内置 MCP Server:在「设置 → 发布与集成 → MCP Server」中为空间创建端点即可,支持多个端点、按端点选择知识库范围和工具,客户端通过 Streamable HTTP 直接连接 `/mcp/<endpoint_id>`,无需再部署本目录的 Python 进程。本目录仅为兼容旧部署保留,后续版本将移除。
> Academy 现已内置 MCP Server:在「设置 → 发布与集成 → MCP Server」中为空间创建端点即可,支持多个端点、按端点选择知识库范围和工具,客户端通过 Streamable HTTP 直接连接 `/mcp/<endpoint_id>`,无需再部署本目录的 Python 进程。本目录仅为兼容旧部署保留,后续版本将移除。
>
> WeKnora now ships a built-in MCP server: create endpoints under "Settings → Publish & Integrations → MCP Server", each with its own token, knowledge-base scope and tool list, and connect clients to `/mcp/<endpoint_id>` over Streamable HTTP. This Python package is kept only for existing deployments and will be removed in a future release.
> Academy now ships a built-in MCP server: create endpoints under "Settings → Publish & Integrations → MCP Server", each with its own token, knowledge-base scope and tool list, and connect clients to `/mcp/<endpoint_id>` over Streamable HTTP. This Python package is kept only for existing deployments and will be removed in a future release.
这是一个 Model Context Protocol (MCP) 服务器,提供对 WeKnora 知识管理 API 的访问。
这是一个 Model Context Protocol (MCP) 服务器,提供对 Academy 知识管理 API 的访问。
## 快速开始
@@ -20,16 +20,16 @@ pip install -r requirements.txt
### 2. 配置环境变量
```bash
# Linux/macOS
export WEKNORA_BASE_URL="http://localhost:8080/api/v1"
export WEKNORA_API_KEY="your_api_key_here"
export ACADEMY_BASE_URL="http://localhost:8080/api/v1"
export ACADEMY_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"
$env:ACADEMY_BASE_URL="http://localhost:8080/api/v1"
$env:ACADEMY_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
set ACADEMY_BASE_URL=http://localhost:8080/api/v1
set ACADEMY_API_KEY=your_api_key_here
```
### 3. 运行服务器
@@ -48,10 +48,10 @@ python run_server.py
python run.py
# 直接运行服务器模块
python weknora_mcp_server.py
python academy_mcp_server.py
# 作为 Python 模块运行
python -m weknora_mcp_server
python -m academy_mcp_server
```
### 4. 命令行选项
@@ -67,14 +67,14 @@ python main.py --version # 显示版本信息
### 从 PyPI 安装
```bash
pip install tencent-weknora-mcp
pip install tencent-academy-mcp
# 或使用 uvx 直接运行(无需预安装)
uvx --from tencent-weknora-mcp weknora-mcp-server
uvx --from tencent-academy-mcp academy-mcp-server
```
> 官方 PyPI 包名为 **`tencent-weknora-mcp`**(Tencent/WeKnora 维护,Trusted Publishing 发布)。
> 旧社区包 `weknora-mcp` 请不要再使用。
> 安装后命令行入口仍为 `weknora-mcp-server` / `weknora-server`。
> 官方 PyPI 包名为 **`tencent-academy-mcp`**(Tencent/WeKnora 维护,Trusted Publishing 发布)。
> 旧社区包 `academy-mcp` 请不要再使用。
> 安装后命令行入口仍为 `academy-mcp-server` / `academy-server`。
### 开发模式安装
```bash
@@ -83,9 +83,9 @@ pip install -e .
安装后可以使用命令行工具:
```bash
weknora-mcp-server
academy-mcp-server
# 或
weknora-server
academy-server
```
### 生产模式安装
+6 -6
View File
@@ -1,14 +1,14 @@
#!/usr/bin/env python3
"""
WeKnora MCP Server Package
Academy MCP Server Package
A Model Context Protocol server that provides access to the WeKnora knowledge management API.
A Model Context Protocol server that provides access to the Academy knowledge management API.
"""
__version__ = "1.1.1"
__author__ = "WeKnora Team"
__description__ = "WeKnora MCP Server - Model Context Protocol server for WeKnora API"
__author__ = "Academy Team"
__description__ = "Academy MCP Server - Model Context Protocol server for Academy API"
from weknora_mcp_server import WeKnoraClient, run
from academy_mcp_server import AcademyClient, run
__all__ = ["WeKnoraClient", "run"]
__all__ = ["AcademyClient", "run"]
@@ -1,8 +1,8 @@
#!/usr/bin/env python3
"""
WeKnora MCP Server
Academy MCP Server
A Model Context Protocol server that provides access to the WeKnora knowledge management API.
A Model Context Protocol server that provides access to the Academy knowledge management API.
"""
import argparse
@@ -28,14 +28,14 @@ logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Configuration - Load from environment variables with defaults
WEKNORA_BASE_URL = os.getenv("WEKNORA_BASE_URL", "http://localhost:8080/api/v1")
WEKNORA_API_KEY = os.getenv("WEKNORA_API_KEY", "")
ACADEMY_BASE_URL = os.getenv("ACADEMY_BASE_URL", "http://localhost:8080/api/v1")
ACADEMY_API_KEY = os.getenv("ACADEMY_API_KEY", "")
# Chat SSE read timeout in seconds. LLM responses can be slow; default 300s.
try:
WEKNORA_CHAT_TIMEOUT = int(os.getenv("WEKNORA_CHAT_TIMEOUT", "300"))
ACADEMY_CHAT_TIMEOUT = int(os.getenv("ACADEMY_CHAT_TIMEOUT", "300"))
except ValueError:
logger.warning("WEKNORA_CHAT_TIMEOUT is not a valid integer; falling back to 300s.")
WEKNORA_CHAT_TIMEOUT = 300
logger.warning("ACADEMY_CHAT_TIMEOUT is not a valid integer; falling back to 300s.")
ACADEMY_CHAT_TIMEOUT = 300
# Bound the data accumulated while waiting for an SSE event's blank line.
MAX_SSE_EVENT_BYTES = 8 * 1024 * 1024
@@ -126,19 +126,19 @@ def _normalize_kb_entries(resp: object) -> list[Dict]:
return out
class WeKnoraClient:
"""Client for interacting with WeKnora API"""
class AcademyClient:
"""Client for interacting with Academy API"""
def __init__(self, base_url: str, api_key: str):
"""Initialize the WeKnora API client with base URL and authentication"""
"""Initialize the Academy API client with base URL and authentication"""
self.base_url = base_url
self.api_key = api_key
# SSL verification: enabled by default. Set WEKNORA_VERIFY_SSL=false to disable
# SSL verification: enabled by default. Set ACADEMY_VERIFY_SSL=false to disable
# (e.g. for self-signed certs in dev environments — NOT recommended for production).
self.verify_ssl = os.getenv("WEKNORA_VERIFY_SSL", "true").lower() != "false"
self.verify_ssl = os.getenv("ACADEMY_VERIFY_SSL", "true").lower() != "false"
if not self.verify_ssl:
logger.warning(
"SSL certificate verification is DISABLED (WEKNORA_VERIFY_SSL=false). "
"SSL certificate verification is DISABLED (ACADEMY_VERIFY_SSL=false). "
"This is insecure and should not be used in production."
)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
@@ -164,7 +164,7 @@ class WeKnoraClient:
return self._session_local.session
def _request(self, method: str, endpoint: str, **kwargs) -> Dict[str, Any]:
"""Make a request to the WeKnora API
"""Make a request to the Academy API
Args:
method: HTTP method (GET, POST, PUT, DELETE)
@@ -503,7 +503,7 @@ class WeKnoraClient:
"""POST to *url* with *body*, consume the SSE stream, and return the assembled result.
Centralised helper used by both chat() and agent_chat().
Timeout: (10s connect, WEKNORA_CHAT_TIMEOUT read) — configurable via env var.
Timeout: (10s connect, ACADEMY_CHAT_TIMEOUT read) — configurable via env var.
Server-Sent Events (SSE) stream format:
data: {"response_type": "answer", "content": "..."}
@@ -515,10 +515,10 @@ class WeKnoraClient:
"""
try:
# POST with stream=True to receive server-sent events incrementally
# Timeout: 10s to establish connection, WEKNORA_CHAT_TIMEOUT for reading response
# Timeout: 10s to establish connection, ACADEMY_CHAT_TIMEOUT for reading response
response = self.session.post(
url, json=body, stream=True,
timeout=(10, WEKNORA_CHAT_TIMEOUT),
timeout=(10, ACADEMY_CHAT_TIMEOUT),
)
answer_chunks: list = []
@@ -678,9 +678,9 @@ class WeKnoraClient:
# Initialize MCP server instance (mcp 2.x high-level API).
# MCPServer (formerly FastMCP) builds input schemas from function type hints
# and serializes plain return values automatically.
mcp = MCPServer("weknora-server", version="1.1.1")
# Initialize WeKnora API client with configuration
client = WeKnoraClient(WEKNORA_BASE_URL, WEKNORA_API_KEY)
mcp = MCPServer("academy-server", version="1.1.1")
# Initialize Academy API client with configuration
client = AcademyClient(ACADEMY_BASE_URL, ACADEMY_API_KEY)
# ---------------------------------------------------------------------------
@@ -702,7 +702,7 @@ def create_tenant(
business: str,
retriever_engines: dict | None = None,
) -> dict:
"""Create a new tenant in WeKnora."""
"""Create a new tenant in Academy."""
engines = retriever_engines or {
"engines": [
{"retriever_type": "keywords", "retriever_engine_type": "postgres"},
@@ -1191,7 +1191,7 @@ def main():
2. MCP_TRANSPORT environment variable
3. Default: stdio
"""
parser = argparse.ArgumentParser(description="WeKnora MCP Server")
parser = argparse.ArgumentParser(description="Academy MCP Server")
parser.add_argument(
"--transport",
choices=["stdio", "sse", "http"],
+15 -15
View File
@@ -1,12 +1,12 @@
#!/usr/bin/env python3
"""
WeKnora MCP Server 主入口点
Academy MCP Server 主入口点
这个文件提供了一个统一的入口点来启动 WeKnora MCP 服务器。
这个文件提供了一个统一的入口点来启动 Academy MCP 服务器。
可以通过多种方式运行:
1. python main.py
2. python -m weknora_mcp_server
3. weknora-mcp-server (安装后)
2. python -m academy_mcp_server
3. academy-mcp-server (安装后)
注意:在 stdio 传输下,stdout 是 JSON-RPC 通道,所有诊断/提示信息必须写入
stderr,否则会破坏 MCP 协议流导致客户端判定"启动失败"。本文件所有 print
@@ -43,18 +43,18 @@ def check_dependencies():
def check_environment_variables():
"""检查环境变量配置"""
base_url = os.getenv("WEKNORA_BASE_URL")
api_key = os.getenv("WEKNORA_API_KEY")
base_url = os.getenv("ACADEMY_BASE_URL")
api_key = os.getenv("ACADEMY_API_KEY")
print("=== WeKnora MCP Server 环境检查 ===", file=sys.stderr)
print("=== Academy MCP Server 环境检查 ===", file=sys.stderr)
print(f"Base URL: {base_url or 'http://localhost:8080/api/v1 (默认)'}", file=sys.stderr)
print(f"API Key: {'已设置' if api_key else '未设置 (警告)'}", file=sys.stderr)
if not base_url:
print("提示: 可以设置 WEKNORA_BASE_URL 环境变量", file=sys.stderr)
print("提示: 可以设置 ACADEMY_BASE_URL 环境变量", file=sys.stderr)
if not api_key:
print("警告: 建议设置 WEKNORA_API_KEY 环境变量", file=sys.stderr)
print("警告: 建议设置 ACADEMY_API_KEY 环境变量", file=sys.stderr)
print("=" * 40, file=sys.stderr)
return True
@@ -63,7 +63,7 @@ def check_environment_variables():
def parse_arguments():
"""解析命令行参数"""
parser = argparse.ArgumentParser(
description="WeKnora MCP Server - Model Context Protocol server for WeKnora API",
description="Academy MCP Server - Model Context Protocol server for Academy API",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
示例:
@@ -72,8 +72,8 @@ def parse_arguments():
python main.py --verbose # 启用详细日志
环境变量:
WEKNORA_BASE_URL WeKnora API 基础 URL (默认: http://localhost:8080/api/v1)
WEKNORA_API_KEY WeKnora API 密钥
ACADEMY_BASE_URL Academy API 基础 URL (默认: http://localhost:8080/api/v1)
ACADEMY_API_KEY Academy API 密钥
MCP_SERVER_AUTH_TOKEN SSE/HTTP 传输必填,客户端通过 Authorization: Bearer 传递
""",
)
@@ -85,7 +85,7 @@ def parse_arguments():
parser.add_argument("--verbose", "-v", action="store_true", help="启用详细日志输出")
parser.add_argument(
"--version", action="version", version="WeKnora MCP Server 1.1.1"
"--version", action="version", version="Academy MCP Server 1.1.1"
)
parser.add_argument(
@@ -136,9 +136,9 @@ async def main():
print("已启用详细日志模式", file=sys.stderr)
try:
print(f"正在启动 WeKnora MCP Server (transport={args.transport})...", file=sys.stderr)
print(f"正在启动 Academy MCP Server (transport={args.transport})...", file=sys.stderr)
from weknora_mcp_server import run_stdio, run_sse, run_http
from academy_mcp_server import run_stdio, run_sse, run_http
# Select transport mode based on CLI argument or MCP_TRANSPORT env var
# - stdio: Default, used by VS Code Copilot for local integration
+9 -9
View File
@@ -3,18 +3,18 @@ requires = ["setuptools>=45", "wheel", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"
[project]
name = "tencent-weknora-mcp"
name = "tencent-academy-mcp"
version = "1.1.1"
description = "WeKnora MCP Server - Model Context Protocol server for WeKnora API"
description = "Academy MCP Server - Model Context Protocol server for Academy API"
readme = "README.md"
license = {text = "MIT"}
authors = [
{name = "WeKnora Team", email = "support@weknora.com"}
{name = "Academy Team", email = "support@academy.com"}
]
maintainers = [
{name = "WeKnora Team", email = "support@weknora.com"}
{name = "Academy Team", email = "support@academy.com"}
]
keywords = ["mcp", "model-context-protocol", "weknora", "knowledge-management", "api-server"]
keywords = ["mcp", "model-context-protocol", "academy", "knowledge-management", "api-server"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
@@ -52,17 +52,17 @@ test = [
[project.urls]
Homepage = "https://github.com/Tencent/WeKnora"
Documentation = "https://docs.weknora.com"
Documentation = "https://docs.academy.com"
Repository = "https://github.com/Tencent/WeKnora/tree/main/mcp-server"
"Bug Reports" = "https://github.com/Tencent/WeKnora/issues"
Changelog = "https://github.com/Tencent/WeKnora/blob/main/mcp-server/CHANGELOG.md"
[project.scripts]
weknora-mcp-server = "main:sync_main"
weknora-server = "run_server:main"
academy-mcp-server = "main:sync_main"
academy-server = "run_server:main"
[tool.setuptools]
py-modules = ["weknora_mcp_server", "upload_paths", "main", "run_server", "run", "test_module"]
py-modules = ["academy_mcp_server", "upload_paths", "main", "run_server", "run", "test_module"]
include-package-data = true
[tool.setuptools.package-data]
+4 -4
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
WeKnora MCP Server 便捷启动脚本
Academy MCP Server 便捷启动脚本
这是一个简化的启动脚本,提供最基本的功能。
对于更多选项,请使用 main.py
@@ -23,10 +23,10 @@ def main():
sys.path.insert(0, str(current_dir))
# 检查环境变量
base_url = os.getenv("WEKNORA_BASE_URL", "http://localhost:8080/api/v1")
api_key = os.getenv("WEKNORA_API_KEY", "")
base_url = os.getenv("ACADEMY_BASE_URL", "http://localhost:8080/api/v1")
api_key = os.getenv("ACADEMY_API_KEY", "")
print("WeKnora MCP Server", file=sys.stderr)
print("Academy MCP Server", file=sys.stderr)
print(f"Base URL: {base_url}", file=sys.stderr)
print(f"API Key: {'已设置' if api_key else '未设置'}", file=sys.stderr)
print("-" * 40, file=sys.stderr)
+8 -8
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
WeKnora MCP Server 启动脚本
Academy MCP Server 启动脚本
注意:在 stdio 传输下,stdout 是 JSON-RPC 通道,所有诊断/提示信息必须写入
stderr,否则会破坏 MCP 协议流导致客户端判定"启动失败"。本脚本所有 print
@@ -14,29 +14,29 @@ import sys
def check_environment():
"""检查环境配置"""
base_url = os.getenv("WEKNORA_BASE_URL")
api_key = os.getenv("WEKNORA_API_KEY")
base_url = os.getenv("ACADEMY_BASE_URL")
api_key = os.getenv("ACADEMY_API_KEY")
if not base_url:
print(
"警告: WEKNORA_BASE_URL 环境变量未设置,使用默认值: http://localhost:8080/api/v1",
"警告: ACADEMY_BASE_URL 环境变量未设置,使用默认值: http://localhost:8080/api/v1",
file=sys.stderr,
)
if not api_key:
print("警告: WEKNORA_API_KEY 环境变量未设置", file=sys.stderr)
print("警告: ACADEMY_API_KEY 环境变量未设置", file=sys.stderr)
print(f"WeKnora Base URL: {base_url or 'http://localhost:8080/api/v1'}", file=sys.stderr)
print(f"Academy Base URL: {base_url or 'http://localhost:8080/api/v1'}", file=sys.stderr)
print(f"API Key: {'已设置' if api_key else '未设置'}", file=sys.stderr)
def main():
"""主函数"""
print("启动 WeKnora MCP Server...", file=sys.stderr)
print("启动 Academy MCP Server...", file=sys.stderr)
check_environment()
try:
from weknora_mcp_server import run
from academy_mcp_server import run
asyncio.run(run())
except ImportError as e:
+10 -10
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
WeKnora MCP Server 安装脚本
Academy MCP Server 安装脚本
"""
from setuptools import setup
@@ -12,7 +12,7 @@ def read_readme():
with open("README.md", "r", encoding="utf-8") as f:
return f.read()
except FileNotFoundError:
return "WeKnora MCP Server - Model Context Protocol server for WeKnora API"
return "Academy MCP Server - Model Context Protocol server for Academy API"
# 读取依赖
@@ -32,15 +32,15 @@ def read_requirements():
setup(
name="tencent-weknora-mcp",
name="tencent-academy-mcp",
version="1.1.1",
author="WeKnora Team",
author_email="support@weknora.com",
description="WeKnora MCP Server - Model Context Protocol server for WeKnora API",
author="Academy Team",
author_email="support@academy.com",
description="Academy MCP Server - Model Context Protocol server for Academy API",
long_description=read_readme(),
long_description_content_type="text/markdown",
url="https://github.com/Tencent/WeKnora/tree/main/mcp-server",
py_modules=["weknora_mcp_server", "upload_paths", "main", "run_server", "run", "test_module"],
py_modules=["academy_mcp_server", "upload_paths", "main", "run_server", "run", "test_module"],
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
@@ -58,13 +58,13 @@ setup(
install_requires=read_requirements(),
entry_points={
"console_scripts": [
"weknora-mcp-server=main:sync_main",
"weknora-server=run_server:main",
"academy-mcp-server=main:sync_main",
"academy-server=run_server:main",
],
},
include_package_data=True,
data_files=[
("", ["README.md", "requirements.txt", "LICENSE"]),
],
keywords="mcp model-context-protocol weknora knowledge-management api-server",
keywords="mcp model-context-protocol academy knowledge-management api-server",
)
+2 -2
View File
@@ -11,7 +11,7 @@ from unittest import mock
import requests
import weknora_mcp_server as srv
import academy_mcp_server as srv
KB_ID = "11111111-1111-1111-1111-111111111111"
SHARED_KB_ID = "22222222-2222-2222-2222-222222222222"
@@ -93,7 +93,7 @@ class ChatAsyncPreflightTest(unittest.IsolatedAsyncioTestCase):
)
self.server_thread.start()
self.addCleanup(self.cleanup_backend)
self.client = srv.WeKnoraClient(
self.client = srv.AcademyClient(
f"http://127.0.0.1:{self.server.server_port}/api/v1", "test-key"
)
new_session = self.client._new_session
+3 -3
View File
@@ -8,12 +8,12 @@ from unittest import mock
import requests
import weknora_mcp_server as srv
import academy_mcp_server as srv
class ChatSSETest(unittest.TestCase):
def setUp(self):
self.client = srv.WeKnoraClient("http://example.test/api/v1", "test-key")
self.client = srv.AcademyClient("http://example.test/api/v1", "test-key")
self.addCleanup(self.client.session.close)
def consume(self, lines, *, agent=False):
@@ -194,7 +194,7 @@ class ChatSSETest(unittest.TestCase):
for status in (400, 503):
for agent in (False, True):
with self.subTest(status=status, agent=agent):
client = srv.WeKnoraClient(
client = srv.AcademyClient(
f"http://127.0.0.1:{port}/{status}", "test-key"
)
client.session.trust_env = False
@@ -8,16 +8,16 @@ python test_create_knowledge_from_text.py
import unittest
from unittest import mock
import weknora_mcp_server as srv
import academy_mcp_server as srv
class CreateKnowledgeFromTextTest(unittest.TestCase):
def test_client_method_exists_and_callable(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
self.assertTrue(callable(getattr(client, "create_knowledge_from_text", None)))
def test_posts_to_manual_endpoint_with_expected_body(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch.object(client, "_request", return_value={"ok": True}) as req:
client.create_knowledge_from_text("kb-1", "T", "C", tag_ids=["t1"])
args, kwargs = req.call_args
@@ -31,13 +31,13 @@ class CreateKnowledgeFromTextTest(unittest.TestCase):
self.assertEqual(body["status"], "publish")
def test_status_can_be_overridden_to_draft(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch.object(client, "_request", return_value={"ok": True}) as req:
client.create_knowledge_from_text("kb-1", "T", "C", status="draft")
self.assertEqual(req.call_args.kwargs["json"]["status"], "draft")
def test_omits_tag_ids_when_none(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch.object(client, "_request", return_value={"ok": True}) as req:
client.create_knowledge_from_text("kb-1", "T", "C")
body = req.call_args.kwargs["json"]
@@ -27,12 +27,12 @@ if "mcp" not in sys.modules:
sys.modules["mcp"] = mcp_pkg
sys.modules["mcp.server"] = mcp_server
import weknora_mcp_server as srv # noqa: E402
import academy_mcp_server as srv # noqa: E402
class CreateKnowledgeFromFileTest(unittest.TestCase):
def test_includes_file_name_in_multipart_when_set(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
payload = b"pdf-bytes"
with mock.patch(
"builtins.open", mock.mock_open(read_data=payload)
@@ -53,7 +53,7 @@ class CreateKnowledgeFromFileTest(unittest.TestCase):
self.assertEqual(data["enable_multimodel"], "true")
def test_omits_file_name_when_empty(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch(
"builtins.open", mock.mock_open(read_data=b"x")
), mock.patch.object(
@@ -71,7 +71,7 @@ class CreateKnowledgeFromFileTest(unittest.TestCase):
class ListKnowledgeFolderTest(unittest.TestCase):
def test_forwards_folder_path_and_scope(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch.object(client, "_request", return_value={"items": []}) as req:
client.list_knowledge(
"kb-1", page=2, page_size=10, folder_path="docs", folder_scope="all"
@@ -83,7 +83,7 @@ class ListKnowledgeFolderTest(unittest.TestCase):
self.assertEqual(params["folder_scope"], "all")
def test_omits_folder_params_when_unset(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch.object(client, "_request", return_value={"items": []}) as req:
client.list_knowledge("kb-1")
params = req.call_args.kwargs["params"]
+9 -9
View File
@@ -14,7 +14,7 @@ MCP_SERVER_DIR = Path(__file__).resolve().parent
class TransportRegressionTest(unittest.TestCase):
def test_http_transport_is_stateless(self):
import weknora_mcp_server as srv
import academy_mcp_server as srv
from mcp.server import MCPServer
probe = MCPServer("probe")
@@ -24,7 +24,7 @@ class TransportRegressionTest(unittest.TestCase):
self.assertTrue(probe.session_manager.stateless)
def test_sse_message_path_matches_legacy_mount(self):
import weknora_mcp_server as srv
import academy_mcp_server as srv
from mcp.server import MCPServer
from starlette.routing import Mount, Route
@@ -41,10 +41,10 @@ class TransportRegressionTest(unittest.TestCase):
{path.rstrip("/") for path in mount_paths},
)
def test_weknora_client_session_is_thread_local(self):
from weknora_mcp_server import WeKnoraClient
def test_academy_client_session_is_thread_local(self):
from academy_mcp_server import AcademyClient
client = WeKnoraClient("http://localhost:8080/api/v1", "test-key")
client = AcademyClient("http://localhost:8080/api/v1", "test-key")
barrier = threading.Barrier(2)
sessions: dict[str, object] = {}
@@ -73,10 +73,10 @@ class StdioToolsListTest(unittest.TestCase):
params = StdioServerParameters(
command=sys.executable,
args=[str(MCP_SERVER_DIR / "weknora_mcp_server.py")],
args=[str(MCP_SERVER_DIR / "academy_mcp_server.py")],
env={
**os.environ,
"WEKNORA_API_KEY": "test-key",
"ACADEMY_API_KEY": "test-key",
},
)
async with stdio_client(params) as (read, write):
@@ -97,12 +97,12 @@ class HttpStatelessSmokeTest(unittest.TestCase):
env = {
**os.environ,
"MCP_SERVER_AUTH_TOKEN": "test-token",
"WEKNORA_API_KEY": "test-key",
"ACADEMY_API_KEY": "test-key",
}
proc = subprocess.Popen(
[
sys.executable,
"weknora_mcp_server.py",
"academy_mcp_server.py",
"--transport",
"http",
"--host",
+15 -15
View File
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
"""
WeKnora MCP Server 模组测试脚本
Academy MCP Server 模组测试脚本
测试模组的各种启动方式和功能。unittest discover 会收集本文件中的 TestCase;
也可直接运行: python test_module.py
@@ -18,7 +18,7 @@ REQUIRED_FILES = [
"__init__.py",
"main.py",
"run_server.py",
"weknora_mcp_server.py",
"academy_mcp_server.py",
"requirements.txt",
"setup.py",
"pyproject.toml",
@@ -33,20 +33,20 @@ class ModuleIntegrationTest(unittest.TestCase):
def test_imports(self):
import mcp # noqa: F401
import requests # noqa: F401
import weknora_mcp_server # noqa: F401
from weknora_mcp_server import WeKnoraClient, run # noqa: F401
import academy_mcp_server # noqa: F401
from academy_mcp_server import AcademyClient, run # noqa: F401
import main # noqa: F401
def test_environment_optional_vars(self):
os.getenv("WEKNORA_BASE_URL")
os.getenv("WEKNORA_API_KEY")
os.getenv("ACADEMY_BASE_URL")
os.getenv("ACADEMY_API_KEY")
def test_client_creation(self):
from weknora_mcp_server import WeKnoraClient
from academy_mcp_server import AcademyClient
base_url = os.getenv("WEKNORA_BASE_URL", "http://localhost:8080/api/v1")
api_key = os.getenv("WEKNORA_API_KEY", "test_key")
client = WeKnoraClient(base_url, api_key)
base_url = os.getenv("ACADEMY_BASE_URL", "http://localhost:8080/api/v1")
api_key = os.getenv("ACADEMY_API_KEY", "test_key")
client = AcademyClient(base_url, api_key)
self.assertEqual(client.base_url, base_url)
self.assertEqual(client.api_key, api_key)
@@ -75,17 +75,17 @@ class ModuleIntegrationTest(unittest.TestCase):
self.assertEqual(result.returncode, 0, result.stderr)
def test_wiki_tools(self):
import weknora_mcp_server
import academy_mcp_server
client = weknora_mcp_server.WeKnoraClient("http://localhost:8080/api/v1", "test")
client = academy_mcp_server.AcademyClient("http://localhost:8080/api/v1", "test")
for method in ["wiki_search", "wiki_read_page", "wiki_index_view"]:
self.assertTrue(hasattr(client, method), f"WeKnoraClient missing: {method}")
self.assertTrue(hasattr(client, method), f"AcademyClient missing: {method}")
self.assertTrue(callable(getattr(client, method)), f"{method} not callable")
def test_pyproject_metadata(self):
text = (MCP_SERVER_DIR / "pyproject.toml").read_text(encoding="utf-8")
self.assertIn("tencent-weknora-mcp", text)
self.assertIn("weknora-mcp-server", text)
self.assertIn("tencent-academy-mcp", text)
self.assertIn("academy-mcp-server", text)
if __name__ == "__main__":
@@ -4,12 +4,12 @@
import unittest
from unittest import mock
import weknora_mcp_server as srv
import academy_mcp_server as srv
class UpdateKnowledgeFromTextTest(unittest.TestCase):
def test_client_puts_manual_update_to_expected_endpoint(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch.object(client, "_request") as req:
req.return_value = {"ok": True}
result = client.update_knowledge_from_text(
@@ -28,7 +28,7 @@ class UpdateKnowledgeFromTextTest(unittest.TestCase):
)
def test_client_can_save_a_draft_and_keep_the_title(self):
client = srv.WeKnoraClient("http://localhost:8080/api/v1", "k")
client = srv.AcademyClient("http://localhost:8080/api/v1", "k")
with mock.patch.object(client, "_request") as req:
req.return_value = {"ok": True}
client.update_knowledge_from_text(
+3 -3
View File
@@ -1,8 +1,8 @@
from weknora_mcp_server import WeKnoraClient
from academy_mcp_server import AcademyClient
def test_resolve_agent_id_accepts_non_uuid_agent_id(monkeypatch):
client = WeKnoraClient("http://example.test/api/v1", "")
client = AcademyClient("http://example.test/api/v1", "")
agents = {
"data": [
{
@@ -20,7 +20,7 @@ def test_resolve_agent_id_accepts_non_uuid_agent_id(monkeypatch):
def test_resolve_agent_id_accepts_agent_name_case_insensitively(monkeypatch):
client = WeKnoraClient("http://example.test/api/v1", "")
client = AcademyClient("http://example.test/api/v1", "")
agents = {
"data": [
{
+3 -3
View File
@@ -1,4 +1,4 @@
from weknora_mcp_server import WeKnoraClient, _normalize_kb_entries
from academy_mcp_server import AcademyClient, _normalize_kb_entries
# Shapes mirror GET /knowledge-bases and GET /shared-knowledge-bases wire JSON.
# See internal/handler/knowledgebase.go (buildKBListResponse) and
@@ -32,7 +32,7 @@ def test_normalize_kb_entries_passes_through_owned_rows():
def test_resolve_kb_id_accepts_shared_kb_name(monkeypatch):
client = WeKnoraClient("http://example.test/api/v1", "")
client = AcademyClient("http://example.test/api/v1", "")
def fake_request(method, path, **kwargs):
if path == "/knowledge-bases":
@@ -58,7 +58,7 @@ def test_resolve_kb_id_accepts_shared_kb_name(monkeypatch):
def test_resolve_kb_id_prefers_owned_over_shared_name(monkeypatch):
client = WeKnoraClient("http://example.test/api/v1", "")
client = AcademyClient("http://example.test/api/v1", "")
def fake_request(method, path, **kwargs):
if path == "/knowledge-bases":
+1 -1
View File
@@ -1503,7 +1503,7 @@ wheels = [
]
[[package]]
name = "tencent-weknora-mcp"
name = "tencent-academy-mcp"
version = "1.1.1"
source = { editable = "." }
dependencies = [