Skip to main content
Glama
short-pixel-optimizer

ShortPixel MCP Server

Official

ShortPixel MCP 服务器

面向 AI 代理(Cursor、Claude Desktop、VS Code 等)公开 ShortPixel SPIO 图像优化功能的公共 HTTP MCP 服务器。

架构

AI client (Cursor, Claude, …)
    │
    │  MCP over HTTPS (Streamable HTTP)
    ▼
https://mcp.shortpixel.com/mcp
    │
    │  user's API key in Authorization header
    ▼
ShortPixel SPIO API (api.shortpixel.com)

每个请求携带用户自己的 ShortPixel API 密钥。MCP 服务器不存储用户密钥——而是将其转发到公共 SPIO API。

Related MCP server: img-convert MCP Server

要求

  • Node.js 20+

  • npm

安装(服务器)

npm ci
npm run build
cp .env.example .env

编辑 .env 以配置服务器设置(端口、允许的主机、上游 API URL)。不要将用户 API 密钥放入服务器 .env 中。

运行

npm start

端点:

路径

方法

描述

/health

GET

健康检查(无需 API 密钥)

/ping

GET

认证检查——如果存在 API 密钥头则返回 ok

/mcp

POST

MCP 流式 HTTP 端点

快速测试(curl)

服务器启动,无 API 密钥:

curl http://mcp.shortpixel.com:3000/health

存在 API 密钥(简单检查):

curl -i -H "Authorization: Bearer YOUR_API_KEY" http://mcp.shortpixel.com:3000/ping

使用 http://(而非 https://)和端口 3000,除非在 nginx 上配置了 TLS。

MCP 请求(重要:流式 HTTP 客户端必须同时接受 JSON 和 SSE):

curl -s -N -X POST http://mcp.shortpixel.com:3000/mcp \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'

认证

在每个 MCP 请求中发送用户的 ShortPixel API 密钥:

Authorization: Bearer <shortpixel_api_key>

备选头:

X-ShortPixel-Api-Key: <shortpixel_api_key>

没有密钥的用户可以在 shortpixel.com 获取一个。

Cursor 设置(最终用户)

{
  "mcpServers": {
    "shortpixel": {
      "url": "https://mcp.shortpixel.com/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_SHORTPIXEL_API_KEY"
      }
    }
  }
}

开发期间将 URL 替换为你的部署主机(例如 http://localhost:3000/mcp)。

服务器环境变量

变量

必需

默认值

描述

PORT

3000

HTTP 监听端口

ALLOWED_HOSTS

逗号分隔的 Host 头允许列表(生产环境推荐)

SHORTPIXEL_API_URL

https://api.shortpixel.com/v2

上游 SPIO API 基础 URL

SHORTPIXEL_PLUGIN_VERSION

MCP01

发送给 SPIO 的插件版本

LOG_LEVEL

info

日志详细程度:debuginfowarnerror

LOG_FORMAT

text

text = 人类可读行;json = 结构化 JSON

LOG_MCP_PROTOCOL

true

记录入站/出站 MCP JSON-RPC 负载

对于内部 ShortPixel 开发,设置 SHORTPIXEL_API_URL=https://devapi2.shortpixel.com/v2

请求日志

日志输出到 stdout(pm2 logs / npm start)。

默认(LOG_FORMAT=text——可追踪的叙述流:

[2026-06-30 15:01:53] [1/5] → CLIENT | HTTP POST /mcp | JSON-RPC request: "initialize" (client connects) | id: 0
           {
             "jsonrpc": "2.0",
             "method": "initialize",
             "id": 0,
             "params": { ... }
           }
[2026-06-30 15:01:53] [1/5] ← SERVER | HTTP POST /mcp 200 | JSON-RPC response: "initialize" (client connects)
[2026-06-30 15:01:53] [2/5] → CLIENT | HTTP POST /mcp | JSON-RPC request: "notifications/initialized" (session ready, no response body expected) | id: null
[2026-06-30 15:01:53] [2.5/5] → CLIENT | HTTP POST /mcp | JSON-RPC request: "tools/list" (client asks which tools exist) | id: 1
[2026-06-30 15:01:53] [2.5/5] ← SERVER | HTTP POST /mcp 200 | JSON-RPC response: "tools/list" (client asks which tools exist) | tools discovered: optimize_image_urls
[2026-06-30 15:02:18] [3/5] → CLIENT | HTTP POST /mcp | JSON-RPC request: "tools/call" (client runs a tool) | id: 2 | tool: "optimize_image_urls"
[2026-06-30 15:02:18] [4/5] MCP → SPIO API: POST reducer.php (args mapped to SPIO payload) | ...
[2026-06-30 15:02:35] [5/5] MCP ← SPIO API: Success | reduction: 27.41% | optimized: http://api.shortpixel.com/f/...-lossy.jpg | original: ...
[2026-06-30 15:02:35] [3/5] ← SERVER | HTTP POST /mcp 200 | JSON-RPC response: "tools/call" (client runs a tool) | tool: optimize_image_urls
           { "jsonrpc": "2.0", "id": 2, "result": { ... } }
[2026-06-30 15:02:35]     ✓ round-trip done (16.3s)

LOG_MCP_PROTOCOL=false 仅保留高级应用日志,隐藏 MCP 负载转储。

结构化(LOG_FORMAT=json——每行一个 JSON 对象:

事件

触发时机

http_request

每个请求(方法、路径、状态、耗时、MCP 方法/工具)

spio_request

对 SPIO reducer.php 的出站调用

spio_response

SPIO 结果摘要(状态、改进百分比)

mcp_auth_missing

无 API 密钥的请求

API 密钥被屏蔽(****abcd)。完整密钥永远不会被记录。

注意: 聊天提示永远不会到达此服务器。LLM(在 MCP 客户端内部)将用户文本转换为结构化的 tools/call;服务器仅看到 JSON-RPC 参数并将其映射到 SPIO API。

pm2 logs shortpixel-mcp
# or
npm start

设置 LOG_LEVEL=debug 以查看 tools/list 和额外的 HTTP 行。

在开发服务器上部署

cd /xxx/mcp.shortpixel.com
npm ci
npm run build
cp .env.example .env
# set ALLOWED_HOSTS and PORT, then run behind nginx with TLS
npm start

每次依赖变更后重新上传 package.jsonpackage-lock.json。如果构建仍然失败,运行 npm ci --include=dev(某些服务器设置了 NODE_ENV=production,会跳过 devDependencies)。

可用的 MCP 工具

工具

描述

optimize_image_urls

通过 SPIO reducer API 优化一个或多个公共图片 URL

optimize_image_urls 参数:

  • urls(必需):要优化的公共图片 URL(最多 100 个)

  • lossy:压缩级别(0 无损,1 有损,2 光泽)

  • wait:最大等待秒数(0 立即返回,1-30 等待)

  • upscale:放大倍数(0234

  • resize:调整大小模式(0 无,1 外切,3 内切,4 智能裁剪)

  • resize_widthresize_height:调整大小的目标像素尺寸

  • cmyk2rgb:将 CMYK 转换为 RGB(1 是,0 否)

  • keep_exif:保留 EXIF 元数据(1 保留,0 移除)

  • convertto:转换值(+webp+avif+webp|+avifwebp|avifjpgpnggif

  • bg_remove:背景移除(1、图片 URL 或 #rrggbbxx

  • refresh:强制重新获取源(1)或使用缓存的优化数据(0

  • paramlist:每个 URL 的覆盖数组(必须与 urls 长度匹配)

  • returndatalist:任何数组,在响应中原样返回

项目布局

src/index.ts                    HTTP server entry point
src/http/auth.ts                API key extraction from requests
src/mcp/create-mcp-server.ts    Per-request MCP server factory
src/clients/spio-api-client.ts  ShortPixel SPIO HTTP client
src/tools/spio-tools.ts         MCP tools
src/http/request-log-middleware.ts HTTP request logging
src/logging/request-logger.ts    Structured JSON logger
src/logging/mcp-protocol-log.ts  MCP protocol payload capture/normalize

命名约定

种类

风格

示例

文件

kebab-case

spio-api-client.ts

PascalCase

SpioApiClient

方法

camelCase

optimizeUrls

脚本

命令

描述

npm run build

将 TypeScript 编译到 dist/

npm start

运行 HTTP MCP 服务器

npm run dev

使用 tsx 运行(无需构建步骤)

F
license - not found
-
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • SEO research, audits, backlinks, GSC, and content workflow tools for AI agents.

  • Zero-auth MCP: image optimize, cited storage/format data, and dev utilities LLMs get wrong.

  • URL intelligence for AI agents and developers. 16 tools, 25 signal weights, 20 free checks.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/short-pixel-optimizer/com.shortpixel.mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server