article
README
🚀 上下文7项目说明
本项目提供了一系列工具和服务,用于解析库ID、获取库文档等,能帮助开发者更高效地进行开发工作。
🚀 快速开始
安装与配置
使用npm进行安装
npm install -g @upstash/context7-mcp
启动服务
context7-mcp start --port 3001
📦 安装指南
示例配置
在package.json中添加如下内容:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp@latest"]
}
}
}
本地配置示例
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["tsx", "/path/to/folder/context7-mcp/src/index.ts"]
}
}
}
💻 使用示例
基础用法
const { Context7MCP } = require('@upstash/context7-mcp');
async function main() {
const mcp = new Context7MCP();
await mcp.start({ port: 3001 });
}
main().catch(console.error);
高级用法
const config = {
port: 3002,
logLevel: 'debug',
apiEndpoints: ['api.example.com', 'docs.example.com']
};
const { Context7MCP } = require('@upstash/context7-mcp');
async function main() {
const mcp = new Context7MCP(config);
await mcp.start();
}
main().catch(console.error);
📚 详细文档
工具介绍
resolve-library-id
将通用库名称解析为上下文7兼容的库ID。
- 参数:
libraryName(必需)
get-library-docs
使用上下文7兼容的库ID获取库文档。
- 参数:
context7CompatibleLibraryID(必需)topic(可选):聚焦于特定主题,例如“路由”、“钩子”tokens(可选,默认5000):返回的最大令牌数。小于配置的DEFAULT_MINIMUM_TOKENS值时会自动提升到该值。
开发指南
克隆项目并安装依赖
bun i
构建项目
bun run build
解决问题
模块未找到错误
如果出现此错误,请尝试使用bunx代替npx。
{
"mcpServers": {
"context7": {
"command": "bunx",
"args": ["-y", "@upstash/context7-mcp@latest"]
}
}
}
ESM解析问题
如果遇到类似Error: Cannot find module 'uriTemplate.js'的错误,请尝试使用以下命令:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": [
"-y",
"--node-options=--experimental-vm-modules",
"@upstash/context7-mcp@1.0.6"
]
}
}
}
客户端错误处理
- 如果出现错误,请尝试移除
@latest版本号。 - 尝试使用
bunx作为替代方案。 - 考虑使用
deno作为另一种选择。 - 确保使用Node.js v18或更高版本以获得
npx的原生fetch支持。
文档示例
解决问题步骤
- 安装依赖:
npm install @upstash/context7-mcp - 创建配置文件:
context7-config.json - 启动服务:
npx context7-mcp start --port 3001
最佳实践
- 总是使用最新版本以获得最佳性能和安全更新。
- 在生产环境中,建议将端口配置为非默认值以提高安全性。
- 定期检查文档更新,保持项目知识的及时性。
环境变量配置
设置默认端口
export DEFAULT_PORT=3002
配置日志级别
export LOG_LEVEL=info
🔧 技术细节
媒体报道
📄 许可证
本项目遵循MIT许可证。查看LICENSE获取详细信息。
联系方式
如需帮助或反馈,请访问GitHub仓库或联系email@example.com。
贡献指南
欢迎社区贡献!请参考CONTRIBUTING.md了解如何参与开发。
扫码联系在线客服