Skip to main content

Installation

npm install uniplex-mcp-sdk

Quick Start

Protect your MCP tools with Uniplex in under 5 minutes:
import { UniplexMCPServer, defineTool } from 'uniplex-mcp-sdk';

// Define your tool
const searchFlights = defineTool()
  .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(async (input) => {
    // Your API call here
    return { flights: [] };
  })
  .build();

// Create and run server
const server = new UniplexMCPServer({
  gate_id: 'gate_acme-travel',
  tools: [searchFlights],
  test_mode: true  // Use mock data for development
});

server.start();

Configuration

Environment Variables

VariableRequiredDescription
UNIPLEX_GATE_IDYesYour gate identifier
UNIPLEX_API_URLNoAPI URL (default: https://api.uniplex.ai)

Server Options

const server = new UniplexMCPServer({
  gate_id: 'gate_acme-travel',
  tools: [searchFlights, bookFlight],
  
  // Cache settings
  cache: {
    catalog_ttl_ms: 300000,     // 5 minutes
    revocation_ttl_ms: 60000    // 1 minute
  },
  
  // Commerce (optional)
  commerce: {
    enabled: true,
    issue_receipts: true  // Auto-issue consumption attestations
  },
  
  // Development
  test_mode: true
});

Defining Tools

Basic Tool

const getTicker = defineTool()
  .name('get_ticker')
  .permission('market:read')
  .schema({
    type: 'object',
    properties: {
      symbol: { type: 'string' }
    },
    required: ['symbol']
  })
  .handler(async ({ symbol }) => {
    return { price: 150.25, symbol };
  })
  .build();

Tool with Constraints

Enforce cost limits, rate limits, or custom constraints:
const bookFlight = defineTool()
  .name('book_flight')
  .permission('flights:book')
  .riskLevel('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(async (input) => {
    return { confirmation: 'ABC123' };
  })
  .build();
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": "node",
      "args": ["./dist/server.js"],
      "env": {
        "UNIPLEX_GATE_ID": "gate_acme-travel"
      }
    }
  }
}

API Reference

defineTool()

Fluent builder for tool definitions:
defineTool()
  .name(string)                    // Tool name
  .permission(string)              // Permission key (e.g., 'flights:book')
  .riskLevel('low'|'medium'|'high'|'critical')
  .schema(JSONSchema)              // Input schema
  .constraint(ConstraintConfig)    // Add constraint
  .handler(async (input) => {})    // Tool implementation
  .build()                         // Returns ToolDefinition

UniplexMCPServer

const server = new UniplexMCPServer(config);

server.start()                     // Start stdio transport
server.registerTool(tool)          // Add tool at runtime

transformToCanonical()

Convert financial values to integers:
import { transformToCanonical, dollarsToCents } from 'uniplex-mcp-sdk';

transformToCanonical('4.99', 2)           // → 499
transformToCanonical('1.005', 2, 'round') // → 101
dollarsToCents('19.99')                   // → 1999

computePlatformFee()

Calculate platform fees with ceiling rounding:
import { computePlatformFee } from 'uniplex-mcp-sdk';

computePlatformFee(1000, 200)  // 2% of $10 = 20 cents
computePlatformFee(101, 200)   // 2% of $1.01 = 3 cents (ceiling)

Resources