mcp server
A unified API server that enables interaction with multiple AI model providers like Anthropic and OpenAI through a consistent interface, supporting chat completions, tool calling, and context handling.
A unified API server that enables interaction with multiple AI model providers like Anthropic and OpenAI through a consistent interface, supporting chat completions, tool calling, and context handling.
A simple server implementation for the Model Context Protocol that provides a unified API for multiple AI model providers.
# Clone the repository
git clone <repository-url>
cd testmcp
# Install dependencies
npm install
# Run the interactive setup
npm run setup
The setup script will guide you through configuring the necessary API keys:
ANTHROPIC_API_KEY
- For Claude modelsOPENAI_API_KEY
- For GPT models and DALL-E image generationSTABILITY_API_KEY
- For Stable Diffusion image generationGOOGLE_CSE_API_KEY
and GOOGLE_CSE_ID
- For web search functionalityBING_SEARCH_API_KEY
- For fallback web searchYou can also manually edit the .env
file if you prefer.
The MCP server uses MongoDB for data persistence. You have several options for setting up MongoDB:
Run the MongoDB setup script, which will guide you through the process:
# Run the MongoDB setup script
npm run setup-mongodb
This script will: 1. Check if Docker is available 2. Start MongoDB using Docker Compose (if available) 3. Configure the connection in your .env file 4. Verify the MongoDB connection
The easiest way to get started with MongoDB is to use the included Docker Compose configuration:
# Start MongoDB and Mongo Express in Docker
docker compose up -d
# Update your .env file with the connection string
echo "MONGODB_URI=mongodb://mcpuser:mcppassword@localhost:27017/mcp-server" >> .env
MongoDB will be available at mongodb://mcpuser:mcppassword@localhost:27017/mcp-server
Mongo Express (web admin) will be available at http://localhost:8081
If you prefer to install MongoDB locally:
.env
file with:
MONGODB_URI=mongodb://localhost:27017/mcp-server
For production use, MongoDB Atlas is recommended:
.env
file:
MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/mcp-server?retryWrites=true&w=majority
To migrate existing data to MongoDB:
# Run the migration script
npm run migrate-mongodb
This script will: 1. Migrate tool definitions to MongoDB 2. Migrate configurations (like API keys) to MongoDB 3. Import any backup data if available
# Interactive startup (checks for API keys)
npm start
# Development mode with auto-reload
npm run dev
# Quick start (skips environment checks)
npm run quick-start
# Start server with PM2 process manager
npm run pm2:start
# Start server with PM2 in production mode
npm run pm2:start:prod
The server will be running at http://localhost:3000 (or the port you specified in .env).
npm start
):Recommended for first-time users
Development Mode (npm run dev
):
Best for development
Quick Start (npm run quick-start
):
Useful when you know your configuration is correct
PM2 Production Mode (npm run pm2:start:prod
):
The server can be run with PM2, a production process manager for Node.js applications. PM2 provides features like:
# Start the server with PM2
npm run pm2:start
# Start in production mode
npm run pm2:start:prod
# View logs
npm run pm2:logs
# Monitor performance
npm run pm2:monit
# Restart the server
npm run pm2:restart
# Stop the server
npm run pm2:stop
# Remove the server from PM2
npm run pm2:delete
The PM2 configuration is stored in ecosystem.config.js
. You can modify this file to change:
- Process name
- Environment variables
- Memory limits
- Deployment configuration
- Number of instances (for load balancing)
POST /mcp/:provider
Make requests to AI models through a unified API.
URL Parameters:
- provider
: The AI provider to use (anthropic
or openai
)
Request Body:
{
"messages": [
{ "role": "user", "content": "Your prompt here" }
],
"model": "claude-3-opus-20240229", // Optional, provider-specific model name
"tools": [...], // Optional, tools for function calling
"context": "System message or context" // Optional
}
OR (Legacy format):
{
"prompt": "Your prompt here",
"model": "claude-3-opus-20240229", // Optional
"context": "System message or context" // Optional
}
Response: Returns the raw response from the provider s API.
GET /tools/available
Get a comprehensive list of all available tools with detailed information.
Query Parameters:
- format
- Response format: json
(default), yaml
, table
, or html
- category
- Filter tools by category (optional)
- enabled
- Filter by enabled status: true
(default) or false
- search
- Search for tools by name, description, or tags
- provider
- Filter tools by provider (e.g., openai
, google
)
- limit
- Maximum number of tools to return (for pagination)
- offset
- Offset for pagination (default: 0)
Response (JSON format):
{
"success": true,
"count": 10,
"metadata": {
"categories": ["web", "image", "utility"],
"providers": ["openai", "anthropic", "internal"],
"totalCount": 24,
"offset": 0,
"limit": 10
},
"tools": [
{
"name": "web_search",
"description": "Search the web for information",
"category": "web",
"version": "1.0.0",
"provider": "google",
"enabled": true,
"parameters": {
"query": {
"type": "string",
"description": "The search query",
"required": true
},
"limit": {
"type": "number",
"description": "Maximum number of results",
"required": false,
"default": 5
}
},
"usage": {
"endpoint": "/tools/web/search",
"method": "POST",
"parameters": { /* same as above */ }
},
"metadata": {
"createdAt": "2023-10-15T12:00:00Z",
"updatedAt": "2024-04-20T09:30:00Z",
"usageCount": 1245
}
}
// ... more tools
]
}
GET /health
Health check endpoint that returns status 200 if the server is running.
You can create and manage database backups:
# Create a full backup
npm run backup-mongodb
# Create a backup with execution history
npm run backup-mongodb -- --with-executions
# List existing backups
npm run backup-mongodb -- --list
To verify your MongoDB setup:
# Run the database test script
npm run test-mongodb
A test client is included in src/client.js
. To run it:
node src/client.js
A simple web interface is available at http://localhost:3000 when the server is running. You can use this to test the API directly from your browser.
The MCP server provides a tools discovery endpoint that allows users and AI agents to programmatically list all available tools:
GET /tools/available
- Lists all available tools with detailed information.
Example usage:
# Get all tools in JSON format
curl http://localhost:3000/tools/available
# Get tools in a specific category
curl http://localhost:3000/tools/available?category=web
# Search for image-related tools
curl http://localhost:3000/tools/available?search=image
# Get a formatted HTML page of all tools
curl http://localhost:3000/tools/available?format=html > tools.html
The server includes built-in web search and retrieval tools:
/tools/web/search
)query
(required), limit
(optional)GOOGLE_CSE_API_KEY
and GOOGLE_CSE_ID
environment variablesFalls back to BING_SEARCH_API_KEY
if Google search fails
Web Content (/tools/web/content
)
Parameters: url
(required), useCache
(optional)
Web Batch (/tools/web/batch
)
urls
(required array), useCache
(optional)The server also includes image generation, editing, and variation tools:
/tools/image/generate
)Parameters:
prompt
(required): Detailed description of the imageprovider
(optional): openai
or stability
(defaults to openai
)options
(optional): Provider-specific optionsEdit Image (/tools/image/edit
)
Parameters:
imagePath
(required): Path to the image to editprompt
(required): Description of the edit to makemaskPath
(optional): Path to a mask imageCreate Image Variation (/tools/image/variation
)
imagePath
(required): Path to the image to create variations ofNote: To use these tools, you need to set API keys in your
.env
file: - For OpenAI images:OPENAI_API_KEY
- For Stability AI images:STABILITY_API_KEY
- For Web Search:GOOGLE_CSE_API_KEY
andGOOGLE_CSE_ID
The MCP server automatically handles tool calling and execution with AI models. When a model decides to use a tool, the server:
AI models can use the /tools/available
endpoint to discover what tools are available and how to use them. This is particularly useful for:
Example system prompt for AI models:
You have access to external tools through the MCP server.
Before using any tools, you should check what tools are available by calling:
GET /tools/available
This will return a list of all available tools with their parameters and usage instructions.
You can then use these tools by following the provided usage patterns.
See the /examples
directory for sample code demonstrating tool usage.
To add new AI providers:
server.js
To add new tools to the server:
/src/tools
directorytool-definitions.js
server.js
ISC