Snap.as MCP服务器
用于上传照片的模型上下文协议(MCP)服务器 Snap.as 使用Write.as身份验证。
特性
- 将JPG、PNG或GIF图像(最大10MB)上传到Snap.as
- 使用短期访问令牌进行自动Write.as身份验证
- 返回上传照片的公共URL
- 可配置的响应格式(Markdown或JSON)
- 具有可操作消息的全面错误处理
安装
NPX用法(推荐)
无需安装!直接与npx一起使用:
npx snapas-mcp-server本地安装
npm install -g snapas-mcp-server配置
服务器需要Write.as凭据进行身份验证。设置这些环境变量:
export WRITEAS_USERNAME="your-username"
export WRITEAS_PASSWORD="your-password"安全说明:访问令牌是短暂的,每次请求时都会自动获得。切勿直接存储或配置访问令牌。
用法
作为MCP服务器
添加到您的MCP客户端配置中(例如,Claude Desktop):
{
"mcpServers": {
"snapas": {
"command": "npx",
"args": ["snapas-mcp-server"],
"env": {
"WRITEAS_USERNAME": "your-username",
"WRITEAS_PASSWORD": "your-password"
}
}
}
}可用工具
snapas_upload_photo
将图像文件上传到Snap.as并接收公共URL。
参数:
file_path(string,必填):图像文件的绝对路径username(字符串,可选):Write.as用户名(覆盖env变量)password(字符串,可选):Write.as密码(覆盖env变量)response_format(字符串,可选):输出格式-"json"(默认)或"markdown"
示例用法:
// Via MCP tool call (default JSON response)
{
"file_path": "/Users/username/photos/sunset.jpg"
}响应(JSON格式-默认):
{
"id": "abc123",
"filename": "sunset.jpg",
"size": 245760,
"url": "https://i.snap.as/abc123.jpg"
}响应(Markdown格式):
// Via MCP tool call with markdown response
{
"file_path": "/Users/username/photos/sunset.jpg",
"response_format": "markdown"
}## Photo Uploaded Successfully
**URL:** https://i.snap.as/abc123.jpg
**ID:** abc123
**Filename:** sunset.jpg
**Size:** 240.00 KB
You can access the photo at: https://i.snap.as/abc123.jpg支持的文件类型
- JPG/JPEG(
.jpg,.jpeg) - PNG(
.png) - GIF(
.gif)
最大文件大小:10MB
错误处理
服务器提供清晰、可操作的错误消息:
- 认证失败:Write.as凭据无效(HTTP 401)
- 文件未找到:指定的文件路径不存在
- 不支持的文件类型:文件必须是JPG、PNG或GIF
- 文件超过10MB限制:文件太大
- 请求频率超限:请求太多(HTTP 429)
- 访问被拒绝:权限不足(HTTP 403)
发展
先决条件
- Node.js>=18
- npm
设置
# Clone the repository
git clone https://github.com/rawveg/snapas-mcp
cd snapas-mcp-server
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
# Test locally
npm start测试
该项目使用Vitest,具有全面的测试覆盖率:
# Run tests once
npm test
# Watch mode
npm run test:watch
# Coverage report
npm run test:coverage项目结构
snapas-mcp-server/
├── src/
│ ├── __tests__/ # Test files
│ │ ├── services/
│ │ └── utils/
│ ├── services/ # API clients
│ │ ├── snapas-client.ts
│ │ └── writeas-client.ts
│ ├── utils/ # Utilities
│ │ ├── auth.ts
│ │ └── file-handler.ts
│ ├── constants.ts # Configuration constants
│ ├── index.ts # MCP server entry point
│ ├── schemas.ts # Zod validation schemas
│ └── types.ts # TypeScript types
├── package.json
├── tsconfig.json
└── vitest.config.tsAPI参考资料
许可证
AGPL-3.0或更高版本
贡献
欢迎投稿!请随时提交拉取请求。
