把 MarxSphere 的推理/检索能力接入 OpenAI Codex CLI。
MARXSPHERE_PREVIEW=1 npx tsx src/index.ts(4173)编辑 ~/.codex/config.toml:
[mcp_servers.sag]
command = "npx"
args = ["tsx", "scripts/sag-mcp-server.ts"]
注意:
scripts/sag-mcp-server.ts是项目相对路径,需在SAG_ROOT下运行。 如果 Codex 工作目录不是 SAG 项目,建议用绝对路径或全局安装。
[mcp_servers.sag]
command = "cmd"
args = ["/c", "cd", "<SAG_ROOT>", "&&", "npx", "tsx", "scripts/sag-mcp-server.ts"]
env = { SAG_API_URL = "http://localhost:4173" }
[mcp_servers.sag]
command = "cmd"
args = ["/c", "cd", "<SAG_ROOT>", "&&", "npx", "tsx", "scripts/sag-mcp-server.ts"]
env = { SAG_API_URL = "https://your-server.example.com", SAG_API_TOKEN = "sag_xxx" }
完整示例见仓库根目录 codex-config.toml.example。
重启 Codex CLI 后:
codex
> 用 sag_documents 看看知识库里有什么
> 用 sag_search 找关于土地流转的论文
sag_reason(它会自动检索论文原文后推理)sag_search(秒级)sag_ingest 入库,之后所有 Agent 都能检索到| 现象 | 原因 | 解决 |
|---|---|---|
| Codex 报 MCP server 启动失败 | 路径/命令问题 | 确认工作目录与 npx 可用;用 cmd /c 写法 |
| 工具调用返回空 | 服务没起 | 确认 4173 在跑 |
401/403 |
Token 问题 | 检查 SAG_API_TOKEN 与权限 |