Bidirectional adapter for converting between MCP and Opal tools
Project description
MCP-Opal Adapter
A bidirectional adapter service that converts between MCP (Model Context Protocol) tools and Opal tools using the official Opal Tools SDK with automatic MCP discovery.
Key Features
- MCP Discovery: Automatically discovers tools from MCP servers
- Proper Opal Tools SDK Integration: Uses
ToolsServiceand@tooldecorator - Dynamic Schema Translation: JSON Schema to Pydantic model conversion
- JSON-RPC Proxy: Forwards MCP calls via JSON-RPC protocol
- Discovery Endpoint: Exposes
/discoveryfor tool listing - Just-in-Time Configuration: HTTP API for dynamic tool registration
Architecture
┌─────────────────────────────────────────────────────────────┐
│ HTTP Configuration API │
│ POST /configure (MCP endpoint only) │
└─────────────────────┬───────────────────────────────────────┘
│
┌─────────────────────▼───────────────────────────────────────┐
│ MCP-Opal Proxy Service │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ MCP Discovery │◄──►│ Opal Tools │ │
│ │ (tools/list) │ │ SDK │ │
│ └─────────────────┘ └─────────────────┘ │
│ ┌─────────────────┐ ┌─────────────────┐ │
│ │ Dynamic Tool │ │ Protocol │ │
│ │ Registry │ │ Translator │ │
│ └─────────────────┘ └─────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Quick Start
1. Build and Run
# Build the Docker image
docker build -t mcp-opal-adapter .
# Run with Docker Compose
docker-compose up -d
2. Configure MCP Tools via Discovery
# Configure tools by discovering them from an MCP server
curl -X POST http://localhost:8000/configure \
-H "Content-Type: application/json" \
-d '"http://your-mcp-server:3000"'
3. Discover Available Tools
# Get list of available Opal tools
curl http://localhost:8000/discovery
4. Call Tools
# Call a discovered tool
curl -X POST http://localhost:8000/tools/weather_lookup \
-H "Content-Type: application/json" \
-d '{"location": "New York", "units": "imperial"}'
API Reference
Configuration Endpoints
POST /configure
Configure MCP tools by discovering them from an MCP server.
Request Body:
"http://mcp-server:3000"
Response:
{
"status": "configured",
"tools": ["weather_lookup", "calculator"],
"total_discovered": 2,
"successfully_configured": 2
}
Opal Tools Endpoints
GET /discovery
Discover available Opal tools (auto-generated by Opal Tools SDK).
POST /tools/{tool_name}
Call a configured tool via Opal interface.
Request Body:
{
"param1": "value1",
"param2": 42
}
Management Endpoints
GET /health
Health check endpoint.
GET /status
Get adapter status and configuration.
DELETE /configure/{tool_name}
Remove a configured tool.
MCP Discovery Process
The adapter automatically:
- Discovers Tools: Calls
tools/liston the MCP server - Extracts Schemas: Gets tool names, descriptions, and input schemas
- Converts Schemas: Transforms JSON Schema to Pydantic models
- Creates Proxies: Generates proxy functions for each tool
- Registers Tools: Registers them with the Opal Tools SDK
MCP Protocol Support
The adapter supports the standard MCP protocol:
- tools/list: Discovers available tools
- tools/call: Executes tool calls via JSON-RPC
- server/health: Health checking (optional)
Development
Local Development
# Install uv if not already installed
pip install uv
# Install dependencies using uv
uv sync
# For development with testing tools
uv sync --extra dev
# Run development server
uvicorn main:app --reload --host 0.0.0.0 --port 8000
Testing
# Run tests using uv
uv run pytest
# Or install dev dependencies and run tests
uv sync --extra dev
pytest
Development Workflow
# Install all dependencies including dev tools
make build-dev
# Run tests
make test
# Run development server
make run
Deployment
Docker Compose
version: '3.8'
services:
mcp-opal-adapter:
build: .
ports:
- "8000:8000"
environment:
- ADAPTER_PORT=8000
- LOG_LEVEL=info
networks:
- adapter-network
Kubernetes
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcp-opal-adapter
spec:
replicas: 3
selector:
matchLabels:
app: mcp-opal-adapter
template:
metadata:
labels:
app: mcp-opal-adapter
spec:
containers:
- name: adapter
image: mcp-opal-adapter:latest
ports:
- containerPort: 8000
env:
- name: ADAPTER_PORT
value: "8000"
- name: LOG_LEVEL
value: "info"
Protocol Translation
MCP to Opal Flow
- Discover Tools: Call
tools/liston MCP server - Convert Schema: JSON Schema → Pydantic model using
create_model() - Create Proxy Function: Async function that forwards to MCP server
- Register with Opal SDK: Use
@tooldecorator to register - Handle Calls: Proxy function forwards JSON-RPC calls to MCP server
JSON-RPC Proxy
# MCP JSON-RPC request format
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "tool_name",
"arguments": {"param1": "value1"}
}
}
Key Implementation Details
Opal Tools SDK Integration
from opal_tools_sdk import ToolsService, tool
# Initialize with FastAPI app
app = FastAPI()
tools_service = ToolsService(app)
# Register dynamic tool
tool_decorator = tool("tool_name", "description")
registered_func = tool_decorator(proxy_function)
Dynamic Pydantic Model Creation
from pydantic import create_model
# Convert JSON Schema to Pydantic model
model_class = create_model(
"ToolParameters",
**field_definitions
)
MCP Discovery Function
async def discover_mcp_tools(mcp_endpoint: str):
# Call tools/list on MCP server
discovery_request = {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}
# Process response and extract tool information
Error Handling
Network Errors
- Connection timeouts (30s default)
- MCP server unavailability
- JSON-RPC protocol errors
Validation Errors
- Schema validation failures via Pydantic
- Required field missing
- Type conversion errors
Discovery Errors
- MCP server discovery failures
- Invalid tool schemas
- Duplicate tool names
Monitoring
Health Checks
- Service availability
- Tool count monitoring
- Configuration status
Logging
- Structured logging throughout
- Error tracking
- Performance monitoring
Security Considerations
Input Validation
- Schema-based validation via Pydantic
- Type checking and conversion
- Required field enforcement
Network Security
- Timeout configuration
- Error message sanitization
- Connection pooling
Future Enhancements
Planned Features
- Authentication and authorization
- Rate limiting
- Caching layer
- Metrics collection
- WebSocket support
- GraphQL interface
Scalability Improvements
- Database persistence
- Load balancing
- Service discovery
- Circuit breaker pattern
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
License
MIT License - see LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opal_mcp_adapter-0.0.1.tar.gz.
File metadata
- Download URL: opal_mcp_adapter-0.0.1.tar.gz
- Upload date:
- Size: 32.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f14a3c53dadaade0ebae4f8f9a92521848b8239fac65ca463f1a1cabac320fbf
|
|
| MD5 |
73af0a1893b42b4c7de979b0928fc05f
|
|
| BLAKE2b-256 |
e78757ef8fb6d187e67bd01684e1b425c43c8c609ae482cf6d520fe848e5fcd6
|
File details
Details for the file opal_mcp_adapter-0.0.1-py3-none-any.whl.
File metadata
- Download URL: opal_mcp_adapter-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94c6cb087ac35c68fea638ed3a0f10c0422f294b7e947dbc79be7677c5ccd357
|
|
| MD5 |
355396a3279037193ddda8007051b114
|
|
| BLAKE2b-256 |
9b63485ab610a7b314b98acabb85ed05a0be0c6f269b4ccd40c03e1501bb2f6c
|