MCP 包文档优化器
帮助大型语言模型(LLM)高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化提升软件开发效率。
服务介绍
包文档 MCP 服务器
一个提供多种编程语言和语言服务器协议(LSP)功能的包文档高效访问的MCP(模型上下文协议)服务器。
特性
-
多语言支持:
- 通过
go doc支持 Go 包 - 通过内置
help()支持 Python 库 - 通过注册表文档支持 NPM 包(包括私有注册表)
- 通过 crates.io 和 docs.rs 支持 Rust 包
- 通过
-
智能文档解析:
- 结构化输出,包含描述、用法和示例
- 聚焦信息以避免上下文过载
- 支持特定符号/函数查找
- 文档中的模糊和精确搜索功能
-
高级搜索功能:
- 在包文档中搜索
- 模糊匹配以实现灵活查询
- 带相关性评分的上下文感知结果
- 从搜索结果中提取符号
-
语言服务器协议 (LSP) 支持:
- 代码符号悬停信息
- 代码补全
- 诊断(错误和警告)
- 当前支持 TypeScript/JavaScript
- 可扩展到其他语言
-
性能优化:
- 内置缓存
- 高效解析
- 最小内存占用
安装
npx -y mcp-package-docs
通过 Smithery 安装
要通过 Smithery 自动为 Claude Desktop 安装包文档:
npx -y @smithery/cli install mcp-package-docs --client claude
使用
作为 MCP 服务器
- 添加到您的 MCP 设置配置中:
{
"mcpServers": {
"package-docs": {
"command": "npx",
"args": ["-y", "mcp-package-docs"],
"env": {
"ENABLE_LSP": "true" // Optional: Enable Language Server Protocol support
}
}
}
}
- LSP 功能包括对常用语言服务器的默认配置:
- TypeScript/JavaScript:
typescript-language-server --stdio - HTML:
vscode-html-language-server --stdio - CSS:
vscode-css-language-server --stdio - JSON:
vscode-json-language-server --stdio
如果需要,您可以覆盖这些默认设置:
{
"mcpServers": {
"package-docs": {
"command": "npx",
"args": ["-y", "mcp-package-docs"],
"env": {
"ENABLE_LSP": "true",
"TYPESCRIPT_SERVER": "{\"command\":\"/custom/path/typescript-language-server\",\"args\":[\"--stdio\"]}"
}
}
}
}
- 服务器提供以下工具:
lookup_go_doc / describe_go_package
获取 Go 包文档
{
"name": "describe_go_package",
"arguments": {
"package": "encoding/json", // required
"symbol": "Marshal" // optional
}
}
lookup_python_doc / describe_python_package
获取 Python 包文档
{
"name": "describe_python_package",
"arguments": {
"package": "requests", // required
"symbol": "get" // optional
}
}
describe_rust_package
从 crates.io 和 docs.rs 获取 Rust 包文档
{
"name": "describe_rust_package",
"arguments": {
"package": "serde", // required: crate name
"version": "1.0.219" // optional: specific version
}
}
search_package_docs
在包文档中搜索
{
"name": "search_package_docs",
"arguments": {
"package": "requests", // required: package name
"query": "authentication", // required: search query
"language": "python", // required: "go", "python", "npm", "swift", or "rust"
"fuzzy": true // optional: enable fuzzy matching (default: true)
}
}
lookup_npm_doc / describe_npm_package
从公共和私有注册表中获取 NPM 包文档。根据您的 .npmrc 配置自动使用适当的注册表。
{
"name": "describe_npm_package",
"arguments": {
"package": "axios", // required - supports both scoped (@org/pkg) and unscoped packages
"version": "1.6.0" // optional
}
}
该工具读取您的 ~/.npmrc 文件以确定每个包的正确注册表:
- 使用作用域注册表配置(例如,@mycompany:registry=...)
- 支持私有注册表(GitHub Packages、GitLab、Nexus、Artifactory 等)
- 如果没有配置自定义注册表,则回退到默认的 npm 注册表
示例 .npmrc 配置:
registry=https://nexus.mycompany.com/repository/npm-group/
@mycompany:registry=https://nexus.mycompany.com/repository/npm-private/
@mycompany-ct:registry=https://npm.pkg.github.com/
语言服务器协议 (LSP) 工具
当启用 LSP 支持时,以下附加工具将变得可用:
get_hover
获取文档中某个位置的悬停信息
{
"name": "get_hover",
"arguments": {
"languageId": "typescript", // required: language identifier (e.g., "typescript", "javascript")
"filePath": "src/index.ts", // required: path to the source file
"content": "const x = 1;", // required: content of the file
"line": 0, // required: zero-based line number
"character": 6, // required: zero-based character position
"projectRoot": "/path/to/project" // optional: project root directory
}
}
get_completions
获取文档中某个位置的补全建议
{
"name": "get_completions",
"arguments": {
"languageId": "typescript", // required: language identifier
"filePath": "src/index.ts", // required: path to the source file
"content": "const arr = []; arr.", // required: content of the file
"line": 0, // required: zero-based line number
"character": 16, // required: zero-based character position
"projectRoot": "/path/to/project" // optional: project root directory
}
}
get_diagnostics
获取文档的诊断信息(错误、警告)
{
"name": "get_diagnostics",
"arguments": {
"languageId": "typescript", // required: language identifier
"filePath": "src/index.ts", // required: path to the source file
"content": "const x: string = 1;", // required: content of the file
"projectRoot": "/path/to/project" // optional: project root directory
}
}
在 LLM 中的示例用法
查找文档
// Looking up Go documentation
const goDocResult = await use_mcp_tool({
server_name: "package-docs",
tool_name: "describe_go_package",
arguments: {
package: "encoding/json",
symbol: "Marshal"
}
});
// Looking up Python documentation
const pythonDocResult = await use_mcp_tool({
server_name: "package-docs",
tool_name: "describe_python_package",
arguments: {
package: "requests",
symbol: "post"
}
});
// Looking up Rust documentation
const rustDocResult = await use_mcp_tool({
server_name: "package-docs",
tool_name: "describe_rust_package",
arguments: {
package: "serde"
}
});
// Searching within documentation
const searchResult = await use_mcp_tool({
server_name: "package-docs",
tool_name: "search_package_docs",
arguments: {
package: "serde",
query: "serialize",
language: "rust",
fuzzy: true
}
});
// Using LSP for hover information (when LSP is enabled)
const hoverResult = await use_mcp_tool({
server_name: "package-docs",
tool_name: "get_hover",
arguments: {
languageId: "typescript",
filePath: "src/index.ts",
content: "const axios = require('axios');\naxios.get",
line: 1,
character: 7
}
});
要求
- Node.js >= 20
- Go(用于 Go 包文档)
- Python 3(用于 Python 包文档)
- 网络连接(用于 NPM 包文档和 Rust crate 文档)
- 语言服务器(用于 LSP 功能):
- TypeScript/JavaScript:
npm install -g typescript-language-server typescript - HTML/CSS/JSON:
npm install -g vscode-langservers-extracted
- TypeScript/JavaScript:
开发
# Install dependencies
npm i
# Build
npm run build
# Watch mode
npm run watch
贡献
- 分叉仓库
- 创建你的功能分支 (
git checkout -b feature/amazing-feature) - 提交你的更改 (
git commit -m 'Add some amazing feature') - 推送到分支 (
git push origin feature/amazing-feature) - 打开一个 Pull Request
许可证
此项目根据 MIT 许可证授权 - 详情请参阅 LICENSE 文件。