打字机mcp
用TypeScript超级智能增强你的AI编码代理。
通过 模型上下文协议 因此任何MCP兼容代理都可以使用它们。
- 即时类型分辨率 --悬停信息、泛型、推断类型而不读取文件
- 即时呼叫追踪 --在一次调用中跟随一个符号从处理程序到实现
- 即时影响分析 --“如果我改变这个,会有什么问题?”贯穿整个代码库
- 即时依赖关系映射 --什么导入什么,直接和传递,按包
- 瞬时循环检测 --在\= 22
- TypeScript >=目标项目中的5.0
- npm 用于依赖项安装
工具
语义查询(tsserver)
| 工具 | 说明 |
|---|---|
ts_find_symbol | 按名称查找符号在文件中的位置 |
ts_definition | 转到定义——通过导入、再导出、桶文件、泛型进行解析 |
ts_references | 查找所有语义引用(非字符串匹配) |
ts_type_info | 获取类型和文档——与VS代码悬停相同 |
ts_navigate_to | 在整个项目中搜索符号 |
ts_trace_chain | 按照定义自动跳转,构建呼叫链 |
ts_blast_radius | 分析更改符号的影响——所有使用站点和受影响的文件 |
ts_module_exports | 列出具有已解析类型的模块的所有导出 |
导入图形查询(oxc解析器+oxc解析器)
| 工具 | 说明 |
|---|---|
ts_dependency_tree | 文件的传递依赖树 |
ts_dependents | 依赖于给定文件的所有文件,按包分组 |
ts_import_cycles | 检测循环导入依赖关系 |
ts_shortest_path | 两个文件之间的最短导入路径 |
ts_subgraph | 提取种子文件周围的邻域 |
ts_module_boundary | 分析模块耦合:输入/输出边缘、隔离分数 |
命令行界面
typegraph-mcp [options]
setup Install plugin into the current project
remove Uninstall from the current project
check Run 12 health checks
test Smoke test all 14 tools
bench Run benchmarks (token, latency, accuracy)
start Start the MCP server (stdin/stdout)
--yes Skip prompts
--clean-global-codex Also remove a stale global Codex MCP entry for this project
--help Show helpremove 始终清理项目本地配置。如果检测到遗留全局 ~/.codex/config.toml 指向当前项目的条目,它将在以交互模式删除之前询问。在非交互模式下,通过 --clean-global-codex 以便进行全局清理。
故障排除
首先运行健康检查——它可以发现大多数问题:
npx typegraph-mcp check| 症状 | 修复 |
|---|---|
| 服务器无法启动 | cd plugins/typegraph-mcp && npm install --include=optional |
| “未找到TypeScript” | 运行 pnpm install 或 npm install;如果未声明TypeScript,请先将其添加到devDependencies中 |
| 工具返回空结果 | 检查 TYPEGRAPH_TSCONFIG 指向正确的tsconfig |
| 插件生成错误/ | 添加 "plugins/**" 到tsconfig.json exclude 阵列 |
@esbuild/* 或 @rollup/* 包丢失 | 使用节点22重新安装: npm install --include=optional |
| “npm warn Unknown project config” | 可以安全忽略——由您的pnpm设置引起 .npmrc npm无法识别 |
手动MCP配置
Codex 命令行界面
将此添加到您的项目 .codex/config.toml:
[mcp_servers.typegraph]
command = "/absolute/path/to/your-project/plugins/typegraph-mcp/node_modules/.bin/tsx"
args = ["/absolute/path/to/your-project/plugins/typegraph-mcp/server.ts"]
env = { TYPEGRAPH_PROJECT_ROOT = "/absolute/path/to/your-project", TYPEGRAPH_TSCONFIG = "/absolute/path/to/your-project/tsconfig.json" }使用本地插件 tsx 二进制避免依赖 npx tsx 当Codex启动MCP服务器时可以解决。
Codex仅加载项目 .codex/config.toml 受信任项目的文件。如果需要,请将此添加到 ~/.codex/config.toml:
[projects."/absolute/path/to/your-project"]
trust_level = "trusted"基于JSON的MCP客户端
添加 .claude/mcp.json (或 ~/.claude/mcp.json 全球):
{
"mcpServers": {
"typegraph": {
"command": "npx",
"args": ["tsx", "/absolute/path/to/typegraph-mcp/server.ts"],
"env": {
"TYPEGRAPH_PROJECT_ROOT": ".",
"TYPEGRAPH_TSCONFIG": "./tsconfig.json"
}
}
}
}TYPEGRAPH_PROJECT_ROOT 相对于代理的工作目录进行解析。这 args 通往 server.ts 必须是绝对的。
运作原理
AI Agent ─── stdin/stdout ─── MCP Server ─┬── tsserver (child process)
MCP protocol │ type-aware point queries
└── module-graph (in-process)
oxc-parser + oxc-resolver
structural graph queries两个子系统同时启动:
- tsserver --语义查询的子进程。使用tsserver的JSON协议通过管道进行通信。崩溃时自动重启(最多3次)。
Monorepo支持 --通过解决 composite 项目参考、地图 dist/ 返回源代码,句柄 extensionAlias 为了 .js → .ts 绘制地图,并跟踪跨包装桶再出口。
贡献
从源安装
git clone https://github.com/guyowen/typegraph-mcp.git
cd typegraph-mcp
nvm use
npm install --include=optional在本地针对项目运行
cd /path/to/your-ts-project
npx tsx ~/typegraph-mcp/cli.ts setup或者直接启动MCP服务器:
TYPEGRAPH_PROJECT_ROOT=/path/to/project TYPEGRAPH_TSCONFIG=/path/to/project/tsconfig.json npx tsx ~/typegraph-mcp/server.ts作为Claude Code插件加载(从源代码)
claude --plugin-dir ~/typegraph-mcp验证您的更改
npx tsx ~/typegraph-mcp/cli.ts check # 12 health checks
npx tsx ~/typegraph-mcp/cli.ts test # smoke test all 14 tools构建编译输出
npm run build # compiles to dist/ via tsup分行工作流程
dev--所有的工作都在这里进行main--合并到主触发器CI:自动更新补丁版本,通过OIDC信任的发布者发布到npm
已知限制
- 对象文字属性键 (例如,RPC处理程序名称)未被tsserver索引
navto.使用ts_find_symbol使用特定文件,或传递file提示ts_navigate_to. - 首次查询延迟 --tsserver加载项目时大约需要2秒。后续查询:1-60ms。
- 记忆 --tsserver将项目保存在内存中。对于非常大的monorepos(1000+个文件),预计约200-500MB的RSS。
