🚀 Transform any REST API into a Model Context Protocol (MCP) server in minutes, not hours
ContextLayer bridges the gap between traditional REST APIs and AI assistants, enabling seamless integration with Claude, VS Code Copilot, and other MCP-compatible tools without requiring any code modifications to your existing APIs.
- REST API to MCP Bridge: Convert existing REST APIs into MCP servers without code modifications
- Visual Configuration Interface: Web-based management dashboard for API configuration
- Instant Deployment: Start and stop MCP servers with one-click operations
- Real-time Monitoring: Track server status, uptime, and performance metrics
- Multiple Authentication Methods: Support for Bearer tokens, API keys, Basic authentication, and OAuth
- OpenAPI Integration: Import API configurations directly from OpenAPI/Swagger specifications
- Modern Web Interface: Built with Next.js, TypeScript, and shadcn/ui components
- Persistent Data Storage: PostgreSQL database for configuration management
- Container Ready: Full Docker support for streamlined deployment
The Model Context Protocol enables AI assistants to securely connect to external data sources and tools. ContextLayer serves as a bridge between traditional REST APIs and MCP, allowing any existing API to become accessible to AI assistants without requiring modifications to the original API implementation.
# Clone the repository
git clone https://github.com/Joel-hanson/contextlayer.git
cd contextlayer
# Start with Docker Compose
docker-compose up -d
# Open http://localhost:3000# Prerequisites: Node.js 18+, PostgreSQL
# 1. Install dependencies
npm install
# 2. Set up environment
cp .env.example .env.local
# Edit .env.local with your database URL and other settings
# 3. Set up database
npm run db:migrate
npm run db:seed
# 4. Start development server
npm run dev- Node.js 18+ - Download here
- PostgreSQL - Installation guide
- npm or yarn - Package manager
- Git - Version control
-
Clone the repository:
git clone https://github.com/Joel-hanson/contextlayer.git cd contextlayer -
Install dependencies:
npm install
-
Environment configuration:
cp .env.example .env.local
Edit
.env.localwith your settings:# Database DATABASE_URL="postgresql://user:password@localhost:5432/contextlayer" # Authentication NEXTAUTH_SECRET="your-secret-key" NEXTAUTH_URL="http://localhost:3000" # OAuth (optional) GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret"
-
Database setup:
# Run migrations npm run db:migrate # Seed with sample data npm run db:seed
-
Start the application:
npm run dev
Visit http://localhost:3000
- Sign in to the ContextLayer dashboard
- Navigate to "Bridges" and click "Create Bridge"
- Configure your API:
- Basic Info: Name, description, and base URL
- Authentication: Choose auth method and provide credentials
- Endpoints: Define the API endpoints you want to expose
# Upload your OpenAPI/Swagger spec file
# ContextLayer will automatically configure endpoints and authentication- Toggle the bridge to "Running" state
- Copy the MCP server URL
- Configure your AI assistant to use the MCP server
// Add to your Claude config
{
"mcpServers": {
"my-api": {
"command": "node",
"args": ["/path/to/contextlayer/mcp-server.js"],
"env": {
"BRIDGE_URL": "http://localhost:3000/mcp/your-bridge-id"
}
}
}
}// Use the MCP extension for VS Code
// Configure with your bridge URLinterface BridgeConfig {
name: string;
description: string;
baseUrl: string;
authentication: {
type: "none" | "bearer" | "apikey" | "basic" | "oauth";
// ... auth-specific fields
};
endpoints: Array<{
name: string;
method: "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
path: string;
description: string;
parameters?: Array<Parameter>;
requestBody?: RequestBodySchema;
}>;
rateLimiting?: {
enabled: boolean;
requestsPerMinute: number;
burstLimit: number;
};
}{
"type": "bearer",
"token": "your-bearer-token"
}{
"type": "apikey",
"key": "your-api-key",
"keyLocation": "header", // or "query"
"keyName": "X-API-Key"
}{
"type": "basic",
"username": "your-username",
"password": "your-password"
}{
"type": "oauth",
"clientId": "your-client-id",
"clientSecret": "your-client-secret",
"authUrl": "https://api.example.com/oauth/authorize",
"tokenUrl": "https://api.example.com/oauth/token"
}ContextLayer supports multiple authentication methods for both the application and the APIs you're bridging.
- Google OAuth (recommended)
- GitHub OAuth
- Email/Password (can be disabled)
- No Authentication
- Bearer Token
- API Key (header or query parameter)
- Basic Authentication
- OAuth 2.0 (coming soon)
// Create a bridge
POST /api/bridges
{
"name": "My API Bridge",
"baseUrl": "https://api.example.com",
// ... configuration
}
// Start/Stop bridge
POST /api/bridges/{id}/start
POST /api/bridges/{id}/stop
// Get bridge status
GET /api/bridges/{id}/status// MCP server endpoint
GET /mcp/{bridgeId}
// Tool execution
POST /mcp/{bridgeId}/tools/execute
{
"name": "get_user",
"arguments": {
"userId": "123"
}
}ContextLayer uses a modern, scalable architecture:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ AI Assistant │───▶│ ContextLayer │───▶│ REST API │
│ (Claude, etc) │ │ MCP Server │ │ (Any API) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
- Next.js Frontend: React-based UI for bridge management
- MCP Server: Protocol-compliant server for AI integration
- Bridge Engine: Handles API transformation and routing
- Authentication Layer: Manages auth for both app and APIs
- PostgreSQL Database: Stores configurations and metadata
# Production deployment
docker-compose -f docker-compose.prod.yml up -d# Set up Vercel
npm run vercel:setup
# Deploy
vercel --prod# Build the application
npm run build
# Start production server
npm start# Run all tests
npm test
# Run with UI
npm run test:ui
# Run specific test file
npm test -- bridges.test.tsWe welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- API Connectors: Pre-built configurations for popular APIs
- Testing: More comprehensive test coverage
- Documentation: Examples and guides
- UI/UX: Design improvements and accessibility
- Features: New authentication methods, monitoring tools
This project is licensed under the MIT License - see the LICENSE file for details.
- Model Context Protocol by Anthropic
- shadcn/ui for beautiful components
- Next.js for the fantastic framework
- All our amazing contributors
- Website: https://contextlayer.joelhanson.com
- Documentation: https://docs.contextlayer.joelhanson.com
- Twitter: @contextlayer
Star this repository if you find it helpful!