使用说明
doc-mcpify是一个npm包,它将您现有的文档、API和源代码转换为MCP(模型上下文协议)服务器,Copilot和Cursor等AI助手可以直接查询。doc-mcpify不是强迫开发人员(或人工智能)手动搜索Markdown文件、OpenAPI规范或TypeScript代码,而是解析所有内容——文档、组件、钩子、类型、端点——并通过标准化的MCP端点公开,这样人工智能就可以按需获取确切的答案、代码片段和模式。只需几行设置,它就支持多种格式(Markdown、MDX、TS/JS、OpenAPI),可以独立工作或在Express/Fastify内部工作,并允许人工智能提出自然语言问题,如“向我展示按钮组件代码”或“什么是模态道具?”——使您的文档立即机器可读、可搜索且对开发人员友好。
使您的文档可由Copilot和Cursor等AI助手查询。
用3行代码将文档、API和源代码转换为MCP服务器。不需要协议知识。
为什么使用这个?
如果你有一个 用户界面库, API,或 软件开发工具包,开发人员现在可以问AI:
- “显示按钮组件代码”
- “我如何使用Modal?”
- “获取useAuth钩子示例”
与其搜索文档, AI获取精确的代码 他们需要您的MCP服务器。
它做什么
// Your docs + code
docs/
├── button.md // Markdown docs
├── modal.md
src/
├── components/
│ └── Button.tsx // Source code
└── hooks/
└── useAuth.ts
// Becomes queryable by AI
👇
await docmcp({ docs: ['./docs/**/*.md', './src/**/*.{ts,tsx}'] });
// ✅ Copilot can now query your docs + code!
特性
- AI可查询 -Copilot/Cursor可以搜索您的文档和代码
- 多种格式 -Markdown、OpenAPI、Types/JavaScript
- 智能解析 -提取函数、类型、JSDoc、代码示例
- 球形图案 -自动扫描整个目录
- 零配置 -3行开始
- 框架不可知 -快速、禁食或独立
安装
完整包(所有解析器)
npm install doc-mcpify
轻量级选项(仅安装所需内容)
# For Markdown/MDX only
npm install doc-mcpify # Then use: import { docmcp } from 'doc-mcpify/md'
# For TypeScript/TSX only (.ts, .tsx files)
npm install doc-mcpify # Then use: import { docmcp } from 'doc-mcpify/ts'
# For JavaScript/JSX only (.js, .jsx files)
npm install doc-mcpify # Then use: import { docmcp } from 'doc-mcpify/js'
# For OpenAPI/Swagger only
npm install doc-mcpify # Then use: import { docmcp } from 'doc-mcpify/openapi'
# For MDX specifically (includes Markdown)
npm install doc-mcpify # Then use: import { docmcp } from 'doc-mcpify/mdx'
快速入门(3个步骤)
步骤1:安装
npm install doc-mcpify
步骤2:创建MCP服务器
创建 mcp-server.mjs 在您的项目中:
选项A:完整套餐
import { docmcp } from 'doc-mcpify';
await docmcp({
docs: [
'./docs/**/*.md', // All markdown files
'./src/components/**/*.tsx', // React components
'./src/hooks/**/*.ts', // Custom hooks
],
standalone: true,
port: 3001,
});
console.log('✅ MCP Server running on http://localhost:3001');
选项B:轻量级(仅Markdown)
import { docmcp } from 'doc-mcpify/md'; // ✨ Only installs markdown parser
await docmcp({
docs: ['./docs/**/*.md'],
standalone: true,
port: 3001,
});
选项C:仅限TypeScript/TSX
import { docmcp } from 'doc-mcpify/ts'; // ✨ Supports .ts AND .tsx files
await docmcp({
docs: ['./src/**/*.{ts,tsx}'],
standalone: true,
port: 3001,
});
选项D:反应组件(JSX/TSX)
import { docmcp } from 'doc-mcpify/ts'; // ✨ Parses React components
await docmcp({
docs: ['./components/**/*.{jsx,tsx}'],
standalone: true,
port: 3001,
});
步骤3:连接到VS代码
添加到您的 .vscode/settings.json:
{
"mcp.servers": {
"my-docs": {
"command": "node",
"args": ["./mcp-server.mjs"]
}
}
}
完成! 重新加载VS Code和Copilot现在可以查询您的文档。
试试看
询问副驾驶:
- “演示如何使用按钮组件”
- “获取莫代尔道具”
- 解析什么?
从Markdown文件
# Button Component
## Usage
\`\`\`tsx
<Button variant="primary">Click me</Button>
\`\`\`
摘录:
- 组件名称
- 代码示例
- 使用说明
- K整合方案
选项1:独立(推荐)
非常适合文档网站:
import docmcp from 'doc-mcpify';
await docmcp({
docs: ['./docs/**/*.md', './src/**/*.tsx'],
standalone: true,
port: 3001,
});
选项2:使用Express
添加到现有的Express应用程序:
import express from 'express';
import { docmcp } from 'doc-mcpify'; // Or use /md, /ts, /openapi
const app = express();
await docmcp(app, {
docs: './docs/**/*.md',
basePath: '/mcp',
});
app.listen(3000);
选项3:禁食
import Fastify from 'fastify';
import { docmcp } from 'doc-mcpify'; // Or use /md, /ts, /openapi
const fastify = Fastify();
await docmcp(fastify, {
docs: './docs/**/*.md',
});
fastify.listen({ port: 3000 });
MCP端点(自动创建)
| 端点 | 副驾驶获得什么 |
|---|---|
/mcp/describe |
您的API/库概述 |
/mcp/resources |
所有文档+代码示例 ⭐ |
/mcp/endpoints |
API端点列表(如果是OpenAPI) |
/mcp/schemas |
类型定义 |
| } |
导出界面ButtonProps{ 变体?:“主要”|“次要”; }
**Extracted:**
- Exported functions/components
- JSDoc comments
- TypeScript interfaces/types
- Function signatures
### From OpenAPI Specs
```yaml
paths:
/users/{id}:
get:
summary: Get user by ID
摘录:
- API端点
- 参数
- 请求/响应模式
- 身份验证要求mcp验证。/openapi.yaml
检查已解析的文档
医生mcp检查。/openapi.yaml
## MCP Endpoints
Once mounted, doc-mcp exposes the following endpoints:
| Endpoint | Method | Purpose |
|----------|--------|---------|
| `/mcp/describe` | GET | High-level API description, metadata, versioning |
| `/mcp/schemas` | GET | Normalized API schemas (OpenAPI-like JSON) |
| `/mcp/endpoints` | GET | List of available API endpoints with params |
| `/mcp/auth` | GET | Authentication requirements and headers |
### Example Responses
#### GET /mcp/describe
```json
{
"name": "My API",
"description": "A sample API",
"version": "1.0.0",
"servers": [
{ "url": "https://api.example.com" }
],
"documentation": {
"type": "openapi",
"sources": ["./openapi.yaml"]
}## Common Use Cases
### UI Library Documentation
```javascript
// Lightweight: Only markdown parser
import { docmcp } from 'doc-mcpify/md';
await docmcp({
docs: ['./docs/**/*.md'],
standalone: true,
port: 3001,
});
// Full: Markdown + TypeScript components
import { docmcp } from 'doc-mcpify';
await docmcp({
docs: [
'./docs/**/*.md', // Markdown docs
'./src/components/**/*.tsx', // Component code
'./src/hooks/**/*.ts', // Custom hooks
],
standalone: true,
port: 3001,
metadata: {
title: 'My UI Library',
description: 'Reusable React components',
},
});
API文档
// OpenAPI only (lightweight)
import { docmcp } from 'doc-mcpify/openapi';
await docmcp({
docs: ['./openapi.yaml'],
standalone: true,
port: 3001,
});
// OpenAPI + Guides
import { docmcp } from 'doc-mcpify';
await docmcp({
docs: [
'./openapi.yaml', // API spec
'./guides/*.md', // User guides
],
standalone: true,
port: 3001,
});
SDK文档
// TypeScript SDK only
import { docmcp } from 'doc-mcpify/ts';
await docmcp({
docs: [
'./README.md',
'./docs/**/*.md',
'./src/**/*.ts', // All TypeScript files
],
standalone: true, {
"method": "GET",
"path": "/users/{id}",
"operationId": "getUser",
"summary": "Get a user by ID",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": [
Testing Your MCP Server
### 1. Start the server
```bash
node mcp-server.mjs
2.浏览器测试
http://localhost:3001/mcp/resources?search=button
应返回您的按钮文档/代码。
3.连接到VS Code
增添 .vscode/settings.json:
{
"mcp.servers": {
"my-docs": {
"command": "node",
"args": ["./mcp-server.mjs"]
}
}
}
重新加载VS代码(Ctrl+Shift+P→ “重新加载窗口”)
4.使用Copilot进行查询
问: “显示文档中的按钮组件”
如果它有效,Copilot将返回您的按钮代码! 🎉 }; };
//可见性控制 能见度?: { 包括?:string[];//要包含的全局模式 排除?:string[];//要排除的全局模式 内部曝光?:布尔值; };
//元数据覆盖 元数据?: { 标题?:字符串; 描述?:字符串; 版本?:字符串; 联系?:{名称?:string;电子邮件?:string?url?:string}; 许可证?:{name?:string;url?:string}; 服务器?:数组<{url:string;描述?:string}>; };
//启用详细日志记录 冗长?:布尔值;
//自定义解析器 解析器?:CustomParser[]; }
### Environment Variables
Configuration can also be set via environment variables:
- `DOC_MCP_DOCS` - Path to documentation
- `DOC_MCP_BASE_PATH` - Base path for endpoints
- `DOC_MCP_VERBOSE` - Enable verbose logging (`true` or `1`)
## Multiple Documentation Sources
Combine multiple documentation files:
```typescript
awaAdvanced Configuration
```javascript
await docmcp({
docs: [
'./docs/**/*.md',
'./src/**/*.{ts,tsx,js,jsx}',
],
// Base path for endpoints
basePath: '/mcp',
// Filter what gets exposed
visibility: {
include: ['./src/components/**/*'],
exclude: ['**/*.test.*', '**/__tests__/**'],
},
// Metadata override
metadata: {
title: 'My Library',
version: '2.0.0',
description: 'Library documentation',
},
// Enable logging
verbose: true,
// Standalone server options
standalone: true,
port: 3001,
host: '0.0.0.0',
});
支持的文件类型
| 类型 | 扩展名 | 提取内容 | 导入来源 |
|---|---|---|---|
| 标记语言 | .md, .mdx |
代码块、标题、内容 | doc-mcpify/md 或 doc-mcpify/mdx |
| TypeScript | .ts, .tsx |
导出、JSDoc、类型、接口 | doc-mcpify/ts |
| JavaScript | .js, .jsx, .mjs |
导出、JSDoc、函数 | doc-mcpify/js |
| 开放API | .yaml, .yml, .json |
端点、模式、身份验证 | doc-mcpify/openapi |
注: 使用子路径导入(如
/ts,/md)只安装该解析器所需的依赖项,保持您的node_modules轻量!//只包含某些路径 包括:['api/v1/“,”/公共/'],
// Exclude internal endpoints
exclude: ['/internal/*', '*/admin/*'],
// Don't expose internal/private endpoints
exposeInternal: false
} });
## Query Parameters
The `/mcp/endpoints` endpoint supports filtering:
GET/mcp/端点?tag=users#按标签筛选 GET/mcp/端点?method=POST#按HTTP方法筛选 GET/mcp/端点?path=/users#按路径子字符串筛选 GET/mcp/端点?弃用=false#排除已弃用
## Programmatic Access
Access the parsed schema programmatically:
```Real-World Examples
### Example 1: Component Library
```javascript
// mcp-server.mjs
import docmcp from 'doc-mcpify';
await docmcp({
docs: [
'./README.md',
'./docs/**/*.md',
'./src/components/**/*.tsx',
'./src/hooks/**/*.ts',
],
metadata: {
title: 'Acme UI Components',
description: 'React component library for Acme Corp',
},
standalone: true,
port: 3001,
});
副驾驶现在可以回答:
- “显示Acme按钮组件”
- “如何使用Acme Modal?”
- “获取Acme useTheme挂钩代码”
示例2:REST API
import docmcp from 'doc-mcpify';
await docmcp({
docs: [
'./openapi.yaml',
'./docs/getting-started.md',
'./docs/authentication.md',
],
standalone: true,
port: 3001,
});
副驾驶可以查询:
- API端点
- 身份验证流程
- 请求/响应示例
故障排除
MCP服务器未连接?
- 检查服务器是否正在运行:
node mcp-server.mjs - 验证VS代码设置中的端口是否正确
- 尝试重新加载VS代码窗口
- 检查终端是否有错误
副驾驶找不到我的医生?
- 测试终点:
http://localhost:3001/mcp/resources - 应随文档返回JSON
- 尝试搜索:
http://localhost:3001/mcp/resources?search=yourterm - 检查文档数组中的文件路径是否正确
TypeScript文件无法解析?
- 确保文件与glob模式匹配
- 检查语法是否有效(运行
tsc --noEmit) - 启用
verbose: true查看解析日志: 医生mcp服务 [选项]启动MCP服务器 doc-mcp验证 验证文档文件 医生mcp检查 检查并显示解析后的文档 doc-mcp--help显示此帮助消息 doc-mcp--version显示版本
选项: --端口,-p 监听端口(默认值:3000) --主机,-h 要绑定的主机(默认值:0.0.0.0) --基础路径,-b MCP端点的基本路径(默认值:/MCP) --verbose,-v启用详细日志记录
## Supported Documentation Formats
### OpenAPI
- OpenAPI 3.0.x
- OpenAPI 3.1.x
- Swagger 2.0
Files with `.yaml`, `.yml`, or `.json` extensions containing OpenAPI specs are automatically detected.
### Markdown
Markdown files are parsed for API documentation patterns:
```markdown
# My API
Version: 1.0.0
Base URL: https://api.example.com
## API Reference
Full TypeScript types exported:
```typescript
import type {
DocMcpConfig,
DocMcpInstance,
DocResource,
CodeExample,
NormalizedSchema,
} from 'doc-mcpify';
看 示例/ 了解更多使用模式。
贡献
欢迎投稿!看 贡献.md
许可证
麻省理工学院
由...制作❤️ 对于希望人工智能理解其文档的开发人员s API使用承载令牌身份验证。
添加授权标头: Authorization: Bearer your-token
端点
GET/users/{id}
按ID获取用户。
参数:
id(string)-用户ID
答复200:
- 用户对象
## TypeScript Support
Full TypeScript support with exported types:
```typescript
import type {
DocMcpConfig,
DocMcpInstance,
NormalizedSchema,
EndpointSchema,
McpDescribeResponse,
McpEndpointsResponse,
} from 'doc-mcp';
许可证
麻省理工学院