MCP Server Deployment Guide
Self-host the BuyWhere MCP server for AI agent integrations.
Table of Contents
- Prerequisites
- Local Setup
- Docker Deployment
- Environment Variables
- Troubleshooting
- Testing with Claude Desktop
Prerequisites
- Python 3.10 or higher
- pip or pip3
- A BuyWhere API key (get one)
- Linux, macOS, or Windows
Local Setup
1. Clone or navigate to the repository
git clone https://github.com/buywhere/buywhere-api.git
cd buywhere-api
2. Create a virtual environment (recommended)
python3 -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
3. Install dependencies
pip install -r requirements.txt
Required packages:
httpx— async HTTP clientmcp— Model Context Protocol server frameworkfastapi— web frameworkuvicorn— ASGI server
4. Configure environment variables
Create a .env file or export variables:
# Required
export BUYWHERE_API_KEY="your_api_key_here"
# Optional (defaults shown)
export BUYWHERE_API_URL="http://localhost:8000"
export BUYWHERE_MCP_HTTP_PORT="8080"
5. Run the MCP server
STDIO transport (default, recommended for desktop agents like Claude Desktop):
python mcp_server.py
HTTP/SSE transport (for web or cloud deployments):
python mcp_server.py --transport http --port 8080
Both transports:
python mcp_server.py --transport both --port 8080
6. Verify it is running
# Health check
curl http://localhost:8080/health # if using HTTP transport
# Or test via STDIO by running:
echo '{"jsonrpc":"2.0","method":"initialize","params":{},"id":1}' | python mcp_server.py
Docker Deployment
Using Docker directly
docker build -t buywhere-mcp .
docker run -d \
--name buywhere-mcp \
-p 8080:8080 \
-e BUYWHERE_API_KEY="your_api_key_here" \
-e BUYWHERE_API_URL="https://api.buywhere.ai" \
-e BUYWHERE_MCP_HTTP_PORT=8080 \
buywhere-mcp
Using Docker Compose
Create a docker-compose.mcp.yml:
version: '3.8'
services:
buywhere-mcp:
build: .
container_name: buywhere-mcp
ports:
- "8080:8080"
environment:
- BUYWHERE_API_KEY=${BUYWHERE_API_KEY}
- BUYWHERE_API_URL=${BUYWHERE_API_URL:-https://api.buywhere.ai}
- BUYWHERE_MCP_HTTP_PORT=8080
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 10s
retries: 3
Run:
docker compose -f docker-compose.mcp.yml up -d
Production Docker considerations
- Store
BUYWHERE_API_KEYin a secrets manager, not in plaintext - Use a reverse proxy (nginx) for TLS termination if exposing HTTP transport publicly
- Set resource limits:
--memory="512m" --cpus="1" - Use
--env-fileto load environment variables from a file excluded from version control
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
BUYWHERE_API_KEY | Yes | — | Your BuyWhere API key |
BUYWHERE_API_URL | No | http://localhost:8000 | BuyWhere API base URL |
BUYWHERE_MCP_HTTP_PORT | No | 8080 | HTTP/SSE server port |
Getting an API key
- Sign up at https://buywhere.ai/api
- Navigate to Dashboard > API Keys
- Create a new key with appropriate scopes
- Copy the key — it will not be shown again
Security best practices
- Never commit API keys to version control
- Use a secrets manager (AWS Secrets Manager, HashiCorp Vault, etc.) in production
- Rotate keys periodically
- Use environment-specific keys (dev/staging/prod)
Troubleshooting
"Connection refused" errors
- Verify the MCP server is running:
curl http://localhost:8080/health - Check the API URL is correct (must include
https://api.buywhere.ai) - Ensure your firewall allows the port
"Permission denied" or 401 errors
- Confirm your API key is valid and active
- Check if you've exceeded your rate limit
- Verify the API key has the required scopes
MCP server not appearing in Claude Desktop
- Use absolute paths to
mcp_server.py, not relative paths - Restart Claude Desktop completely after config changes
- Check Claude's developer console for error messages:
- macOS:
~/Library/Logs/Claude/ - Linux:
~/.config/Claude/logs/ - Windows:
%APPDATA%\Claude\logs\
- macOS:
Python import errors
Ensure all dependencies are installed:
pip install -r requirements.txt
If using a virtual environment, make sure it is activated.
Docker container exits immediately
Check logs:
docker logs buywhere-mcp
Common issues:
- Missing
BUYWHERE_API_KEYenvironment variable - Port already in use — try a different port
- Invalid API URL format (must include
http://orhttps://)
High memory usage
- Limit Docker container memory:
--memory=512m - Reduce the number of concurrent connections
- Use HTTP transport instead of STDIO for long-running deployments
Testing with Claude Desktop
1. Configure Claude Desktop
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Add the BuyWhere MCP server:
{
"mcpServers": {
"buywhere": {
"command": "python",
"args": [
"/absolute/path/to/buywhere-api/mcp_server.py"
],
"env": {
"BUYWHERE_API_KEY": "your_api_key_here",
"BUYWHERE_API_URL": "https://api.buywhere.ai"
}
}
}
}
2. Restart Claude Desktop
Close completely and reopen.
3. Verify the connection
Ask Claude:
Search for "iphone 15 pro" on BuyWhere
You should see product results from Singapore e-commerce platforms.
4. Check available tools
Ask Claude:
What tools do you have available from BuyWhere?
Claude should list: search_products, get_product, compare_products, get_deals, list_categories.
Quick Reference
# One-liner local test
BUYWHERE_API_KEY=your_key python mcp_server.py --transport http --port 8080
# Docker deployment
docker run -d -p 8080:8080 -e BUYWHERE_API_KEY=your_key buywhere-mcp
# Check logs
docker logs -f buywhere-mcp
# Stop
docker stop buywhere-mcp
Support
- API documentation: https://api.buywhere.ai/docs
- MCP server source:
/home/paperclip/buywhere-api/mcp_server.py - Issues: https://github.com/buywhere/buywhere-api/issues