软件包文档 MCP 服务器
MCP(模型上下文协议)服务器为 LLM 提供跨多种编程语言和语言服务器协议 (LSP) 功能对包文档的有效访问。
特征
- 多语言支持:
- 通过
go doc
获取 Go 软件包 - 通过内置
help()
Python 库 - 通过注册表文档(包括私有注册表)的 NPM 包
- 通过 crates.io 和 docs.rs 获取 Rust 板条箱
- 智能文档解析:
- 包含描述、用法和示例的结构化输出
- 重点突出的信息,避免上下文过载
- 支持特定符号/函数查找
- 跨文档的模糊和精确搜索功能
- 高级搜索功能:
- 在包文档中搜索
- 模糊匹配,灵活查询
- 具有相关性评分的上下文感知结果
- 从搜索结果中提取符号
- 语言服务器协议(LSP)支持:
- 代码符号的悬停信息
- 代码补全
- 诊断(错误和警告)
- 目前支持 TypeScript/JavaScript
- 可扩展至其他语言
- 性能优化:
安装
通过 Smithery 安装
要通过Smithery自动安装 Claude Desktop 的 Package Docs:
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 crate 文档
{
"name": "describe_rust_package",
"arguments": {
"package": "serde", // required: crate name
"version": "1.0.219" // optional: specific version
}
}
搜索包文档
在包文档中搜索
{
"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 支持后,以下附加工具将可用:
获取悬停
获取文档中某个位置的悬停信息
{
"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
}
}
获取完成信息
获取文档中某个位置的完成建议
{
"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
}
}
获取诊断
获取文档的诊断信息(错误、警告)
{
"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 包文档)
- 语言服务器(用于 LSP 功能):
- TypeScript/JavaScript:
npm install -g typescript-language-server typescript
- HTML/CSS/JSON:
npm install -g vscode-langservers-extracted
发展
# 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
) - 打开拉取请求
执照
该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅LICENSE文件。