Skip to content
reaatechREAATECH

@reaatech/llm-router-mcp

npm v1.0.0

Exposes an LLM router as a Model Context Protocol (MCP) server, providing tools to route requests, query model metadata, and retrieve cost reports. It provides a factory function to create the server instance and requires an implementation of a `RouterInterface` to handle the underlying routing logic.

@reaatech/llm-router-mcp

npm version License: MIT CI

Status: Pre-1.0 — APIs may change in minor versions. Pin to a specific version in production.

MCP server integration for llm-router. Exposes three MCP tools — route_request, get_model_info, and get_cost_report — enabling AI agents and orchestration frameworks to route LLM requests through the router via the Model Context Protocol.

Installation

terminal
npm install @reaatech/llm-router-mcp @modelcontextprotocol/sdk
# or
pnpm add @reaatech/llm-router-mcp @modelcontextprotocol/sdk

Feature Overview

  • Three MCP tools — route LLM requests, query model metadata, and generate cost reports
  • Dual transports — stdio for desktop clients (Claude Desktop, VS Code) and Streamable HTTP for remote agents
  • Pluggable router interfaceRouterInterface decouples the server from the router implementation
  • Zero additional MCP tooling — all tool schemas and handlers are self-contained
  • Auto-startserver.start() detects the transport environment and activates the right transport

Quick Start

typescript
import { createMCPServer } from "@reaatech/llm-router-mcp";
import type { RouterInterface } from "@reaatech/llm-router-mcp";
 
// Implement the router interface
const router: RouterInterface = {
  async route(request) {
    const result = await myLLMRouter.route(request);
    return {
      model: result.model,
      strategy: result.strategy,
      cost: result.cost,
      confidence: result.confidence,
      latencyMs: result.latencyMs,
      result: result.result,
    };
  },
  getModels() {
    return myLLMRouter.getModels();
  },
  getBudget(budgetId) {
    return myLLMRouter.getBudget(budgetId);
  },
};
 
// Create and start the MCP server
const server = createMCPServer({ name: "llm-router", version: "1.0.0" });
server.setRouter(router);
await server.start();

Claude Desktop Configuration

json
{
  "mcpServers": {
    "llm-router": {
      "command": "npx",
      "args": ["@reaatech/llm-router-mcp"]
    }
  }
}

API Reference

createMCPServer(config?): MCPServer

Factory function for creating an MCP server instance.

MCPServerConfig

FieldTypeDefaultDescription
namestringllm-routerServer name reported to MCP clients
versionstring1.0.0Server version
descriptionstringOptional human-readable description

MCPServer (class)

Methods

MethodReturnsDescription
setRouter(router)voidAttach the router implementation that tools delegate to
start()Promise<void>Starts the server, auto-detecting stdio vs HTTP transport
stop()Promise<void>Gracefully shuts down the server
getTools()Tool[]Returns the registered MCP tool schemas

RouterInterface

Your router must implement this contract for the MCP tools to function:

typescript
interface RouterInterface {
  route(request: RoutingRequest): Promise<RouterRouteSummary>;
  getModels(): ModelDefinition[];
  getBudget(budgetId?: string): BudgetInfo | null;
}
MethodDescription
route(request)Route a single LLM request through the router
getModels()Return all registered model definitions
getBudget(budgetId?)Return a budget’s current state (daily limit, remaining, spent today)

MCP Tools

route_request

Routes a prompt through the LLM router and returns the routing decision, selected model, execution result, cost, and latency.

Input parameters:

ParameterTypeRequiredDescription
promptstringYesThe text to route through an LLM
strategystringNoStrategy to use (cost-optimized, latency-optimized, judgment-based, capability-based)
maxTokensnumberNoMaximum output tokens
requiredCapabilitiesstring[]NoRequired model capabilities (code, reasoning, etc.)
budgetIdstringNoBudget to count this request against
confidenceThresholdnumberNoMinimum confidence for strategy acceptance

get_model_info

Returns detailed information about a specific model: capabilities, pricing, max tokens, and provider.

Input parameters:

ParameterTypeRequiredDescription
modelIdstringYesThe model ID to look up

get_cost_report

Generates a cost report for a budget within a time period.

Input parameters:

ParameterTypeRequiredDescription
budgetIdstringYesBudget to report on
periodstringNoTime period: today, week, or month (default: today)

Transport Selection

The server auto-detects its transport at startup:

ConditionTransportClient Examples
stdin is not a TTYStdioServerTransportClaude Desktop, VS Code Copilot
PORT env var is setStreamableHTTPServerTransportRemote agents, web-based MCP clients
NeitherStdioServerTransport (default)

Integration with the Engine

typescript
import { LLMRouter, loadRouterConfig } from "@reaatech/llm-router-engine";
import { createMCPServer } from "@reaatech/llm-router-mcp";
 
const router = LLMRouter.fromConfig(loadRouterConfig("llm-router.config.yaml"));
 
const server = createMCPServer({ name: "llm-router", version: "1.0.0" });
 
server.setRouter({
  async route(request) {
    const result = await router.route(request);
    return { model: result.model, strategy: result.strategy, cost: result.cost, confidence: result.confidence, latencyMs: result.latencyMs, result: result.result };
  },
  getModels: () => router.getModels(),
  getBudget: (id) => router.getBudget(id),
});
 
await server.start();

License

MIT