MCP server for uploading local images to Sanity CMS.
Lets AI assistants upload files from your filesystem directly into Sanity as image assets.
______________________________________________________________________
快速开始
1.获取您的理智令牌
要么设置 SANITY_TOKEN env-var,或者只需使用Sanity CLI登录:
npx sanity login服务器自动从Sanity CLI配置中读取令牌(~/.config/sanity/config.json 在所有平台上)。
2.添加到克劳德代码
claude mcp add sanity-images --scope user --transport stdio \
-e SANITY_PROJECT_ID=your-project-id \
-- npx -y mcp-sanity-images@latest就是这样。重新启动Claude Code,工具就可用了。每个会话都会自动运行最新版本。
也与 bunx mcp-sanity-images@latest 如果你有 包子.Alternative: standalone binary
从下载预构建的二进制文件 发布:
| 平台 | 文件 |
|---|---|
| macOS(苹果硅) | mcp-sanity-images-darwin-arm64 |
| macOS(英特尔) | mcp-sanity-images-darwin-x64 |
| Linux | mcp-sanity-images-linux-x64 |
| 窗户 | mcp-sanity-images-windows-x64.exe |
macOS/Linux:
curl -Lo mcp-sanity-images https://github.com/pijusz/mcp-sanity-images/releases/latest/download/mcp-sanity-images-darwin-arm64
chmod +x mcp-sanity-images
sudo mv mcp-sanity-images /usr/local/bin/
claude mcp add sanity-images --scope user --transport stdio \
-e SANITY_PROJECT_ID=your-project-id \
-- /usr/local/bin/mcp-sanity-imagesWindows(PowerShell):
Invoke-WebRequest -Uri "https://github.com/pijusz/mcp-sanity-images/releases/latest/download/mcp-sanity-images-windows-x64.exe" -OutFile "$env:LOCALAPPDATA\mcp-sanity-images.exe"
claude mcp add sanity-images --scope user --transport stdio -e SANITY_PROJECT_ID=your-project-id -- "%LOCALAPPDATA%\mcp-sanity-images.exe"克劳德桌面版
添加到您的 claude_desktop_config.json:
Using npx (auto-updates)
{
"mcpServers": {
"sanity-images": {
"command": "npx",
"args": ["-y", "mcp-sanity-images@latest"],
"env": {
"SANITY_PROJECT_ID": "your-project-id"
}
}
}
}Using binary (macOS / Linux)
{
"mcpServers": {
"sanity-images": {
"command": "/usr/local/bin/mcp-sanity-images",
"env": {
"SANITY_PROJECT_ID": "your-project-id"
}
}
}
}Using binary (Windows)
{
"mcpServers": {
"sanity-images": {
"command": "%LOCALAPPDATA%\\mcp-sanity-images.exe",
"env": {
"SANITY_PROJECT_ID": "your-project-id"
}
}
}
}工具
| 工具 | 说明 |
|---|---|
upload_image | 将单个本地图像作为资产上传到Sanity |
upload_and_set | 上传图像并将其修补到文档字段上 |
batch_upload | 将文件夹中的所有图像作为资源上传 |
list_images | 列出目录中的图像文件 |
groq_query | 运行GROQ查询(在附加之前查找文档) |
支持的格式:PNG、JPG/JPEG、WebP、GIF、SVG。
配置
| Env-var | 必需 | 默认 | 描述 |
|---|---|---|---|
SANITY_PROJECT_ID | 是 | -- | 您的Sanity项目ID |
SANITY_DATASET | 没有 | production | 数据集名称 |
SANITY_TOKEN | 没有\* | - | neneneba API令牌(\*返回到CLI身份验证) |
所有工具也接受 projectId 和 dataset 作为参数,覆盖每次调用的env变量。
工具详细信息
upload_image
上传一个文件并获取资产引用。
filePath: "/path/to/hero.png"
alt: "Hero banner" (optional — derived from filename)退货 { assetId, url, alt, reference } --the reference 已准备好修补任何Sanity图像字段。
upload_and_set
一次通话上传+补丁。
filePath: "/path/to/hero.png"
documentId: "product-123"
fieldPath: "hero.image"批量上传
上传目录中的所有图像。
directory: "/path/to/images"
recursive: truelist_images
列出不上传的图像文件——这对AI查看可用内容很有用。
directory: "/path/to/images"
recursive: truegroq_query
运行任何GROQ查询。使用前查找文档ID很有用 upload_and_set.
query: "*[_type == 'product']{_id, title, slug}"更新
使用 npx @latest (推荐):您始终获得最新版本,无需手动更新。
使用二进制:服务器在启动时检查新版本,如果过时,则记录到stderr:
[update] v0.2.0 available (current: v0.1.0). Download: https://github.com/pijusz/mcp-sanity-images/releases/latest检查您安装的版本:
mcp-sanity-images --version要更新,请下载新的二进制文件并替换旧的。
发展
需要 包子.
git clone https://github.com/pijusz/mcp-sanity-images.git
cd mcp-sanity-images
bun install
bun test # 37 tests
bun run lint # biome check
bun run build # compile standalone binary许可证
麻省理工学院
