ts-graph-mcp

ts-graph-mcp

A TypeScript code graph tool with MCP integration that enables AI agents to perform semantic search and graph traversal (call graphs, paths between symbols) across a codebase.

Category
访问服务器

README

ts-graph-mcp

A TypeScript code graph tool that extracts code structure into a queryable database, with MCP integration for AI coding agents.

What It Does

ts-graph parses TypeScript source code using AST analysis and builds a graph database of your codebase structure. The graph captures code symbols (functions, classes, interfaces, types, variables) and their relationships (calls, imports, type usage, inheritance).

Semantic search included. On first run, ts-graph downloads an embedding model (~300MB) and generates embeddings for all symbols. AI agents can search by concept ("user validation", "database queries") not just exact symbol names.

AI agents query the graph through the searchGraph MCP tool to:

  • Find code by concept (semantic search)
  • Traverse call graphs (who calls this? what does this call?)
  • Find paths between symbols

Quick Start

1. Configuration

Create ts-graph-mcp.config.json in your project root:

{
  "packages": [
    { "name": "main", "tsconfig": "./tsconfig.json" }
  ],
  "server": {
    "port": 4000
  }
}

For monorepos, list multiple packages:

{
  "packages": [
    { "name": "shared", "tsconfig": "./shared/tsconfig.json" },
    { "name": "frontend", "tsconfig": "./frontend/tsconfig.json" },
    { "name": "backend", "tsconfig": "./backend/tsconfig.json" }
  ],
  "server": {
    "port": 4000
  }
}

2. Start the HTTP Server

npx ts-graph-mcp

The server indexes your project on first run and watches for changes.

3. Configure Claude Code

claude mcp add ts-graph-mcp -- npx -y ts-graph-mcp --mcp

Or manually in .mcp.json:

{
  "mcpServers": {
    "ts-graph-mcp": {
      "command": "npx",
      "args": ["-y", "ts-graph-mcp", "--mcp"]
    }
  }
}

Note: Start the HTTP server first. The MCP wrapper connects to it.

MCP Tool: searchGraph

Unified search combining semantic search with graph traversal.

Query Patterns

// Find code by concept (semantic search)
{ topic: "user authentication" }

// What does handleRequest call? (forward traversal)
{ from: { symbol: "handleRequest" } }

// Who calls saveUser? (backward traversal)
{ to: { symbol: "saveUser" } }

// How does A reach B? (path finding)
{ from: { symbol: "handleRequest" }, to: { symbol: "saveUser" } }

Parameters

Parameter Required Description
topic No* Standalone semantic search (not combinable with from/to)
from No* Start point: { symbol } or { query } with optional file_path
to No* End point: { symbol } or { query } with optional file_path
max_nodes No Output limit (default: 50)

*At least one of topic, from, or to is required. topic is standalone only — it cannot be combined with from/to.

Example Output

## Symbols matching "validation" (semantic search)

validateInput (Function) - src/validation.ts [score: 0.847]
checkUserData (Function) - src/user.ts [score: 0.721]
## Graph

handleRequest --CALLS--> validate --CALLS--> saveUser

## Nodes

validate:
  type: Function
  file: src/service.ts
  offset: 10, limit: 5
  snippet:
    10: export function validate(data: Input) {
  > 11:   return saveUser(data);
    12: }

CLI Options

ts-graph-mcp              # Start HTTP server
ts-graph-mcp --mcp        # Start MCP stdio server
ts-graph-mcp --reindex    # Force clean reindex

Configuration Reference

Required

Field Description
packages Array of { name, tsconfig }
server.port HTTP server port (no default)

Optional

Field Description Default
embedding.enabled Enable semantic search true
embedding.preset Embedding model "nomic-embed-text-v1.5"
storage.type Database type "sqlite"
storage.path Database file path .ts-graph-mcp/graph.db
watch.debounce Enable debouncing true
watch.debounceInterval Debounce delay (ms) 300
watch.polling Use polling (for Docker/WSL2) false
watch.pollingInterval Polling interval (ms) 1000
watch.excludeDirectories Directories to skip []
watch.silent Suppress reindex logs false

Embedding Models

Preset Size Dimensions Notes
nomic-embed-text-v1.5 ~300MB 768 Default, fast and effective
qwen3-0.6b ~650MB 1024 Higher quality, slower
qwen3-4b ~4GB 2560 Highest quality, needs more RAM
jina-embeddings-v2-base-code ~300MB 768 Optimized for code

Add .ts-graph-mcp/ to your .gitignore.

Yarn PnP Support

ts-graph works with Yarn 4 PnP monorepos. When .pnp.cjs is detected, module resolution uses Yarn's PnP API.

Requirements:

  • Use base package imports (@libs/utils, not @libs/utils/date)
  • Declare dependencies with workspace:* protocol

Supported Types

Nodes: Function, Class, Method, Interface, TypeAlias, Variable, SyntheticType, Feature, Spec, TestSuite, Test

Edges: CALLS, IMPLEMENTS, EXTENDS, TAKES, RETURNS, HAS_TYPE, HAS_PROPERTY, DERIVES_FROM, ALIAS_FOR, REFERENCES, INCLUDES, CONTAINS, SPECIFIES, VERIFIED_BY

Development

npm run check        # Run tests, build, and lint
npm test             # Run tests
npm run build        # Compile TypeScript

Project Structure

ts-graph-mcp/
├── http/          # HTTP server, database, ingestion, queries
├── mcp/           # MCP stdio wrapper
├── shared/        # Shared types
├── ui/            # Web UI (React + Vite)
└── main.ts        # Entry point

Windows Users

This package uses better-sqlite3, which requires compilation tools:

  1. Install Visual Studio Build Tools with "Desktop development with C++"
  2. Install Python 3.x
  3. Use Node.js LTS

Contributing

See ARCHITECTURE.md for technical internals and CLAUDE.md for code style guidelines.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选