samwang0723/mcp-searchapi
If you are the rightful owner of mcp-searchapi and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The MCP SearchAPI Server is a Model Context Protocol server that enables AI assistants to perform Google Shopping searches using SearchAPI.io, providing a standardized interface for product search and price comparison.
MCP SearchAPI Server
An MCP (Model Context Protocol) server that provides Google Shopping search capabilities using SearchAPI.io. This server allows AI assistants to search for products, compare prices, and retrieve shopping information through a standardized interface.
๐ Features
- Google Shopping Search: Search for products with comprehensive filtering options
- TypeScript: Full type safety with modern TypeScript patterns
- HTTP Transport: RESTful API with Express.js server
- Session Management: Stateful connections with proper session handling
- Configuration Management: Environment-based configuration with validation
- Error Handling: Comprehensive error handling and logging
- Health Checks: Built-in health monitoring endpoints
- Docker Support: Production-ready containerization
- Production Ready: Optimized for scalability and security
๐ Prerequisites
- Node.js 20+
- npm or yarn
- SearchAPI.io API key
- Docker (optional, for containerization)
๐ ๏ธ Quick Start
1. Installation
# Clone the repository
git clone https://github.com/your-username/mcp-searchapi.git
cd mcp-searchapi
# Install dependencies
npm install
2. Environment Configuration
Create a .env
file in the root directory:
# SearchAPI Configuration (Required)
SEARCHAPI_API_KEY=your_searchapi_key_here
# Server Configuration
PORT=3000
LOG_LEVEL=info
3. Get SearchAPI.io API Key
- Visit SearchAPI.io
- Sign up for an account
- Get your API key from the dashboard
- Add it to your
.env
file
4. Development
# Start development server with hot reload
npm run dev
# Build for production
npm run build
# Start production server
npm start
# Run tests
npm test
# Lint and format code
npm run lint
npm run lint:fix
๐๏ธ Project Structure
mcp-searchapi/
โโโ src/
โ โโโ config/ # Configuration management
โ โ โโโ index.ts # Main config file
โ โโโ services/ # Service layer
โ โ โโโ searchapi.ts # SearchAPI.io service
โ โโโ utils/ # Utility functions
โ โ โโโ logger.ts # Logging utilities
โ โโโ index.ts # Main server application
โโโ Dockerfile # Docker configuration
โโโ package.json # Dependencies and scripts
โโโ tsconfig.json # TypeScript configuration
โโโ README.md # This file
๐ง Available Tools
Google Shopping Search
Search for products on Google Shopping with advanced filtering options.
Tool Name: google-shopping-search
Parameters:
query
(required): Search query for products (e.g., "iPhone 15", "running shoes")location
(optional): Location for search results (e.g., "United States", "New York")country
(optional): Country code for search results (e.g., "us", "uk", "ca")language
(optional): Language code for search results (e.g., "en", "es", "fr")maxResults
(optional): Maximum number of results to return (default: 10)includeMetadata
(optional): Include search metadata in response (default: false)
Example Usage:
{
"tool": "google-shopping-search",
"arguments": {
"query": "wireless headphones",
"location": "United States",
"country": "us",
"language": "en",
"maxResults": 5
}
}
๐ง Architecture
Core Components
- McpServerApp: Main application class that orchestrates the MCP server
- SearchApiService: Service for interacting with SearchAPI.io
- Configuration: Environment-based configuration with type safety
- Session Management: HTTP-based stateful sessions with cleanup
- Transport Layer: StreamableHTTPServerTransport for MCP communication
- Error Handling: Comprehensive error handling with proper HTTP responses
HTTP Endpoints
GET /health
- Health check endpointPOST /mcp
- Main MCP communication endpointGET /mcp
- Server-to-client notifications via SSEDELETE /mcp
- Session termination
๐ ๏ธ Configuration
Environment Variables
Variable | Description | Default | Required |
---|---|---|---|
SEARCHAPI_API_KEY | Your SearchAPI.io API key | - | Yes |
PORT | Server port | 3000 | No |
LOG_LEVEL | Logging level (debug, info, warn, error) | info | No |
SearchAPI.io Configuration
The server supports all SearchAPI.io Google Shopping parameters:
- Location-based filtering: Target specific geographical regions
- Language preferences: Return results in preferred languages
- Result limiting: Control the number of results returned
- Metadata inclusion: Get additional search metadata
๐ณ Docker Deployment
Build and Run
# Build Docker image
docker build -t mcp-searchapi-server .
# Run container
docker run -p 3000:3000 -e SEARCHAPI_API_KEY=your_key_here mcp-searchapi-server
Docker Compose
Create a docker-compose.yml
:
version: '3.8'
services:
mcp-searchapi:
build: .
ports:
- '3000:3000'
environment:
- SEARCHAPI_API_KEY=${SEARCHAPI_API_KEY}
- NODE_ENV=production
- PORT=3000
- LOG_LEVEL=info
restart: unless-stopped
healthcheck:
test: ['CMD', 'curl', '-f', 'http://localhost:3000/health']
interval: 30s
timeout: 10s
retries: 3
Run with:
# Set your API key in .env file or environment
docker-compose up -d
๐ MCP Client Integration
Using with Claude Desktop
Add to your Claude Desktop configuration:
{
"mcpServers": {
"mcp-searchapi": {
"name": "mcp-searchapi",
"type": "streamable-http",
"streamable": true,
"url": "http://localhost:3000/mcp"
}
}
}
Using with Custom MCP Clients
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
const client = new Client({
name: 'searchapi-client',
version: '1.0.0',
});
// Connect to the server
await client.connect(transport);
// Use the Google Shopping search tool
const result = await client.callTool('google-shopping-search', {
query: 'laptop',
maxResults: 5,
});
๐ Security Best Practices
- API Key Security: Store your SearchAPI.io API key securely
- Input Validation: All parameters are validated using Zod schemas
- Error Handling: Safe error responses without information leakage
- Session Management: Proper session cleanup and validation
- Rate Limiting: Consider implementing rate limiting for production use
๐ Monitoring and Logging
The server includes comprehensive logging for:
- Search requests and responses
- Error tracking and debugging
- Session management events
- Health check status
Logs are structured JSON format suitable for production monitoring systems.
๐งช Testing
# Run all tests
npm test
# Run tests in watch mode
npm run test:watch
# Run tests with coverage
npm run test:coverage
# Test the health endpoint
curl http://localhost:3000/health
๐ Production Deployment
Environment Variables
NODE_ENV=production
SEARCHAPI_API_KEY=your_production_api_key
PORT=3000
LOG_LEVEL=warn
Performance Considerations
- Monitor API rate limits from SearchAPI.io
- Implement caching for frequently searched queries
- Set up proper log rotation
- Monitor memory usage and implement limits
๐ API Documentation
SearchAPI.io Integration
This server integrates with SearchAPI.io Google Shopping API. For detailed API documentation and pricing information, visit their documentation.
MCP Protocol
This server implements the Model Context Protocol specification for standardized AI assistant integration.
๐ค Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
For questions and support:
- Check the MCP Documentation
- Review SearchAPI.io Documentation
- Create an issue with detailed information
Start searching for products with AI! ๐๏ธ