Skip to main content

MCP server for Cangjie programming language - documentation search and code intelligence

Project description

Cangjie MCP Server

CI PyPI Python Versions GitHub Release License

仓颉编程语言的 MCP (Model Context Protocol) 服务器,提供文档搜索和代码智能功能。

功能

  • 文档搜索: 基于向量检索的仓颉语言文档搜索
  • 代码智能: 基于 LSP 的代码补全、跳转定义、查找引用等功能
  • 可选远程文档服务: 支持连接远程文档/索引服务,减少本地资源占用,适合开箱即用或团队共享

安装

pip install cangjie-mcp

或使用 uvx 直接运行(推荐):

uvx cangjie-mcp  # 启动 MCP 服务器

安装并指定 Rust feature

当平台没有预编译 wheel,或你希望按需启用 GPU/NPU 等加速后端时,可强制从 sdist 构建并传入 maturin 构建参数:

pip install --no-binary cangjie-mcp cangjie-mcp \
  --config-settings=build-args="--features local"

可用 feature(传给 cangjie-mcp-cli):

  • local:本地向量化(CPU;默认构建的二进制已启用)
  • legacy:本地向量化改用 ort-tract 后端(适配旧 glibc 构建)
  • local-cuda / local-cudnn:启用 CUDA/CUDNN 后端
  • local-metal:启用 Apple Metal 后端
  • local-mkl / local-accelerate:启用 MKL / Accelerate 后端

架构

cangjie-mcp 支持两种运行模式:

本地模式(默认)

MCP 服务器在本地加载检索索引(BM25 + 向量索引),直接处理查询。

cangjie-mcp

远程文档服务模式(可选)

如果你不想在本机下载/加载向量模型与索引(或希望多人/多台机器共享同一套索引),可以把检索能力以 HTTP 的方式独立部署。之后 MCP 只需要通过 --server-url 连接,就能直接使用文档检索能力。

# 终端 1:启动 HTTP 查询服务器
cangjie-mcp server --embedding local --port 8765

# 终端 2:启动 MCP 服务器,连接远程索引
cangjie-mcp --server-url http://localhost:8765

快速配置

公共文档服务器已部署在 https://cj-mcp.learningman.top,连接后无需本地加载嵌入模型,开箱即用。

注意:LSP 功能需要已安装仓颉 SDK,请将 /path/to/cangjie-sdk 替换为实际路径,或设置 CANGJIE_HOME 环境变量。

Claude Code(推荐)
claude mcp add \
  -e CANGJIE_SERVER_URL=https://cj-mcp.learningman.top \
  -e CANGJIE_HOME=/path/to/cangjie-sdk \
  cangjie -- uvx cangjie-mcp
Cursor / Windsurf / Claude Desktop

配置文件路径:

  • Cursor: ~/.cursor/mcp.json
  • Windsurf: ~/.codeium/windsurf/mcp_config.json
  • Claude Desktop (macOS): ~/Library/Application Support/Claude/claude_desktop_config.json
  • Claude Desktop (Windows): %APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "cangjie": {
      "command": "uvx",
      "args": ["cangjie-mcp"],
      "env": {
        "CANGJIE_SERVER_URL": "https://cj-mcp.learningman.top",
        "CANGJIE_HOME": "/path/to/cangjie-sdk"
      }
    }
  }
}
VS Code (GitHub Copilot)

settings.json:

{
  "mcp": {
    "servers": {
      "cangjie": {
        "command": "uvx",
        "args": ["cangjie-mcp"],
        "env": {
          "CANGJIE_SERVER_URL": "https://cj-mcp.learningman.top",
          "CANGJIE_HOME": "/path/to/cangjie-sdk"
        }
      }
    }
  }
}
Zed

~/.config/zed/settings.json:

{
  "context_servers": {
    "cangjie": {
      "command": {
        "path": "uvx",
        "args": ["cangjie-mcp"],
        "env": {
          "CANGJIE_SERVER_URL": "https://cj-mcp.learningman.top",
          "CANGJIE_HOME": "/path/to/cangjie-sdk"
        }
      }
    }
  }
}
本地模式(不使用远程服务器)

如需完全离线使用或自建索引,可不设置 CANGJIE_SERVER_URL,MCP 会在本地加载嵌入模型和索引:

claude mcp add \
  -e CANGJIE_RERANK_TYPE=local \
  -e CANGJIE_HOME=/path/to/cangjie-sdk \
  cangjie -- uvx cangjie-mcp

可用工具

文档搜索

工具名称 功能
cangjie_search_docs 语义搜索仓颉文档
cangjie_get_topic 获取指定主题的完整内容
cangjie_list_topics 列出所有可用主题

代码智能

需要设置 CANGJIE_HOME 环境变量指向仓颉 SDK 路径,LSP 工具才会注册。

工具名称 功能
cangjie_lsp_definition 跳转到符号定义
cangjie_lsp_references 查找符号的所有引用
cangjie_lsp_hover 获取符号的类型信息和文档
cangjie_lsp_symbols 列出文档中的所有符号
cangjie_lsp_diagnostics 获取文件的错误和警告
cangjie_lsp_completion 获取代码补全建议

命令行参考

cangjie-mcp

启动 MCP 服务器,同时提供文档搜索和 LSP 代码智能功能。LSP 功能在设置了 CANGJIE_HOME 环境变量时自动启用。

cangjie-mcp [OPTIONS]

选项

CLI 参数 环境变量 默认值 说明
-v, --version - - 显示版本并退出
--log-file PATH CANGJIE_LOG_FILE - 日志文件路径
--debug / --no-debug CANGJIE_DEBUG --no-debug 启用调试模式,将 stdio 流量写入日志文件
-V, --docs-version TEXT CANGJIE_DOCS_VERSION latest 文档版本 (git tag)
-l, --lang TEXT CANGJIE_DOCS_LANG zh 文档语言 (zh / en)
-e, --embedding TEXT CANGJIE_EMBEDDING_TYPE none 向量化类型 (none / local / openai)
--local-model TEXT CANGJIE_LOCAL_MODEL paraphrase-multilingual-MiniLM-L12-v2 本地 HuggingFace 向量化模型
--openai-api-key TEXT OPENAI_API_KEY - OpenAI API 密钥
--openai-base-url TEXT OPENAI_BASE_URL https://api.openai.com/v1 OpenAI API 基础 URL
--openai-model TEXT OPENAI_EMBEDDING_MODEL text-embedding-3-small OpenAI 向量化模型
-r, --rerank TEXT CANGJIE_RERANK_TYPE none 重排序类型 (none / local / openai)
--rerank-model TEXT CANGJIE_RERANK_MODEL BAAI/bge-reranker-v2-m3 重排序模型
--rerank-top-k INT CANGJIE_RERANK_TOP_K 5 重排序后返回结果数
--rerank-initial-k INT CANGJIE_RERANK_INITIAL_K 20 重排序前候选数
--chunk-size INT CANGJIE_CHUNK_MAX_SIZE 6000 最大分块大小(字符数)
-d, --data-dir PATH CANGJIE_DATA_DIR ~/.cangjie-mcp 数据目录路径
--server-url TEXT CANGJIE_SERVER_URL - 远程查询服务器 URL

LSP 功能通过以下环境变量控制:

环境变量 说明
CANGJIE_HOME 仓颉 SDK 路径,设置后自动启用 LSP 工具

cangjie-mcp server

启动 HTTP 查询服务器,加载本地检索索引(BM25 + 向量索引),通过 HTTP 提供查询服务。

cangjie-mcp server [OPTIONS]

支持所有与 cangjie-mcp 相同的索引选项,以及:

CLI 参数 环境变量 默认值 说明
--host TEXT CANGJIE_SERVER_HOST 127.0.0.1 HTTP 服务器监听地址
-p, --port INT CANGJIE_SERVER_PORT 8765 HTTP 服务器监听端口

HTTP API

方法 路径 说明
GET /health 健康检查
GET /info 索引元数据
POST /search 向量搜索
GET /topics 列出所有分类和主题
GET /topics/{category}/{topic} 获取文档内容

调试与日志

--log-file--debug 配合使用,可以帮助排查 MCP 通信问题:

# 记录应用日志到文件
cangjie-mcp --log-file /tmp/cangjie.log

# 调试模式:额外记录 MCP stdio 协议流量
cangjie-mcp --log-file /tmp/cangjie.log --debug

# 通过环境变量配置
CANGJIE_LOG_FILE=/tmp/cangjie.log CANGJIE_DEBUG=1 cangjie-mcp

许可证

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cangjie_mcp-0.3.1.tar.gz (141.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cangjie_mcp-0.3.1-py3-none-win_amd64.whl (23.7 MB view details)

Uploaded Python 3Windows x86-64

cangjie_mcp-0.3.1-py3-none-manylinux_2_39_x86_64.whl (25.5 MB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

cangjie_mcp-0.3.1-py3-none-manylinux_2_39_aarch64.whl (25.8 MB view details)

Uploaded Python 3manylinux: glibc 2.39+ ARM64

cangjie_mcp-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (23.2 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

cangjie_mcp-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (21.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

cangjie_mcp-0.3.1-py3-none-macosx_11_0_arm64.whl (23.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file cangjie_mcp-0.3.1.tar.gz.

File metadata

  • Download URL: cangjie_mcp-0.3.1.tar.gz
  • Upload date:
  • Size: 141.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cangjie_mcp-0.3.1.tar.gz
Algorithm Hash digest
SHA256 8ecd4d6192cd23f4fa6db8005df80d820843ad9e57741ccaad2dc8aa91a6dbff
MD5 ca043088cac98937720b0d0902f0e8cf
BLAKE2b-256 e48d98e93dfac982e9409e01d32114795dfd969d1a5774aace05b3b144dd945c

See more details on using hashes here.

File details

Details for the file cangjie_mcp-0.3.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: cangjie_mcp-0.3.1-py3-none-win_amd64.whl
  • Upload date:
  • Size: 23.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cangjie_mcp-0.3.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 084503610f0da407f8bdd93c0f90605fb47a69ef877e6168a1af4236a3236ca0
MD5 d32f532c4149ccff22a36986d43566d4
BLAKE2b-256 137bca5f813e0547a6c19e3adfd56e8aad18b335c06bca3d98495c08fb919ea8

See more details on using hashes here.

File details

Details for the file cangjie_mcp-0.3.1-py3-none-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: cangjie_mcp-0.3.1-py3-none-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 25.5 MB
  • Tags: Python 3, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cangjie_mcp-0.3.1-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 6dff8be0683dd7e441159b44b30f25354e452c40f9cc5d3077c75eabe423a507
MD5 6ce4033f7270397e885d47f831c0c9ae
BLAKE2b-256 129c16a1ef57bdbc08de6f36f4f9cc7e96288e5056f128870a6438c0cd88cdc8

See more details on using hashes here.

File details

Details for the file cangjie_mcp-0.3.1-py3-none-manylinux_2_39_aarch64.whl.

File metadata

  • Download URL: cangjie_mcp-0.3.1-py3-none-manylinux_2_39_aarch64.whl
  • Upload date:
  • Size: 25.8 MB
  • Tags: Python 3, manylinux: glibc 2.39+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cangjie_mcp-0.3.1-py3-none-manylinux_2_39_aarch64.whl
Algorithm Hash digest
SHA256 423f2f1c2b70b8d0de0d4af69d2e9e13e1cfd7ea60c15d7b428889b444d8e543
MD5 50b0db9349795e00fa567799c2e191af
BLAKE2b-256 328bffe94f43f4605bceba9248a891c3a8b733b02724c179e4f34f2854defa10

See more details on using hashes here.

File details

Details for the file cangjie_mcp-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

  • Download URL: cangjie_mcp-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
  • Upload date:
  • Size: 23.2 MB
  • Tags: Python 3, manylinux: glibc 2.17+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cangjie_mcp-0.3.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27a31b6ba2cf3d89468142da352cfeea5cbb6fe9da4443da01962bda8a9ef4ec
MD5 b4f670ea3d8e1dcc9387af96dd82a0cd
BLAKE2b-256 aeeca900966f222d803a6b1a2508e0113a0d264d394990cd07247cfdece6bcae

See more details on using hashes here.

File details

Details for the file cangjie_mcp-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

  • Download URL: cangjie_mcp-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
  • Upload date:
  • Size: 21.8 MB
  • Tags: Python 3, manylinux: glibc 2.17+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cangjie_mcp-0.3.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 12ac6d0f99be328c19412c5be2f1ce4f885d71c18f6b8dc6c4efbda8c7f386a3
MD5 8eabad7a2f3c6c704e9fba52d2a112dc
BLAKE2b-256 6319ec5b3855b35ec0e2b31dc2469510eb8709552aff0463492475baf3954701

See more details on using hashes here.

File details

Details for the file cangjie_mcp-0.3.1-py3-none-macosx_11_0_arm64.whl.

File metadata

  • Download URL: cangjie_mcp-0.3.1-py3-none-macosx_11_0_arm64.whl
  • Upload date:
  • Size: 23.1 MB
  • Tags: Python 3, macOS 11.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.6 {"installer":{"name":"uv","version":"0.10.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for cangjie_mcp-0.3.1-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7d23d0f031e45e46bf1f3df1d72019f13e4a8436a690e093b277fbc9c2afb6db
MD5 0b6807defb243334c35a6c480223fc92
BLAKE2b-256 fc8c05b45d0b7435e8d1f2d847f1b9aa990c889752ed746e63feddb639b83644

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page