Process images (dimensions, color pick, compress, crop, background removal) via sharp-mcp (npx)
sharp-mcp v0.2.6 is a session-based image processing MCP server powered by the sharp library. Unlike mcp-image-tools (uvx/Python), it uses a session model: load an image into a session, then chain operations on the session ID. Includes ML-based background removal via @imgly/background-removal-node.
Install: npx -y [email protected] (stdio transport)
Tools (8): createsession (base64), createsessionbypath (file path), listsession, getdimensions, pickcolor, extractregion, compressimage, removebackground
Session workflow: All tools after create_session take a sessionId parameter. The session persists the image in memory for the server's lifetime.
Note on pick_color: The radius parameter controls sampling area. With radius=1 on a 4x4 image, it averaged to gray (#808080) instead of the exact pixel color. Use radius=0 (if supported) or be aware of the averaging behavior for pixel-precise work.
Recipe: Process images via sharp-mcp session workflow (npx)
Server: npx -y [email protected] — stdio transport, no auth, uses sharp + @imgly/background-removal-node.
Step 1: Initialize
→ {"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"pathfinder","version":"1.0"}}}
← serverInfo: {"name":"sharp-mcp","version":"0.2.6"}, 8 toolsStep 2: Create session from file
→ {"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"create_session_by_path","arguments":{"path":"/tmp/test-pathfinder.png","description":"4x4 test image with 16 colors"}}}
← {"sessionId":"img_K7D6NyM6JsAVcyTm8BBag","source_path":"/tmp/test-pathfinder.png","file_size":101}Step 3: Get dimensions
→ {"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"get_dimensions","arguments":{"sessionId":"img_K7D6NyM6JsAVcyTm8BBag"}}}
← {"width":4,"height":4,"mimeType":"image/png"}Step 4: Pick color at (0,0)
→ {"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"pick_color","arguments":{"sessionId":"img_K7D6NyM6JsAVcyTm8BBag","x":0,"y":0,"radius":1}}}
← {"r":128,"g":128,"b":128,"hex":"#808080"}Note: radius=1 averages a 2×2 area, so the returned color is the average of neighboring pixels, not the exact pixel. For pixel-precise work, request the smallest possible radius.
Step 5: Compress to WebP
→ {"jsonrpc":"2.0","id":6,"method":"tools/call","params":{"name":"compress_image","arguments":{"sessionId":"img_K7D6NyM6JsAVcyTm8BBag","format":"webp","quality":80,"output_path":"/tmp/test-pathfinder-compressed.webp"}}}
← {"success":true,"path":"/tmp/test-pathfinder-compressed.webp","format":"webp","originalSize":101,"compressedSize":90,"compressionRatio":"10.89%"}Key pattern
All operations reference a sessionId — create the session first (from base64 or file path), then chain any number of operations. The session lives in-memory for the server's lifetime.
{ "server": "sharp-mcp", "version": "0.2.6", "install": "npx -y [email protected]", "transport": "stdio", "tools_count": 8, "tools": ["create_session", "create_session_by_path", "list_session", "get_dimensions", "pick_color", "extract_region", "compress_image", "remove_background"], "calls": [ { "tool": "create_session_by_path", "args": { "path": "/tmp/test-pathfinder.png" }, "result": { "sessionId": "img_K7D6NyM6JsAVcyTm8BBag", "file_size": 101 }, "ok": true }, { "tool": "get_dimensions", "args": { "sessionId": "img_K7D6NyM6JsAVcyTm8BBag" }, "result": { "width": 4, "height": 4, "mimeType": "image/png" }, "ok": true }, { "tool": "pick_color", "args": { "sessionId": "img_K7D6NyM6JsAVcyTm8BBag", "x": 0, "y": 0, "radius": 1 }, "result": { "r": 128, "g": 128, "b": 128, "hex": "#808080" }, "ok": true, "note": "radius=1 averages 2x2 area" }, { "tool": "compress_image", "args": { "sessionId": "img_K7D6NyM6JsAVcyTm8BBag", "format": "webp", "quality": 80 }, "result": { "success": true, "originalSize": 101, "compressedSize": 90, "compressionRatio": "10.89%" }, "ok": true } ] }