cls-mcp-server 0.1.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. cls_mcp_server-0.1.7/.dockerignore +51 -0
  2. cls_mcp_server-0.1.7/.env.example +36 -0
  3. cls_mcp_server-0.1.7/.github/workflows/docker-publish.yml +73 -0
  4. cls_mcp_server-0.1.7/.github/workflows/pypi-publish.yml +82 -0
  5. cls_mcp_server-0.1.7/.gitignore +26 -0
  6. cls_mcp_server-0.1.7/PKG-INFO +398 -0
  7. cls_mcp_server-0.1.7/README.md +372 -0
  8. cls_mcp_server-0.1.7/deploy/docker/Dockerfile +63 -0
  9. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/Chart.yaml +13 -0
  10. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/templates/_helpers.tpl +29 -0
  11. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/templates/configmap.yaml +15 -0
  12. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/templates/deployment.yaml +62 -0
  13. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/templates/hpa.yaml +32 -0
  14. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/templates/ingress.yaml +41 -0
  15. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/templates/secret.yaml +15 -0
  16. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/templates/service.yaml +18 -0
  17. cls_mcp_server-0.1.7/deploy/helm/cls-mcp-server/values.yaml +104 -0
  18. cls_mcp_server-0.1.7/deploy/kubernetes/configmap.yaml +17 -0
  19. cls_mcp_server-0.1.7/deploy/kubernetes/deployment.yaml +58 -0
  20. cls_mcp_server-0.1.7/deploy/kubernetes/ingress.yaml +31 -0
  21. cls_mcp_server-0.1.7/deploy/kubernetes/secret.yaml +16 -0
  22. cls_mcp_server-0.1.7/deploy/kubernetes/service.yaml +21 -0
  23. cls_mcp_server-0.1.7/deploy/systemd/cls-mcp-server.env +35 -0
  24. cls_mcp_server-0.1.7/deploy/systemd/cls-mcp-server.service +45 -0
  25. cls_mcp_server-0.1.7/deploy/systemd/install.sh +791 -0
  26. cls_mcp_server-0.1.7/deploy/systemd/uninstall.sh +134 -0
  27. cls_mcp_server-0.1.7/docker-compose.yaml +37 -0
  28. cls_mcp_server-0.1.7/docs/deployment-guide.md +1263 -0
  29. cls_mcp_server-0.1.7/pyproject.toml +53 -0
  30. cls_mcp_server-0.1.7/src/cls_mcp_server/__init__.py +3 -0
  31. cls_mcp_server-0.1.7/src/cls_mcp_server/__main__.py +134 -0
  32. cls_mcp_server-0.1.7/src/cls_mcp_server/auth.py +72 -0
  33. cls_mcp_server-0.1.7/src/cls_mcp_server/config.py +121 -0
  34. cls_mcp_server-0.1.7/src/cls_mcp_server/middleware.py +94 -0
  35. cls_mcp_server-0.1.7/src/cls_mcp_server/server.py +158 -0
  36. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/__init__.py +4 -0
  37. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/_state.py +34 -0
  38. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/alarm.py +877 -0
  39. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/data_transform.py +172 -0
  40. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/metrics.py +186 -0
  41. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/registry.py +129 -0
  42. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/resource.py +801 -0
  43. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/scheduled_sql.py +188 -0
  44. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/search.py +430 -0
  45. cls_mcp_server-0.1.7/src/cls_mcp_server/tools/time_utils.py +244 -0
  46. cls_mcp_server-0.1.7/src/cls_mcp_server/utils/__init__.py +1 -0
  47. cls_mcp_server-0.1.7/src/cls_mcp_server/utils/errors.py +150 -0
  48. cls_mcp_server-0.1.7/src/cls_mcp_server/utils/formatter.py +117 -0
  49. cls_mcp_server-0.1.7/src/cls_mcp_server/utils/validators.py +263 -0
  50. cls_mcp_server-0.1.7/tests/conftest.py +106 -0
  51. cls_mcp_server-0.1.7/tests/test_search_tools_e2e.py +537 -0
  52. cls_mcp_server-0.1.7/tests/test_time_utils.py +249 -0
  53. cls_mcp_server-0.1.7/tests/test_validators.py +173 -0
  54. cls_mcp_server-0.1.7/tests/test_validators_v2.py +364 -0
  55. cls_mcp_server-0.1.7/uv.lock +1004 -0
@@ -0,0 +1,51 @@
1
+ # Git
2
+ .git
3
+ .gitignore
4
+
5
+ # Python
6
+ __pycache__
7
+ *.pyc
8
+ *.pyo
9
+ *.egg-info
10
+ .eggs
11
+ dist
12
+ build
13
+
14
+ # Virtual environments
15
+ .venv
16
+ venv
17
+ env
18
+
19
+ # IDE
20
+ .vscode
21
+ .idea
22
+ *.swp
23
+ *.swo
24
+
25
+ # Testing
26
+ tests
27
+ .pytest_cache
28
+ .coverage
29
+ htmlcov
30
+
31
+ # Documentation
32
+ docs
33
+
34
+ # CI/CD
35
+ .github
36
+
37
+ # Environment files (secrets should be injected at runtime)
38
+ .env
39
+ .env.local
40
+
41
+ # Deploy configs (not needed inside container)
42
+ deploy
43
+
44
+ # Other
45
+ *.md
46
+ !README.md
47
+ LICENSE
48
+ .codebuddy
49
+ cls-search-log-test
50
+ *.tar.gz
51
+ 需求大纲
@@ -0,0 +1,36 @@
1
+ # 腾讯云 CLS MCP Server 配置
2
+ # ==============================
3
+
4
+ # [必填] 腾讯云 API 密钥
5
+ CLS_SECRET_ID=your-secret-id-here
6
+ CLS_SECRET_KEY=your-secret-key-here
7
+
8
+ # [必填] 地域,默认 ap-guangzhou
9
+ CLS_REGION=ap-guangzhou
10
+
11
+ # [可选] 传输方式: stdio | sse | streamable-http,默认 stdio
12
+ CLS_TRANSPORT=stdio
13
+
14
+ # [可选] HTTP 监听端口(SSE/Streamable HTTP 模式),默认 8000
15
+ # 向后兼容 CLS_SSE_PORT
16
+ CLS_PORT=8000
17
+
18
+ # [可选] HTTP 监听地址(SSE/Streamable HTTP 模式),默认 0.0.0.0
19
+ # 向后兼容 CLS_SSE_HOST
20
+ CLS_HOST=0.0.0.0
21
+
22
+ # [可选] Streamable HTTP 无状态模式,推荐 K8s 部署时开启,默认 true
23
+ CLS_STATELESS_HTTP=true
24
+
25
+ # [可选] 权限控制
26
+ # 设置为 true 开启写操作工具(创建、修改)
27
+ CLS_ENABLE_WRITE=false
28
+ # 设置为 true 开启高危操作工具(删除)
29
+ CLS_ENABLE_DANGEROUS=false
30
+
31
+ # [可选] HTTP Bearer Token 认证(SSE/Streamable HTTP 模式)
32
+ # 设置后,客户端请求需带 Authorization: Bearer <token> 头
33
+ # MCP_AUTH_TOKEN=your-secret-token-here
34
+
35
+ # [可选] 日志级别: DEBUG | INFO | WARNING | ERROR
36
+ CLS_LOG_LEVEL=INFO
@@ -0,0 +1,73 @@
1
+ # ============================================================
2
+ # Docker 镜像自动构建与推送工作流
3
+ # ============================================================
4
+ # 触发条件:推送以 v 开头的 Tag(如 v0.1.0、v1.0.0)
5
+ #
6
+ # 推送到 GitHub Container Registry (ghcr.io),免费且无需额外账号。
7
+ #
8
+ # GHCR(GitHub Container Registry):
9
+ # - 无需额外配置,使用 GITHUB_TOKEN 自动认证
10
+ # ============================================================
11
+
12
+ name: Build and Push Docker Image
13
+
14
+ on:
15
+ push:
16
+ tags:
17
+ - "v*"
18
+
19
+ env:
20
+ # GHCR 镜像名(自动根据仓库名生成)
21
+ GHCR_IMAGE: ghcr.io/${{ github.repository }}
22
+
23
+ jobs:
24
+ build-and-push:
25
+ name: Build & Push Docker Image
26
+ runs-on: ubuntu-latest
27
+ permissions:
28
+ contents: read
29
+ packages: write # 推送到 GHCR 需要此权限
30
+
31
+ steps:
32
+ - name: Checkout code
33
+ uses: actions/checkout@v4
34
+
35
+ - name: Docker Logout
36
+ run: docker logout || true
37
+
38
+ - name: Set up Docker Buildx
39
+ uses: docker/setup-buildx-action@v3
40
+
41
+ # 登录 GHCR
42
+ - name: Login to GitHub Container Registry
43
+ uses: docker/login-action@v3
44
+ with:
45
+ registry: ghcr.io
46
+ username: ${{ github.actor }}
47
+ password: ${{ secrets.GITHUB_TOKEN }}
48
+
49
+ # 提取版本标签
50
+ - name: Extract metadata (tags, labels)
51
+ id: meta
52
+ uses: docker/metadata-action@v5
53
+ with:
54
+ images: |
55
+ ${{ env.GHCR_IMAGE }}
56
+ tags: |
57
+ # v1.0.0 -> 1.0.0, latest
58
+ type=semver,pattern={{version}}
59
+ type=semver,pattern={{major}}.{{minor}}
60
+ type=raw,value=latest,enable={{is_default_branch}}
61
+
62
+ # 构建并推送(多平台)
63
+ - name: Build and Push
64
+ uses: docker/build-push-action@v6
65
+ with:
66
+ context: .
67
+ file: deploy/docker/Dockerfile
68
+ push: true
69
+ platforms: linux/amd64,linux/arm64
70
+ tags: ${{ steps.meta.outputs.tags }}
71
+ labels: ${{ steps.meta.outputs.labels }}
72
+ cache-from: type=gha
73
+ cache-to: type=gha,mode=max
@@ -0,0 +1,82 @@
1
+ # ============================================================
2
+ # PyPI 自动发布工作流
3
+ # ============================================================
4
+ # 触发条件:推送以 v 开头的 Tag(如 v0.1.0、v1.0.0)
5
+ # 前提:需要在 GitHub 仓库 Settings > Secrets 中配置 PYPI_API_TOKEN
6
+ #
7
+ # 获取 PyPI Token 步骤:
8
+ # 1. 注册 https://pypi.org 账号
9
+ # 2. 进入 Account Settings > API tokens
10
+ # 3. 创建 token(Scope 选 Entire account 或指定项目)
11
+ # 4. 复制 token,到 GitHub 仓库 Settings > Secrets and variables > Actions
12
+ # 5. 点 "New repository secret",Name 填 PYPI_API_TOKEN,Value 粘贴 token
13
+ # ============================================================
14
+
15
+ name: Publish to PyPI
16
+
17
+ on:
18
+ push:
19
+ tags:
20
+ - "v*"
21
+
22
+ jobs:
23
+ build-and-publish:
24
+ name: Build & Publish to PyPI
25
+ runs-on: ubuntu-latest
26
+ # 推荐:使用 GitHub 的 Trusted Publisher(OIDC),更安全
27
+ # 如果配置了 Trusted Publisher,可以去掉 password,改用 permissions
28
+ permissions:
29
+ contents: read
30
+ id-token: write # 用于 Trusted Publisher(可选)
31
+
32
+ steps:
33
+ - name: Checkout code
34
+ uses: actions/checkout@v4
35
+
36
+ - name: Set up Python
37
+ uses: actions/setup-python@v5
38
+ with:
39
+ python-version: "3.12"
40
+
41
+ - name: Install build tools
42
+ run: pip install build
43
+
44
+ - name: Extract version from tag
45
+ id: version
46
+ run: |
47
+ TAG="${GITHUB_REF#refs/tags/v}"
48
+ echo "version=$TAG" >> "$GITHUB_OUTPUT"
49
+ echo "Building version: $TAG"
50
+
51
+ - name: Verify version consistency
52
+ run: |
53
+ TAG_VERSION="${{ steps.version.outputs.version }}"
54
+ PKG_VERSION=$(python -c "
55
+ import tomllib
56
+ with open('pyproject.toml', 'rb') as f:
57
+ data = tomllib.load(f)
58
+ print(data['project']['version'])
59
+ ")
60
+ echo "Tag version: $TAG_VERSION"
61
+ echo "Package version: $PKG_VERSION"
62
+ if [ "$TAG_VERSION" != "$PKG_VERSION" ]; then
63
+ echo "::error::Version mismatch! Tag=$TAG_VERSION, pyproject.toml=$PKG_VERSION"
64
+ exit 1
65
+ fi
66
+
67
+ - name: Build package
68
+ run: python -m build
69
+
70
+ - name: Verify build artifacts
71
+ run: |
72
+ ls -la dist/
73
+ pip install dist/*.whl
74
+ cls-mcp-server --help
75
+
76
+ # 方式一:使用 API Token(推荐新手使用)
77
+ - name: Publish to PyPI
78
+ uses: pypa/gh-action-pypi-publish@release/v1
79
+ with:
80
+ password: ${{ secrets.PYPI_API_TOKEN }}
81
+ # 首次发布前,可先发到 TestPyPI 验证:
82
+ # repository-url: https://test.pypi.org/legacy/
@@ -0,0 +1,26 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+ *.egg-info/
5
+ dist/
6
+ build/
7
+ .eggs/
8
+ *.egg
9
+ .env
10
+ .venv/
11
+ venv/
12
+ .mypy_cache/
13
+ .ruff_cache/
14
+ .pytest_cache/
15
+ *.log
16
+ .DS_Store
17
+ .idea/
18
+ .vscode/
19
+ .codebuddy/
20
+
21
+ # 打包产物
22
+ *.tar.gz
23
+
24
+ # 临时文件
25
+ 需求大纲
26
+ cls-search-log-test/
@@ -0,0 +1,398 @@
1
+ Metadata-Version: 2.4
2
+ Name: cls-mcp-server
3
+ Version: 0.1.7
4
+ Summary: 腾讯云 CLS 日志服务 MCP Server - 从可观测性视角为 AI 助手提供全方位日志服务能力
5
+ Project-URL: Homepage, https://github.com/Tinker-LGD2026/cls-mcp-server
6
+ Project-URL: Repository, https://github.com/Tinker-LGD2026/cls-mcp-server
7
+ Project-URL: Issues, https://github.com/Tinker-LGD2026/cls-mcp-server/issues
8
+ Author: tinkerli
9
+ License: Apache-2.0
10
+ Keywords: cls,log-service,mcp,observability,tencent-cloud
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: System :: Logging
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: httpx>=0.27.0
21
+ Requires-Dist: mcp[cli]>=1.0.0
22
+ Requires-Dist: python-dotenv>=1.0.0
23
+ Requires-Dist: tencentcloud-sdk-python-cls>=1.0.0
24
+ Requires-Dist: tencentcloud-sdk-python-region>=3.0.0
25
+ Description-Content-Type: text/markdown
26
+
27
+ # CLS MCP Server
28
+
29
+ 腾讯云日志服务(Cloud Log Service)MCP Server —— 从可观测性视角为 AI 助手提供全方位日志服务能力。
30
+
31
+ ## 功能特性
32
+
33
+ - **日志查询分析**:CQL 检索 + SQL 管道分析、上下文查看、直方图、日志计数
34
+ - **指标查询**:PromQL 兼容的单时间点/时间范围指标查询
35
+ - **告警管理**:告警策略/通知渠道/告警记录查询与管理
36
+ - **资源管理**:日志集、日志主题、索引、机器组、仪表盘的增删改查
37
+ - **数据加工 & 定时 SQL**:数据加工任务和定时 SQL 任务管理
38
+ - **三级权限控制**:READ(默认)/ WRITE / DANGER 分级保护
39
+
40
+ 共 **37 个工具**,覆盖 CLS 日志服务的完整能力。
41
+
42
+ ## 工具清单
43
+
44
+ ### 日志检索(5 个)
45
+
46
+ | 工具名称 | 功能说明 | 权限 |
47
+ |---------|---------|------|
48
+ | `cls_search_log` | 检索分析 CLS 日志,支持 CQL 语法检索和 SQL 管道分析 | 只读 |
49
+ | `cls_get_log_context` | 获取日志上下文,查看目标日志前后的记录 | 只读 |
50
+ | `cls_get_log_histogram` | 获取日志数量直方图,观察日志量随时间的分布 | 只读 |
51
+ | `cls_get_log_count` | 快速获取日志数量,比 search_log 更快 | 只读 |
52
+ | `cls_describe_search_syntax` | 获取 CLS 日志检索语法参考和常用查询模板 | 只读 |
53
+
54
+ ### 指标查询(3 个)
55
+
56
+ | 工具名称 | 功能说明 | 权限 |
57
+ |---------|---------|------|
58
+ | `cls_query_metric` | 查询指标数据(单时间点),支持 PromQL 语法 | 只读 |
59
+ | `cls_query_range_metric` | 查询指标数据(时间范围),获取指标变化趋势 | 只读 |
60
+ | `cls_list_metrics` | 列出指标主题下的所有可用指标名称 | 只读 |
61
+
62
+ ### 告警管理(8 个)
63
+
64
+ | 工具名称 | 功能说明 | 权限 |
65
+ |---------|---------|------|
66
+ | `cls_describe_alarms` | 查询告警策略列表,支持分页和过滤 | 只读 |
67
+ | `cls_describe_alarm_detail` | 根据告警策略 ID 获取完整告警配置 | 只读 |
68
+ | `cls_describe_alarm_notices` | 查询告警通知渠道列表(邮件、短信、回调等) | 只读 |
69
+ | `cls_describe_alarm_records` | 查询告警历史触发记录 | 只读 |
70
+ | `cls_get_alarm_detail` | 通过告警详情 URL 获取告警详细信息 | 只读 |
71
+ | `cls_create_alarm` | 创建告警策略 | ⚠️ 写入 |
72
+ | `cls_modify_alarm` | 修改告警策略配置 | ⚠️ 写入 |
73
+ | `cls_delete_alarm` | 删除告警策略(不可恢复) | 🚨 危险 |
74
+
75
+ ### 资源管理(14 个)
76
+
77
+ | 工具名称 | 功能说明 | 权限 |
78
+ |---------|---------|------|
79
+ | `cls_describe_logsets` | 查询日志集列表 | 只读 |
80
+ | `cls_describe_topics` | 查询日志主题列表 | 只读 |
81
+ | `cls_describe_topic_detail` | 获取日志主题详细配置 | 只读 |
82
+ | `cls_describe_index` | 查询日志主题的索引配置 | 只读 |
83
+ | `cls_describe_machine_groups` | 查询机器组列表 | 只读 |
84
+ | `cls_describe_machine_group_detail` | 获取机器组详情和机器在线状态 | 只读 |
85
+ | `cls_describe_dashboards` | 查询仪表盘列表 | 只读 |
86
+ | `cls_describe_regions` | 查询 CLS 支持的地域列表 | 只读 |
87
+ | `cls_create_logset` | 创建日志集 | ⚠️ 写入 |
88
+ | `cls_create_topic` | 创建日志主题 | ⚠️ 写入 |
89
+ | `cls_modify_topic` | 修改日志主题配置 | ⚠️ 写入 |
90
+ | `cls_modify_index` | 修改日志主题的索引配置 | ⚠️ 写入 |
91
+ | `cls_delete_logset` | 删除日志集(不可恢复) | 🚨 危险 |
92
+ | `cls_delete_topic` | 删除日志主题及所有日志数据(不可恢复) | 🚨 危险 |
93
+
94
+ ### 数据加工(3 个)
95
+
96
+ | 工具名称 | 功能说明 | 权限 |
97
+ |---------|---------|------|
98
+ | `cls_describe_data_transform_tasks` | 查询数据加工任务列表 | 只读 |
99
+ | `cls_create_data_transform` | 创建数据加工任务 | ⚠️ 写入 |
100
+ | `cls_delete_data_transform` | 删除数据加工任务 | 🚨 危险 |
101
+
102
+ ### 定时 SQL(3 个)
103
+
104
+ | 工具名称 | 功能说明 | 权限 |
105
+ |---------|---------|------|
106
+ | `cls_describe_scheduled_sql_tasks` | 查询定时 SQL 任务列表 | 只读 |
107
+ | `cls_create_scheduled_sql` | 创建定时 SQL 分析任务 | ⚠️ 写入 |
108
+ | `cls_delete_scheduled_sql` | 删除定时 SQL 任务 | 🚨 危险 |
109
+
110
+ ### 时间工具(1 个)
111
+
112
+ | 工具名称 | 功能说明 | 权限 |
113
+ |---------|---------|------|
114
+ | `cls_convert_time` | 时间与时间戳互转,避免手动计算出错 | 只读 |
115
+
116
+ > **权限说明**:只读工具默认启用;⚠️ 写入工具需设置 `CLS_ENABLE_WRITE=true`;🚨 危险工具需同时设置 `CLS_ENABLE_WRITE=true` 和 `CLS_ENABLE_DANGEROUS=true`。
117
+
118
+ ## 快速开始
119
+
120
+ 先确认你的使用场景,选择对应章节:
121
+
122
+ | 场景 | 说明 | 跳转 |
123
+ |------|------|------|
124
+ | **本地使用** | 在自己电脑上配合 Claude Desktop / Cursor / VS Code 等 IDE 使用 | [场景一:本地 stdio 模式](#场景一本地-stdio-模式) |
125
+ | **远程服务** | 部署到服务器,团队共用或远程访问 | [场景二:远程服务模式](#场景二远程服务模式) |
126
+
127
+ ---
128
+
129
+ ### 环境准备
130
+
131
+ #### 1. 安装 uv(Python 包管理器)
132
+
133
+ [uv](https://docs.astral.sh/uv/) 是一个极快的 Python 包管理器,本项目推荐使用。如已安装可跳过。
134
+
135
+ ```bash
136
+ # macOS / Linux
137
+ curl -LsSf https://astral.sh/uv/install.sh | sh
138
+
139
+ # 安装完成后,让命令生效(二选一):
140
+ source $HOME/.local/bin/env # 立即生效
141
+ # 或者关闭终端重新打开 # 重启终端也行
142
+ ```
143
+
144
+ ```powershell
145
+ # Windows (PowerShell)
146
+ powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
147
+ ```
148
+
149
+ 验证安装成功:
150
+
151
+ ```bash
152
+ uv --version
153
+ # 预期输出: uv 0.11.x(版本号可能不同)
154
+ ```
155
+
156
+ > **没有 uv?** 也可以用 `pip install cls-mcp-server` 安装,但 uv 更快且能自动管理 Python 版本。
157
+
158
+ #### 2. 获取腾讯云密钥
159
+
160
+ 访问 [腾讯云控制台 - API 密钥管理](https://console.cloud.tencent.com/cam/capi),获取 `SecretId` 和 `SecretKey`。
161
+
162
+ ---
163
+
164
+ ### 场景一:本地 stdio 模式
165
+
166
+ 适合在自己电脑上使用,MCP 客户端(Claude Desktop / Cursor 等)自动拉起 Server 进程,无需手动启动服务。
167
+
168
+ #### 第一步:配置 MCP 客户端
169
+
170
+ 选择你使用的客户端,将以下配置写入对应的配置文件:
171
+
172
+ <details>
173
+ <summary><b>Claude Desktop</b></summary>
174
+
175
+ 配置文件位置:
176
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
177
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
178
+
179
+ ```json
180
+ {
181
+ "mcpServers": {
182
+ "cls": {
183
+ "command": "uvx",
184
+ "args": ["cls-mcp-server"],
185
+ "env": {
186
+ "CLS_SECRET_ID": "替换为你的SecretId",
187
+ "CLS_SECRET_KEY": "替换为你的SecretKey",
188
+ "CLS_REGION": "ap-guangzhou"
189
+ }
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ </details>
196
+
197
+ <details>
198
+ <summary><b>Cursor</b></summary>
199
+
200
+ 配置文件位置:`~/.cursor/mcp.json`
201
+
202
+ ```json
203
+ {
204
+ "mcpServers": {
205
+ "cls": {
206
+ "command": "uvx",
207
+ "args": ["cls-mcp-server"],
208
+ "env": {
209
+ "CLS_SECRET_ID": "替换为你的SecretId",
210
+ "CLS_SECRET_KEY": "替换为你的SecretKey",
211
+ "CLS_REGION": "ap-guangzhou"
212
+ }
213
+ }
214
+ }
215
+ }
216
+ ```
217
+
218
+ </details>
219
+
220
+ <details>
221
+ <summary><b>VS Code (Copilot)</b></summary>
222
+
223
+ 在 VS Code 的 `settings.json` 中添加:
224
+
225
+ ```json
226
+ {
227
+ "mcp": {
228
+ "servers": {
229
+ "cls": {
230
+ "command": "uvx",
231
+ "args": ["cls-mcp-server"],
232
+ "env": {
233
+ "CLS_SECRET_ID": "替换为你的SecretId",
234
+ "CLS_SECRET_KEY": "替换为你的SecretKey",
235
+ "CLS_REGION": "ap-guangzhou"
236
+ }
237
+ }
238
+ }
239
+ }
240
+ }
241
+ ```
242
+
243
+ </details>
244
+
245
+ > **说明**:`uvx` 会自动从 PyPI 下载并运行 `cls-mcp-server`,无需手动 `pip install`。`CLS_REGION` 改为你的日志所在地域(如 `ap-shanghai`、`ap-beijing`)。
246
+
247
+ #### 第二步:重启客户端
248
+
249
+ 保存配置后,**重启** Claude Desktop / Cursor / VS Code,客户端会自动拉起 CLS MCP Server。
250
+
251
+ #### 第三步:验证
252
+
253
+ 在客户端中发送一条消息测试:
254
+
255
+ ```
256
+ 帮我查看 CLS 支持哪些地域
257
+ ```
258
+
259
+ 如果返回了地域列表(广州、上海、北京等),说明连接成功。
260
+
261
+ #### 其他安装方式
262
+
263
+ 如果不想用 `uvx`,也可以手动安装后在配置中使用 `cls-mcp-server` 命令:
264
+
265
+ ```bash
266
+ # 方式一:pip 安装(适合已有 pip 工作流的用户)
267
+ pip install cls-mcp-server
268
+
269
+ # 方式二:源码安装(适合需要修改源码的开发者)
270
+ git clone https://github.com/Tinker-LGD2026/cls-mcp-server.git
271
+ cd cls-mcp-server
272
+ uv sync
273
+ # 验证: uv run cls-mcp-server --help
274
+ ```
275
+
276
+ 使用 `pip install` 安装后,客户端配置中把 `"command": "uvx"` 改为 `"command": "cls-mcp-server"`,`"args"` 改为 `[]` 即可。
277
+
278
+ ---
279
+
280
+ ### 场景二:远程服务模式
281
+
282
+ 适合将 Server 部署到服务器上,作为独立 HTTP 服务运行,供远程 MCP 客户端连接。
283
+
284
+ #### 方式一:Docker 部署(推荐,最简单)
285
+
286
+ 一条命令即可启动,无需安装 Python 或任何依赖:
287
+
288
+ ```bash
289
+ docker run -d \
290
+ --name cls-mcp-server \
291
+ -p 8000:8000 \
292
+ -e CLS_SECRET_ID=替换为你的SecretId \
293
+ -e CLS_SECRET_KEY=替换为你的SecretKey \
294
+ -e CLS_REGION=ap-guangzhou \
295
+ ghcr.io/tinker-lgd2026/cls-mcp-server:latest
296
+ ```
297
+
298
+ 验证服务是否启动成功:
299
+
300
+ ```bash
301
+ curl http://localhost:8000/health
302
+ # 预期输出: {"status":"ok","version":"0.1.0","transport":"streamable-http"}
303
+ ```
304
+
305
+ #### 方式二:一键部署脚本(适合无 Docker 的虚拟机)
306
+
307
+ 支持 CentOS 7+、Ubuntu 18.04+、Debian 10+,脚本自动安装 uv + Python 3.12 + 依赖 + 注册 systemd 服务,**零前置依赖**:
308
+
309
+ ```bash
310
+ # 1. 将源码上传到服务器(git clone 或 tar.gz 打包上传)
311
+ git clone https://github.com/Tinker-LGD2026/cls-mcp-server.git
312
+ cd cls-mcp-server
313
+
314
+ # 2. 运行一键部署脚本
315
+ sudo bash deploy/systemd/install.sh
316
+
317
+ # 3. 编辑配置文件,填入真实密钥
318
+ sudo vim /opt/cls-mcp-server/.env
319
+
320
+ # 4. 启动服务
321
+ sudo systemctl start cls-mcp-server
322
+
323
+ # 5. 验证
324
+ curl http://127.0.0.1:8000/health
325
+ ```
326
+
327
+ > **CentOS 7 用户**:不用担心 Python 版本问题,脚本通过 uv 自动下载 Python 3.12,不影响系统自带 Python。如果 git clone 太慢,可以在本地打包后 scp 上传,详见 [部署手册 - systemd 部署](docs/deployment-guide.md#43-systemd-服务虚拟机部署)。
328
+
329
+ #### 客户端连接远程服务
330
+
331
+ 服务启动后,在 MCP 客户端中配置远程连接:
332
+
333
+ ```json
334
+ {
335
+ "mcpServers": {
336
+ "cls": {
337
+ "url": "http://你的服务器IP:8000/mcp"
338
+ }
339
+ }
340
+ }
341
+ ```
342
+
343
+ > 如需 SSE 模式(兼容旧版客户端),端点改为 `/sse`。如已设置 Bearer Token 认证,需添加 `"headers": {"Authorization": "Bearer 你的token"}`。
344
+
345
+ ---
346
+
347
+ ## 配置参考
348
+
349
+ ### 环境变量
350
+
351
+ | 变量 | 必填 | 默认值 | 说明 |
352
+ |------|------|--------|------|
353
+ | `CLS_SECRET_ID` | 是 | — | 腾讯云 API SecretId |
354
+ | `CLS_SECRET_KEY` | 是 | — | 腾讯云 API SecretKey |
355
+ | `CLS_REGION` | 是 | `ap-guangzhou` | 地域(如 `ap-shanghai`、`ap-beijing`) |
356
+ | `CLS_TRANSPORT` | 否 | `stdio` | 传输方式:`stdio` / `sse` / `streamable-http` |
357
+ | `CLS_HOST` | 否 | `0.0.0.0` | HTTP 监听地址(远程模式) |
358
+ | `CLS_PORT` | 否 | `8000` | HTTP 监听端口(远程模式) |
359
+ | `MCP_AUTH_TOKEN` | 否 | — | HTTP Bearer Token 认证(远程模式,建议开启) |
360
+ | `CLS_ENABLE_WRITE` | 否 | `false` | 启用写操作工具(创建/修改) |
361
+ | `CLS_ENABLE_DANGEROUS` | 否 | `false` | 启用危险操作工具(删除,需同时开启写操作) |
362
+ | `CLS_LOG_LEVEL` | 否 | `INFO` | 日志级别:`DEBUG` / `INFO` / `WARNING` / `ERROR` |
363
+
364
+ ---
365
+
366
+ ## 部署指南
367
+
368
+ 除了上面"快速开始"中的 Docker 和一键脚本,还支持更多部署方式:
369
+
370
+ | 方式 | 适用场景 | 文档 |
371
+ |------|----------|------|
372
+ | Docker / Docker Compose | 远程服务,生产环境推荐 | [详细说明](docs/deployment-guide.md#5-docker-部署) |
373
+ | systemd + 一键脚本 | 传统虚拟机(CentOS/Ubuntu) | [详细说明](docs/deployment-guide.md#43-systemd-服务虚拟机部署) |
374
+ | Kubernetes / Helm | 容器编排,多副本水平扩展 | [详细说明](docs/deployment-guide.md#6-kubernetes-部署) |
375
+ | Nginx 反向代理 + HTTPS | 生产环境 TLS 终结 | [详细说明](docs/deployment-guide.md#44-nginx-反向代理) |
376
+ | HTTP Bearer Token 认证 | 远程服务访问控制 | [详细说明](docs/deployment-guide.md#7-http-认证bearer-token) |
377
+
378
+ 完整部署手册请参考 [docs/deployment-guide.md](docs/deployment-guide.md)。
379
+
380
+ ---
381
+
382
+ ## 国内环境加速
383
+
384
+ 如果 pip / Docker / uv 下载速度慢:
385
+
386
+ ```bash
387
+ # pip 使用清华源
388
+ pip install cls-mcp-server -i https://pypi.tuna.tsinghua.edu.cn/simple
389
+
390
+ # uv 使用国内源
391
+ UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple uvx cls-mcp-server --help
392
+ ```
393
+
394
+ 更多加速方案(Docker 镜像加速、uv 离线安装、GitHub 代理等)请参考 [部署手册 - 国内环境加速](docs/deployment-guide.md#9-国内环境加速)。
395
+
396
+ ## 许可证
397
+
398
+ [Apache-2.0](LICENSE)