ts-docs-mcp
An MCP server that gives AI coding agents accurate, version-aware API documentation for any npm package — straight from the source.
README
ts-docs-mcp
An MCP server that gives AI coding agents accurate, version-aware API documentation for any npm package — straight from the source.
⚡
npx ts-docs-mcp— works with Cursor, Claude Code, VS Code Copilot, and any MCP-compatible client.
The Problem
When you ask an AI coding agent (Claude Code, Cursor, Copilot) to write code using an npm package, the model relies on its training data — which is often months or years out of date.
The result:
// ❌ Model hallucinates — Express 4 syntax, but you have Express 5 installed
import bodyParser from 'body-parser';
app.use(bodyParser.json());
// ❌ Wrong API — Zod v3 pattern, but Zod v4 changed the API
const schema = z.object({ name: z.string() });
schema.parse(data); // Zod v4 requires schema.parse({...}) with options
Models know about libraries, but they don't know which version you have installed or what the current API looks like.
The Solution
ts-docs-mcp provides documentation sourced from the actual package source code — not training data.
The pipeline:
npm registry → GitHub .ts (JSDoc) → npm tarball (.d.ts) → DefinitelyTyped (@types/)
- Resolves the exact version from the npm registry
- Reads TypeScript source from GitHub, including JSDoc,
@param,@returns - Follows re-exports to find actual declarations (BFS, parallel fetches)
- Falls back to
.d.tsfrom the npm tarball if GitHub source is insufficient - Falls back to DefinitelyTyped for JS-only packages (express, etc.)
- Returns clean Markdown — full signatures, parameters, deprecation notices, examples
Before vs After
| Package | Before (v0.1.0) | After (v0.4.1) |
|---|---|---|
| zod | 31 symbols | 577 |
| axios | 0 | 83 |
| uuid | 0 | 23 |
| chalk | 19 | 32 |
| fastify | 51 | ~100+ |
| express | 0 | 13 (via @types/express) |
How It Works
┌──────────────────┐ ┌──────────────────────────────────────────────┐
│ AI Coding Agent │ ◄──── │ ts-docs-mcp │
│ (Cursor, Claude │ MCP │ (MCP Server via stdio) │
│ Code, etc.) │ │ │
└──────────────────┘ │ get_package_docs("zod") │
│ │ ↓ │
│ "Here is the │ 1. npm registry → package metadata │
│ full API │ 2. GitHub raw → JSDoc from .ts source │
│ documentation"│ 3. BFS re-export resolution (parallel) │
▼ │ 4. npm tarball → .d.ts parsing (no JSDoc?) │
Writes correct code │ 5. @types/{name} fallback (JS-only) │
│ 6. Merge + dedup → Markdown │
│ 7. XDG cache (24h TTL) │
└──────────────────────────────────────────────┘
Tools
| Tool | Description |
|---|---|
get_package_docs |
Get API docs for any npm package. Optional query, version, subpath. |
Examples
# Latest version
get_package_docs("zod")
# Specific version
get_package_docs("zod", version="3.23.8")
# Subpath export (e.g. zod/v4/classic)
get_package_docs("zod", subpath="v4/classic")
# Query a specific symbol
get_package_docs("zod", query="transform")
Fallback chain
GitHub .ts (JSDoc + declarations)
→ BFS re-export resolution (depth=2, concurrency=5)
→ merge: GitHub .d.ts (from tarball, with re-export following)
→ if 0 symbols: DefinitelyTyped (@types/{name})
→ merge all results, dedup by name (GitHub takes priority)
What the model gets
## findByEmail (function)
> Find a user by their email address.
> @param email — The email to search for
> @returns The user object or null
```typescript
export function findByEmail(email: string, includeDeleted?: boolean): User | null;
Parameters:
email — The email to search forincludeDeleted — Whether to include deleted users
Returns: The user object or null
Full signatures, no truncation. `@param`, `@returns`, `@deprecated`, `@example` are preserved.
### Cache
Documentation is cached in `~/.cache/ts-docs-mcp/` (XDG-compatible), keyed by `package@version`. TTL is 24 hours. Old entries are cleaned up after 7 days.
---
## Usage
### Quick start
Add to your MCP configuration:
```json
{
"mcpServers": {
"ts-docs-mcp": {
"command": "npx",
"args": ["-y", "ts-docs-mcp"]
}
}
}
Cursor: Settings → MCP → Add Server → paste the config above.
Claude Code: claude mcp add ts-docs-mcp -- npx -y ts-docs-mcp
VS Code / Copilot: .vscode/mcp.json → add the entry.
Requirements
- Node.js 20+
- Internet access (fetches from npm registry, GitHub, npm tarballs)
- Package must be on npm with a public GitHub repository (or have @types/ types)
Examples
Get the full API overview:
You → "Show me the axios API"
Agent → calls get_package_docs("axios")
→ gets 83 symbols: types, interfaces, classes, functions
Find a specific symbol:
You → "How do I use Zod's transform method?"
Agent → calls get_package_docs("zod", query="transform")
→ gets ZodEffects.transform with full signature + JSDoc
Why not just use the README / training data?
| Source | Coverage | Version-aware | Freshness |
|---|---|---|---|
| Training data | Variable | ❌ | 6-24 months stale |
| README | ~20% of API | ❌ | Often stale |
| ts-docs-mcp | All exports | ✅ Exact version | ✅ Real-time |
TypeScript .d.ts files + GitHub source are the canonical source of truth — they always reflect the exact installed version.
Development
git clone https://git.827482.xyz/xvantz/ts-docs-mcp.git
cd ts-docs-mcp
npm install
npm run build
npm test # 43 unit tests (5 test files)
npm run test:integration # network tests (skipped in CI)
Project structure
src/
├── registry.ts — npm package metadata + HTTP helpers
├── github.ts — GitHub raw source fetching (BFS, parallel)
├── tarball.ts — .d.ts extraction from tarball + DefinitelyTyped
├── parser.ts — Two-phase JSDoc + declaration parser
├── format.ts — Markdown output (summary + detail)
├── throttle.ts — Per-endpoint token-bucket rate limiter
├── cache.ts — XDG file cache with 24h TTL
├── types.ts — PublicSymbol, PackageInfo interfaces
└── index.ts — MCP server (thin handler)
License
MIT
Built because AI coding agents deserve better than hallucinated APIs.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。