mcpField
C
ctx

ctx

远程服务
ctx.vanshul.com开发工具18 周前更新

关于 ctx

ctx 是一个公共 MCP 服务,可将 GitHub 仓库和文档网站整理为 AI Agent 所需的上下文。它能将内容打包为带 Token 估算的文本块,也能返回附有文件、网址和行号信息的相关片段。

主要功能

  1. 01打包仓库内容
  2. 02搜索仓库片段
  3. 03列出纳入的文件
  4. 04读取单个文件
  5. 05打包抓取的文档
  6. 06搜索文档片段

适用场景

  1. 01为 Agent 提供仓库快照
  2. 02查找代码库中的相关行
  3. 03收集或搜索文档网站内容

MCP 相关

ctx 通过运行在 Cloudflare Workers 上的 MCP 端点提供六种工具。MCP 客户端可通过 HTTP 连接;仅支持 stdio 的客户端可使用桥接方式。

配置

远程服务无需本地安装。选择你使用的客户端,复制配置或使用一键安装。

服务地址https://ctx.vanshul.com/mcp
一键复制安装命令
Claude CodeTerminal
Cursor.cursor/mcp.json
VS Code.vscode/mcp.json
Claude Desktopclaude_desktop_config.json
Windsurf~/.codeium/windsurf/mcp_config.json

命令在终端中运行;JSON 粘贴到对应客户端的 MCP 配置后重启。需要授权的服务会在首次连接时提示登录。

工具

6
参数类型必填说明
refstring否可选的分支、标签或提交 SHA(默认使用默认分支)。
repostring是GitHub 仓库,格式为 "owner/repo" 或 github.com URL。
excludearray否可选的 glob 模式(支持 **、*、?)。
includearray否可选的 glob 模式(支持 **、*、?)。
max_tokensnumber否估算的 token 数超过此值后停止添加文件。

详细介绍

ctx.vanshul.com

MCP Registry Endpoint License: MIT

一个公开的 Model Context Protocol (MCP) 服务,以 Cloudflare Worker 的形式运行,可将 GitHub 仓库或文档站点转换为适合 Agent 使用的上下文。将 AI Agent 指向它,即可将整个仓库(或抓取整个文档站点)打包成一个经过令牌数估算的文本块;也可以搜索并仅获取相关段落,每段都附带文件/URL 和行号。

它是面向 Agent 的 mcp/ 配套工具:mcp 读取单个网页,而 ctx 读取整个仓库和文档站点。仓库处理流程会在进程内获取、解压 gzip 并解析 tarball;文档提取则会复用 Mozilla Readability + Turndown。

端点

POST https://ctx.vanshul.com/mcp     # JSON-RPC 2.0 (MCP)
GET  https://ctx.vanshul.com/health  # { ok: true, tools: [...] }

工具

工具输入返回内容
pack_repo{ repo, ref?, include?, exclude?, max_tokens? }将仓库作为一个上下文文本块返回,带有 ==== path ==== 标题和令牌数估算
search_context{ repo, query, ref?, include?, exclude?, max_matches?, context_chars? }仅返回与 query 匹配的段落,每段包含文件、行号和评分
list_files{ repo, ref?, include?, exclude? }JSON:ctx 将纳入的文本文件及其字节大小
get_file{ repo, path, ref? }单个文件的完整文本
pack_docs{ url, depth?, max_pages?, max_tokens? }将抓取的文档站点作为一个上下文文本块返回(每个页面 → Markdown)
search_docs{ url, query, depth?, max_pages?, max_matches?, context_chars? }仅返回与 query 匹配的文档段落,每段包含页面 URL、行号和评分

repo 可以是 owner/repo、owner/repo/ref 或 github.com URL。文档工具中的 url 是用于开始抓取的绝对 http(s) 文档页面地址。

从 MCP 客户端连接

{ "mcpServers": { "ctx": { "url": "https://ctx.vanshul.com/mcp" } } }

仅支持 Stdio 的客户端可通过 npx mcp-remote https://ctx.vanshul.com/mcp 桥接。

添加到客户端
  • Cursor — 依次选择 Settings → MCP → Add new server,或将以下内容添加到 ~/.cursor/mcp.json:
    { "mcpServers": { "ctx": { "url": "https://ctx.vanshul.com/mcp" } } }
    
  • Claude Desktop — 将相同的配置块添加到 claude_desktop_config.json(Settings → Developer → Edit Config)。如果你的版本仅支持 stdio,请使用:
    { "mcpServers": { "ctx": { "command": "npx", "args": ["mcp-remote", "https://ctx.vanshul.com/mcp"] } } }
    
  • Continue / VS Code — 在 MCP 服务配置中添加 ctx,URL 为 https://ctx.vanshul.com/mcp。

使用 curl 试用

# Pack a repo, capped to 8000 tokens
curl -s https://ctx.vanshul.com/mcp -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/call",
       "params":{"name":"pack_repo","arguments":{"repo":"sindresorhus/slugify","max_tokens":8000}}}'

# Search a repo for just the relevant passages
curl -s https://ctx.vanshul.com/mcp -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/call",
       "params":{"name":"search_context","arguments":{"repo":"sindresorhus/slugify","query":"replace separator"}}}'

目录结构

ctx/
├── src/
│   ├── worker.ts     # entry: routes /mcp, /health, rate limit, CORS
│   ├── mcp.ts        # JSON-RPC dispatch + the six tool definitions
│   ├── github.ts     # fetch tarball, gunzip, parse tar, filter files (no deps)
│   ├── pack.ts       # assemble the context blob + token estimate
│   ├── search.ts     # ranked passage search over files (file + line)
│   ├── docs.ts       # crawl a docs site into pages (BFS, same-section)
│   ├── extract.ts    # HTML -> Markdown / links (Readability + Turndown)
│   ├── fetcher.ts    # bounded fetch with re-validated redirects (SSRF)
│   └── security.ts   # SSRF guard (block private/internal addresses)
├── public/
│   ├── index.html    # landing page (served for non-API paths)
│   ├── og.png / og.svg
│   ├── robots.txt
│   └── sitemap.xml
├── tests/            # vitest: github (tar parsing), pack, search, mcp, worker
├── docs/             # architecture, tools/API reference, deployment
├── wrangler.toml
├── package.json
└── tsconfig.json

开发与部署

cd ctx
npm install
npm run typecheck
npm test           # vitest — full suite
npm run dev        # local worker at http://localhost:8787  (POST /mcp)
npm run deploy     # wrangler deploy

工作原理

owner/repo → github.com tarball → DecompressionStream('gzip')
           → in-process tar parse → drop binaries/lockfiles/build dirs
           → pack (concat + token estimate) OR search (ranked passages)

GitHub URL 始终由固定的 owner/repo 标识构造,因此仓库工具不存在 SSRF 攻击面。文档工具会获取调用方提供的 URL,因此每个 URL 和重定向跳转都会针对 SSRF 防护规则重新验证。下载均有边界限制(超时、大小上限、页面/文件数量上限),结果会在每个 isolate 中缓存几分钟。

安全与限制

  • 无 SSRF: 输入是仓库标识,而非任意 URL;只会获取 github.com。
  • 有限制: 下载超时为 20s,解压后大小上限约为 60 MB,单个文件上限为 512 KB,文件数不超过 3000,并设有基于 IP 的速率限制。
  • 无状态且私密: 不存储代码,流程中不使用大模型;默认支持公开仓库(私有仓库需提供令牌)。

身份验证(可选)

设置 GITHUB_TOKEN Worker 密钥,即可提高 GitHub 的速率限制(每小时 60 次 → 5,000 次)并读取私有仓库:

wrangler secret put GITHUB_TOKEN

该令牌仅作为 Worker 密钥使用,不会作为工具参数传入,因此不会泄露给 Agent。

文档

许可证

MIT © Vanshul Goyal

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。