A Model Context Protocol (MCP) server that provides powerful image processing tools for Claude Code. This server implements three main functionalities: downloading toy-related images from the web, resizing images, and removing backgrounds from images.
- Anthropic MCP Pythone SDK Github repo: https://github.com/modelcontextprotocol/python-sdk?tab=readme-ov-file
- Downloads toy-related images from DuckDuckGo search
- Automatically prefixes search terms with "toy" for better results
- Supports downloading 1-10 images per request
- Saves images to a specified directory
- Resize images to specific dimensions
- Option to maintain aspect ratio
- High-quality resampling using Lanczos algorithm
- Support for all common image formats
- AI-powered background removal using state-of-the-art models
- Multiple model options (u2net, u2netp, silueta, isnet-general-use)
- Outputs PNG with transparent background
- Preserves main object details
- Python 3.11 or higher
- Docker (for containerized deployment)
- Claude Code (for MCP client integration)
-
Clone or create the project directory:
mkdir mcp-toy-image-tools && cd mcp-toy-image-tools
-
Install Python dependencies:
pip install -r requirements.txt
-
Run the server:
python server.py
-
Build the Docker image:
docker build -t mcp-toy-image-tools-server . -
Create necessary directories:
mkdir -p images input output
-
Run the container:
docker run --rm -i \ --name mcp-toy-image-tools \ -v $(pwd)/images:/app/images \ -v $(pwd)/input:/app/input \ -v $(pwd)/output:/app/output \ mcp-toy-image-tools-server
-
Copy the MCP configuration to your Claude Code settings:
For Docker execution:
{ "mcpServers": { "image-tools-server-docker": { "command": "docker", "args": [ "run", "--rm", "-i", "--name", "mcp-toy-image-tools", "-v", "${PWD}/images:/app/images", "-v", "${PWD}/input:/app/input", "-v", "${PWD}/output:/app/output", "mcp-toy-image-tools-server" ], "cwd": "/path/to/your/mcp-toy-image-tools" } } } -
Update the
cwdpath to match your actual project directory.
After updating your MCP configuration, restart Claude Code to load the new server.
Once integrated with Claude Code, you can use these commands:
Please use the fetch_toy_image tool to download 5 robot toy images to the ./images directory.
Can you resize the image at ./images/robot_toy_1.jpg to 800x600 pixels?
Please remove the background from ./images/robot_toy_1.jpg and save it as a PNG.
mcp-toy-image-tools/
βββ server.py # Main MCP server implementation
βββ requirements.txt # Python dependencies
βββ Dockerfile # Docker container configuration
βββ .mcp.json # Claude Code MCP configuration
βββ README.md # This documentation
βββ images/ # Directory for downloaded/processed images
βββ input/ # Directory for input images (Docker)
βββ output/ # Directory for output images (Docker)
- mcp: Anthropic's Model Context Protocol SDK
- Pillow: Python Imaging Library for image processing
- rembg: AI-powered background removal
- requests: HTTP client for downloading images
- duckduckgo-search: DuckDuckGo search API client
- torch/torchvision: PyTorch for AI model inference
- OpenGL libraries for image processing
- GLib and threading libraries
- Various image format support libraries
PYTHONPATH: Set to project directory for proper module resolution
/app/images: Directory for downloaded and processed images/app/input: Input directory for source images/app/output: Output directory for processed images
-
"duckduckgo-search library not available" error:
pip install duckduckgo-search
-
Image download failures:
- Check internet connection
- Some images may be blocked by the source website
- The tool automatically retries with additional results
-
Background removal model download:
- First use may take longer as AI models are downloaded
- Ensure sufficient disk space (~100MB+ for models)
-
Permission errors (Docker):
- Ensure volume mount directories have proper permissions
- The container runs as non-root user
mcp-user
To run with debug logging:
# Direct Python
PYTHONPATH=. python server.py --log-level DEBUG
# Docker
docker run --rm -i -e LOG_LEVEL=DEBUG mcp-toy-image-tools-server-
Server not appearing in Claude Code:
- Check that
.mcp.jsonis in the correct location - Verify the
cwdpath is correct - Restart Claude Code after configuration changes
- Check that
-
Tool execution errors:
- Check server logs for detailed error messages
- Ensure all dependencies are installed
- Verify file paths are accessible
To add new image processing tools:
-
Define the tool in
handle_list_tools():Tool( name="your_new_tool", description="Description of what it does", inputSchema={...} )
-
Implement the handler in
handle_call_tool():elif name == "your_new_tool": return await your_new_tool_function(arguments)
-
Add the async function implementation:
async def your_new_tool_function(arguments: dict[str, Any]) -> list[TextContent]: # Implementation here pass
Test the server independently:
echo '{"method": "tools/list", "params": {}}' | python server.pyThis project is provided as-is for educational and development purposes. Please respect the terms of service of image sources and AI models used.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
For issues and questions:
- Check the troubleshooting section above
- Review Claude Code MCP documentation
- Submit issues to the project repository
Note: This tool downloads images from the internet and uses AI models for processing. Please use responsibly and respect copyright and terms of service of source websites.