这是一个提供与Dropbox集成的模型上下文协议(MCP)服务器,借助一组强大的工具,可实现MCP兼容客户端与Dropbox之间的交互。
⚠️ 重要提示
此项目未获得Dropbox的附属、认可或赞助。它是一个独立的整合项目,通过使用Dropbox的公共API来开展工作。
npm install 安装依赖项。npm run build 构建项目。DROPBOX_APP_KEYDROPBOX_APP_SECRETnpm run start
要安装项目并运行示例,请执行以下步骤:
git clone [仓库地址]
cd dbx - mcp - server
npm install
DROPBOX_APP_KEY:你的 Dropbox 应用密钥。DROPBOX_APP_SECRET:你的 Dropbox 应用秘密。npm run start
此服务器使用基于OAuth 2.0的PKCE(行业标准)进行身份验证。以下是主要的身份验证步骤:
GET https://accounts.dropbox.com/oauth2/authorize?client_id=APP_KEY&response_type=code&redirect_uri=REDIRECT_URI
POST https://api.dropbox.com/oauth2/token
Content - Type: application/x - www - form - urlencoded
grant_type=authorization_code&code=AUTHORIZATION_CODE&redirect_uri=REDIRECT_URI
{
"access_token": "ACCESS_TOKEN",
"token_type": "Bearer",
"expires_in": 3600,
"refresh_token": "REFRESH_TOKEN"
}
以下是此服务器提供的主要功能:
POST /files/upload
Content - Type: multipart/form - data
file=@/path/to/file
GET /files/download?file_id=FILE_ID
GET /files/list?directory=DIRECTORY_ID
POST /metadata/search
Content - Type: application/json
{
"query": "SEARCH_TERM"
}
GET /metadata/file?file_id=FILE_ID
POST /directories/create
Content - Type: application/json
{
"name": "DIRECTORY_NAME",
"parent_id": "PARENT_DIRECTORY_ID"
}
DELETE /directories/delete?directory_id=DIRECTORY_ID
要在服务器上配置环境变量,请添加以下变量:
DROPBOX_APP_KEY:你的 Dropbox 应用密钥。DROPBOX_APP_SECRET:你的 Dropbox 应用秘密。PORT:可选,默认为3000,指定服务器运行的端口。服务器返回以下错误码:
401 Unauthorized:无效或过期令牌。403 Forbidden:被阻止的操作。404 Not Found:资源未找到。500 Internal Server Error:服务器内部错误。项目依赖以下库:
curl -X POST http://localhost:3000/files/upload \
-F "file=@/path/to/file.txt"
curl http://localhost:3000/files/download?file_id=FILE_ID
curl -X POST http://localhost:3000/metadata/search \
-H "Content - Type: application/json" \
-d '{"query": "search_term"}'
为了测试服务器功能,请运行以下命令:
npm test
git clone [仓库地址]
cd dbx - mcp - server
npm install
npm test
要运行特定测试或测试组,请使用以下命令:
npm test -- tests/dropbox/search - delete.test.ts # 运行特定测试文件
npm test -- -t "should search for files" # 运行匹配描述的测试
项目使用 MIT 许可证。
感谢所有贡献者!
如遇问题,请在 GitHub Issues/issues 提交问题。
💡 使用建议
此示例代码旨在提供一个起点,具体实现可能需要根据实际需求调整。