← Guides

Run your own AI infrastructure

One endpoint for your MCP servers, one for your model servers, one for your agents — as separate pieces or as one ai-router — and the apps that sit on top.

On this page
  1. The stacks
  2. All in one: ai-router
  3. Piecemeal
    1. Tools: mcp-router
    2. Upgrading mcp-router from 2.x
    3. Models: llm-router
    4. Agents: agent-router
  4. Something to use it with
  5. Building your own

Once you have more than one model server and more than a couple of MCP servers, every client ends up with a copy of every address, key and model name — and they drift. The routers here each put one endpoint in front of a kind of thing, so the clients only know the router.

There are three things to route, and two ways to run them:

tools models agents
piecemeal mcp-router llm-router agent-router
all in one ai-router ai-router ai-router
  • ai-router is the whole combination: providers and pools, MCP servers, agents, workspaces and people, in one app with one UI and one sign-in. Pick it if you want agents and don't want to wire three services together.
  • Piecemeal is each concern as its own small service. Pick it if you only need one of them — say, one endpoint for every MCP client — or want to swap a piece out. mcp-router and llm-router each have their own UI; agent-router has none, and is driven over GraphQL.

The stacks #

One compose file for each way. Both also run min-agent, task-server and a shared Postgres. Paste one into a new stack, or download it: ai-router.yml or ai-piecemeal.yml.

Set these in the stack's environment; generate each secret with openssl rand -hex 32:

variable stack
PUBLIC_HOST all in one this machine's LAN address or hostname; ai-router builds its own URL from it
POSTGRES_PASSWORD both the shared Postgres
AI_ROUTER_AUTH_SECRET all in one ai-router's session secret
MCP_ROUTER_AUTH_SECRET piecemeal mcp-router's session secret, at least 32 characters
LLM_ROUTER_TOKEN piecemeal llm-router's token; agent-router uses it too, so set it rather than letting one generate
AGENT_ROUTER_ADMIN_TOKEN piecemeal admin on agent-router's /graphql
AGENT_ROUTER_SRC piecemeal path to a checkout of agent-router
service stack port
mcp-router piecemeal 3200
llm-router piecemeal 3201
ai-router all in one 3202
min-agent both 3203
task-server both 3204
agent-router piecemeal 3205

All in one: ai-router #

ai-router runs an agent's whole loop — prompt, models and MCP tools — behind an OpenAI-compatible /v1. An app names an agent as the model and gets back the answer; change an agent's model or tools in one place and every app that uses it follows.

  1. Open http://<PUBLIC_HOST>:3202 and set up sign-in. Pair it with heautou by pasting a setup URL, exactly like the personal-cloud apps, or set the AI_ROUTER_OIDC_* vars.
  2. Add your model servers as providers, and the MCP servers from Give your agents tools, each with its token, or an API key for mcp-skills-manager.
  3. Make an agent, a workspace, and a workspace key.
  4. Point apps at http://<PUBLIC_HOST>:3202/v1 with that key, and the agent's name as the model. The same agents are served as tools at /mcp.

Worker machines can dial in to run tools that have to live somewhere else. It is early, 0.x — expect it to move.

flowchart LR
    heautou["heautou<br/>personal cloud"]
    min["min-agent :3203"]
    task["task-server :3204"]
    air["ai-router :3202<br/>/v1 · /mcp · UI"]
    pg[("postgres")]
    mcpservers["MCP servers<br/>tools · mcp stack"]
    models[("model servers<br/>providers")]
    heautou -. "sign-in" .-> air
    min -- "/v1, agent as model" --> air
    task --> air
    air --> mcpservers
    air --> models
    air --> pg
    min --> pg
    task --> pg
ai-router.yml — show the compose file
# Cubic Echo — AI infrastructure, all in one
# ai-router (models, MCP servers and agents in one app), min-agent, task-server,
# and one shared Postgres. https://cubicecho.com/guides/ai-infrastructure/
#
# Set in the stack's environment (generate secrets with `openssl rand -hex 32`):
#   PUBLIC_HOST            this machine's LAN address or hostname
#   POSTGRES_PASSWORD
#   AI_ROUTER_AUTH_SECRET
# Optional: OPENAI_API_KEY for min-agent / task-server.
#
# Set an app's *_DATABASE_URL to use your own Postgres instead of the bundled one.
name: cubicecho-ai

services:
  ai-router:
    image: ghcr.io/cubicecho/ai-router:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: ${AI_ROUTER_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/ai_router}
      BETTER_AUTH_SECRET: ${AI_ROUTER_AUTH_SECRET:?set AI_ROUTER_AUTH_SECRET}
      APP_URL: ${AI_ROUTER_URL:-http://${PUBLIC_HOST:-localhost}:${AI_ROUTER_PORT:-3202}}
      OIDC_ISSUER: ${AI_ROUTER_OIDC_ISSUER:-}   # or pair with heautou from the sign-in page
      OIDC_CLIENT_ID: ${AI_ROUTER_OIDC_CLIENT_ID:-}
      OIDC_CLIENT_SECRET: ${AI_ROUTER_OIDC_CLIENT_SECRET:-}
      SECURE_LOCAL_NET: ${SECURE_LOCAL_NET:-false}
      TRUST_PROXY: ${TRUST_PROXY:-false}
    ports:
      - "${AI_ROUTER_PORT:-3202}:3000"
    volumes:
      - ai-router-data:/data

  min-agent:
    image: ghcr.io/cubicecho/min-agent:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: ${MIN_AGENT_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/min_agent}
      OPENAI_API_KEY: ${OPENAI_API_KEY:-}
      PORT: 8787
    ports:
      - "${MIN_AGENT_PORT:-3203}:8787"
    extra_hosts:
      - "host.docker.internal:host-gateway"

  task-server:
    image: ghcr.io/cubicecho/task_server:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: ${TASK_SERVER_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD}@postgres:5432/task_server}
      OPENAI_API_KEY: ${OPENAI_API_KEY:-}
      TZ: ${TZ:-UTC}
    ports:
      - "${TASK_SERVER_PORT:-3204}:8787"
    volumes:
      - task-server-data:/data

  # One Postgres for the apps that need one, one database each.
  postgres:
    image: postgres:17-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: cubicecho
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: cubicecho
    configs:
      - source: create-databases
        target: /docker-entrypoint-initdb.d/create-databases.sql
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U cubicecho -d cubicecho"]
      interval: 5s
      timeout: 5s
      retries: 10

# Runs once, when the Postgres volume is first created.
configs:
  create-databases:
    content: |
      CREATE DATABASE ai_router;
      CREATE DATABASE min_agent;
      CREATE DATABASE task_server;

volumes:
  ai-router-data:
  task-server-data:
  postgres-data:

Piecemeal #

Each concern is its own service. agent-router reaches models only through llm-router, which it knows as the provider llm.

flowchart LR
    mcpservers["MCP servers<br/>mcp stack, LAN discovery"]
    models[("model servers")]

    subgraph stack["ai-piecemeal stack"]
        mcpr["mcp-router :3200<br/>tools"]
        llmr["llm-router :3201<br/>models"]
        agr["agent-router :3205<br/>agents, /graphql"]
        min["min-agent :3203"]
        task["task-server :3204"]
        pg[("postgres")]
    end

    mcpr --> mcpservers
    llmr --> models
    agr -- "provider llm<br/>LLM_ROUTER_TOKEN" --> llmr
    min -- "/v1 models" --> llmr
    min -. "/v1 agents" .-> agr
    task --> llmr
    mcpr --> pg
    agr --> pg
    min --> pg
    task --> pg
ai-piecemeal.yml — show the compose file
# Cubic Echo — AI infrastructure, piecemeal
# mcp-router (tools), llm-router (models), agent-router (agents, no UI),
# min-agent, task-server, and one shared Postgres. agent-router calls its models
# through llm-router. https://cubicecho.com/guides/ai-infrastructure/
#
# Set in the stack's environment (generate secrets with `openssl rand -hex 32`):
#   POSTGRES_PASSWORD
#   MCP_ROUTER_AUTH_SECRET   signs mcp-router's UI sessions, 32+ characters
#   LLM_ROUTER_TOKEN         agent-router sends it to llm-router, so set it
#                            rather than letting llm-router generate one
#   AGENT_ROUTER_ADMIN_TOKEN admin on agent-router's /graphql
#   AGENT_ROUTER_SRC         path to a checkout of agent-router (no image yet)
# Optional: OPENAI_API_KEY, and for mcp-router:
#   MCP_ROUTER_SECURE_LOCAL_NET=true   whoever opens the UI is the admin, and /mcp
#                            needs no key. Only on a network you trust; otherwise
#                            sign-in is OIDC (see the guide).
#   MCP_ROUTER_TOKEN         a 2.x router's token, kept working as an API key
#
# Upgrading from mcp-router 2.x? It needs a database and a chown first:
# https://cubicecho.com/guides/ai-infrastructure/#upgrading-mcp-router-from-2-x
#
# Set an app's *_DATABASE_URL to use your own Postgres instead of the bundled one.
name: cubicecho-ai

services:
  mcp-router:
    image: vantreeseba/mcp-router:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: ${MCP_ROUTER_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/mcp_router}
      BETTER_AUTH_SECRET: ${MCP_ROUTER_AUTH_SECRET:?set MCP_ROUTER_AUTH_SECRET}
      SECURE_LOCAL_NET: ${MCP_ROUTER_SECURE_LOCAL_NET:-${SECURE_LOCAL_NET:-false}}
      OIDC_ISSUER: ${MCP_ROUTER_OIDC_ISSUER:-}   # or pair with heautou from the UI
      OIDC_CLIENT_ID: ${MCP_ROUTER_OIDC_CLIENT_ID:-}
      OIDC_CLIENT_SECRET: ${MCP_ROUTER_OIDC_CLIENT_SECRET:-}
      TRUST_PROXY: ${TRUST_PROXY:-false}
      MCP_ROUTER_TOKEN: ${MCP_ROUTER_TOKEN:-}   # upgrades only; imported as an API key
    ports:
      - "${MCP_ROUTER_PORT:-3200}:3000"
    volumes:
      - mcp-router-data:/data   # installed servers and caches; runs as uid 1000

  llm-router:
    image: ghcr.io/cubicecho/llm-router:latest
    restart: unless-stopped
    environment:
      LLM_ROUTER_TOKEN: ${LLM_ROUTER_TOKEN:-}
      SECURE_LOCAL_NET: ${SECURE_LOCAL_NET:-}
    ports:
      - "${LLM_ROUTER_PORT:-3201}:3000"
    volumes:
      - llm-router-data:/data
    extra_hosts:
      - "host.docker.internal:host-gateway"   # reach a model server on the host

  agent-router:
    # No published image yet: runs a checkout of the repo on Node 26.
    image: node:26-slim
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    working_dir: /app
    command: sh -c "npm ci && npm start"
    environment:
      DATABASE_URL: ${AGENT_ROUTER_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/agent_router}
      # Agents name models as <provider>/<model>; "llm/ollama/qwen3:8b" goes to
      # llm-router, which passes "ollama/qwen3:8b" on to its own provider.
      AGENT_ROUTER_PROVIDERS: '${AGENT_ROUTER_PROVIDERS:-[{"name":"llm","baseUrl":"http://llm-router:3000/v1","apiKey":"${LLM_ROUTER_TOKEN:-}"}]}'
      AGENT_ROUTER_ADMIN_TOKEN: ${AGENT_ROUTER_ADMIN_TOKEN:-}
      SECURE_LOCAL_NET: ${AGENT_ROUTER_SECURE_LOCAL_NET:-}
      NODE_ENV: production
      PORT: 3100
    ports:
      - "${AGENT_ROUTER_PORT:-3205}:3100"
    volumes:
      - ${AGENT_ROUTER_SRC:-./agent-router}:/app

  min-agent:
    image: ghcr.io/cubicecho/min-agent:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: ${MIN_AGENT_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD}@postgres:5432/min_agent}
      OPENAI_API_KEY: ${OPENAI_API_KEY:-}
      PORT: 8787
    ports:
      - "${MIN_AGENT_PORT:-3203}:8787"
    extra_hosts:
      - "host.docker.internal:host-gateway"

  task-server:
    image: ghcr.io/cubicecho/task_server:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: ${TASK_SERVER_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD}@postgres:5432/task_server}
      OPENAI_API_KEY: ${OPENAI_API_KEY:-}
      TZ: ${TZ:-UTC}
    ports:
      - "${TASK_SERVER_PORT:-3204}:8787"
    volumes:
      - task-server-data:/data

  # One Postgres for the apps that need one, one database each.
  postgres:
    image: postgres:17-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: cubicecho
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: cubicecho
    configs:
      - source: create-databases
        target: /docker-entrypoint-initdb.d/create-databases.sql
    volumes:
      - postgres-data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U cubicecho -d cubicecho"]
      interval: 5s
      timeout: 5s
      retries: 10

# Runs once, when the Postgres volume is first created.
configs:
  create-databases:
    content: |
      CREATE DATABASE mcp_router;
      CREATE DATABASE agent_router;
      CREATE DATABASE min_agent;
      CREATE DATABASE task_server;

volumes:
  mcp-router-data:
  llm-router-data:
  task-server-data:
  postgres-data:

Tools: mcp-router #

mcp-router installs MCP servers from registries, npm or PyPI, runs them on demand, proxies remote ones, and serves them all from http://<PUBLIC_HOST>:3200:

  • /mcp is every server merged, with tools named <server>__<tool>.
  • /mcp/<name> is one server.
  • /mcp/w/<slug> is a workspace: a chosen subset, for a client that should only see those tools.
claude mcp add --transport http router http://<PUBLIC_HOST>:3200/mcp \
  --header "Authorization: Bearer <token>"

Every client sends an API key of its own. Make one under Settings → API keys; it is shown once. The config lives in the shared Postgres, and is managed from the UI or over GraphQL at /graphql.

People sign in to the UI, one of two ways:

  • Trusted network. Set MCP_ROUTER_SECURE_LOCAL_NET=true and whoever opens the UI is the local admin. It also opens the /mcp endpoints without a key, so only use it on a network nothing hostile can reach.

  • OIDC, such as heautou. mcp-router has to know its own address before a provider can send you back to it, and that is a setting:

    1. Start with MCP_ROUTER_SECURE_LOCAL_NET=true and open http://<PUBLIC_HOST>:3200.
    2. In Settings, set the public URL to that address, then paste a setup URL from heautou. Pair before the next step, or nobody can sign in.
    3. Set the variable back to false, redeploy, and sign in. The first person in through the provider is the admin. Revoke any API key you don't know.

    Or set the MCP_ROUTER_OIDC_* vars, with http://<PUBLIC_HOST>:3200/api/auth/callback/oidc as the redirect URI; the public URL still has to be set first.

It can also find MCP servers that advertise themselves on the LAN, such as mcp-skills-manager with "Advertise on the local network" on. Docker's default network drops mDNS, so that needs network_mode: host on mcp-router, with Postgres on a published port. mcp-skills-manager still wants an API key, made under its Settings → API keys.

Upgrading mcp-router from 2.x #

mcp-router 3 needs a Postgres and no longer runs as root. Back up the mcp-router-data volume, stop mcp-router, then:

  1. Create its database. The stack only does that for a new Postgres volume. In the postgres container's console:

    createdb -U cubicecho mcp_router
    
  2. Give the data volume to uid 1000, since the old image wrote it as root:

    docker run --rm -v cubicecho-ai_mcp-router-data:/data alpine chown -R 1000:1000 /data
    

    The volume's prefix is your stack's name, if you gave it another.

  3. Set MCP_ROUTER_AUTH_SECRET, choose a sign-in as above, and redeploy with the new image pulled.

The first start imports the old config from the volume, and turns the old token into an API key, so clients keep working. Revoke it once they have their own.

Models: llm-router #

llm-router is the same idea for model servers. Add Ollama, llama.cpp, LM Studio or a hosted API as providers in its UI at http://<PUBLIC_HOST>:3201. Clients use http://<PUBLIC_HOST>:3201/v1 (or /w/<slug>/v1 for a workspace), LLM_ROUTER_TOKEN as the API key, and <provider>/<model> as the model. A model server on the Docker host itself is http://host.docker.internal:<port>/v1.

A pool spreads one model across several servers and keeps each conversation on the same one, so a warm cache stays warm.

Agents: agent-router #

agent-router is ai-router's agent half on its own: agents, workspaces, runs and the agent loop, with no UI and no people — just an admin, on /graphql. It serves the same /v1 and /mcp for agents that ai-router does.

The stack points it at llm-router as its one provider, named llm, so an agent's model is llm/<llm-router provider>/<model> — for example llm/ollama/qwen3:8b. Agents, workspaces and keys are made with GraphQL mutations against http://<PUBLIC_HOST>:3205/graphql, sent with Authorization: Bearer $AGENT_ROUTER_ADMIN_TOKEN; its README walks through them. Tools come from workers you attach to a workspace, not from mcp-router.

It has no published image yet, so the stack runs a checkout of the repo (AGENT_ROUTER_SRC) on Node 26. It is the newest piece here and an MVP.

Something to use it with #

  • min-agent — a chat client, at http://<PUBLIC_HOST>:3203. Under Settings → Agent, point it at llm-router for raw models, or at ai-router or agent-router for agents; add MCP servers under Settings → MCP. Web, Android and desktop.
  • task-server — the same thing with the chat taken out, at http://<PUBLIC_HOST>:3204: a prompt on a cron, with every run's output kept. An agent profile can point at ai-router with an agent's name as the model.

kanban-server was the third app; it is retired, and telos carries on the idea of agents working a board.

Building your own #

min-agent and task-server share their agent loop and MCP client pool, and both are published: agent-core is the endpoint-agnostic loop, and agent-mcp-pool keeps MCP clients connected and hands their tools to it. mcp-discovery is the other direction: it lets a server you write publish a Server Card and announce itself on the LAN, so mcp-router finds it with no address typed in.