Installation
pip install uniplex-mcp-sdk
Quick Start
Protect your MCP tools with Uniplex in under 5 minutes:
from uniplex_mcp import UniplexMCPServer, define_tool
# Define your tool
search_flights = (
define_tool()
.name('search_flights')
.permission('flights:search')
.schema({
'type': 'object',
'properties': {
'origin': {'type': 'string'},
'destination': {'type': 'string'},
'date': {'type': 'string', 'format': 'date'}
},
'required': ['origin', 'destination', 'date']
})
.handler(search_flights_handler)
.build()
)
async def search_flights_handler(input):
# Your API call here
return {'flights': []}
# Create and run server
server = UniplexMCPServer(
gate_id='gate_acme-travel',
tools=[search_flights],
test_mode=True # Use mock data for development
)
server.start()
Configuration
Environment Variables
| Variable | Required | Description |
|---|
UNIPLEX_GATE_ID | Yes | Your gate identifier |
UNIPLEX_API_URL | No | API URL (default: https://api.uniplex.ai) |
Server Options
server = UniplexMCPServer(
gate_id='gate_acme-travel',
tools=[search_flights, book_flight],
# Cache settings
catalog_max_age_minutes=5,
revocation_max_age_minutes=1,
# Commerce (optional)
commerce_enabled=True,
issue_receipts=True, # Auto-issue consumption attestations
# Development
test_mode=True
)
get_ticker = (
define_tool()
.name('get_ticker')
.permission('market:read')
.schema({
'type': 'object',
'properties': {
'symbol': {'type': 'string'}
},
'required': ['symbol']
})
.handler(get_ticker_handler)
.build()
)
async def get_ticker_handler(input):
return {'price': 150.25, 'symbol': input['symbol']}
Enforce cost limits, rate limits, or custom constraints:
book_flight = (
define_tool()
.name('book_flight')
.permission('flights:book')
.risk_level('high')
.constraint({
'key': 'core:cost:max',
'source': 'input',
'input_path': '$.price',
'transform': 'dollars_to_cents'
})
.schema({
'type': 'object',
'properties': {
'flight_id': {'type': 'string'},
'price': {'type': 'string'} # Use string for financial values
},
'required': ['flight_id', 'price']
})
.handler(book_flight_handler)
.build()
)
async def book_flight_handler(input):
return {'confirmation': 'ABC123'}
Always use strings for financial values (prices, amounts) to avoid floating-point precision issues. The SDK converts them to canonical integers automatically.
Claude Desktop Integration
Add to your Claude Desktop config:
// ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"travel": {
"command": "uniplex-mcp-sdk",
"args": ["--gate-id", "gate_acme-travel"],
"env": {
"UNIPLEX_GATE_ID": "gate_acme-travel"
}
}
}
}
API Reference
Fluent builder for tool definitions:
(
define_tool()
.name(str) # Tool name
.permission(str) # Permission key (e.g., 'flights:book')
.risk_level('low'|'medium'|'high'|'critical')
.schema(dict) # Input schema (JSON Schema)
.constraint(dict) # Add constraint
.handler(async_func) # Tool implementation
.build() # Returns ToolDefinition
)
UniplexMCPServer
server = UniplexMCPServer(config)
server.start() # Start stdio transport
server.register_tool(tool) # Add tool at runtime
Convert financial values to integers:
from uniplex_mcp import transform_to_canonical, dollars_to_cents
transform_to_canonical('4.99', 2) # → 499
transform_to_canonical('1.005', 2, 'round') # → 101
dollars_to_cents('19.99') # → 1999
Calculate platform fees with ceiling rounding:
from uniplex_mcp import compute_platform_fee
compute_platform_fee(1000, 200) # 2% of $10 = 20 cents
compute_platform_fee(101, 200) # 2% of $1.01 = 3 cents (ceiling)
Resources