---
title: "Deploy agentgateway LLM + MCP Gateway with UI Login"
description: "agentgateway LLM and MCP gateway with a login-protected admin UI"
category: "AI/ML"
url: https://railway.com/deploy/agentgateway-llm-mcp-gateway-with-ui-log
---

# Deploy agentgateway LLM + MCP Gateway with UI Login

agentgateway LLM and MCP gateway with a login-protected admin UI

**[Deploy agentgateway LLM + MCP Gateway with UI Login on Railway](https://railway.com/template/agentgateway-llm-mcp-gateway-with-ui-log)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/agentgateway-llm-mcp-gateway-with-ui-log/manifest.json

- **Creator:** Protemplate
- **Category:** AI/ML
- **Total deploys:** 2

## Template content

### Caddy https://avatars.githubusercontent.com/u/208695296?v=4

- **Image:** caddy:2.11-alpine
- **Start command:** `sh -c 'echo c2V0IC1lCjogIiR7UE9SVDo/UE9SVCBpcyByZXF1aXJlZH0iCjogIiR7VUlfVVNFUk5BTUU6P1VJX1VTRVJOQU1FIGlzIHJlcXVpcmVkfSIKOiAiJHtVSV9QQVNTV09SRDo/VUlfUEFTU1dPUkQgaXMgcmVxdWlyZWR9Igo6ICIke1VJX1BST1hZX1RPS0VOOj9VSV9QUk9YWV9UT0tFTiBpcyByZXF1aXJlZH0iCjogIiR7VVBTVFJFQU06P1VQU1RSRUFNIGlzIHJlcXVpcmVkfSIKSEFTSD0iJChjYWRkeSBoYXNoLXBhc3N3b3JkIC0tcGxhaW50ZXh0ICIkVUlfUEFTU1dPUkQiKSIKY2F0ID4gL2V0Yy9jYWRkeS9DYWRkeWZpbGUgPDxFT0YKewoJYXV0b19odHRwcyBvZmYKCWFkbWluIG9mZgp9CjokUE9SVCB7CgloYW5kbGUgL2dhdGV3YXktaGVhbHRoIHsKCQlyZXNwb25kICJvayIgMjAwCgl9CglAdWkgcGF0aCAvIC91aSAvdWkvKiAvYXBpLyoKCWhhbmRsZSBAdWkgewoJCWJhc2ljX2F1dGggewoJCQkkVUlfVVNFUk5BTUUgJEhBU0gKCQl9CgkJcmV2ZXJzZV9wcm94eSAkVVBTVFJFQU0gewoJCQloZWFkZXJfdXAgLUF1dGhvcml6YXRpb24KCQkJaGVhZGVyX3VwIFgtQWd3LVVpLVRva2VuICIkVUlfUFJPWFlfVE9LRU4iCgkJfQoJfQoJaGFuZGxlIHsKCQlyZXZlcnNlX3Byb3h5ICRVUFNUUkVBTSB7CgkJCWhlYWRlcl91cCAtWC1BZ3ctVWktVG9rZW4KCQkJZmx1c2hfaW50ZXJ2YWwgLTEKCQl9Cgl9Cn0KRU9GCmV4ZWMgY2FkZHkgcnVuIC0tY29uZmlnIC9ldGMvY2FkZHkvQ2FkZHlmaWxlIC0tYWRhcHRlciBjYWRkeWZpbGUK | base64 -d > /tmp/start.sh && exec sh /tmp/start.sh'`
- **Health check:** /gateway-health
- **Public domain:** Yes

### agentgateway https://avatars.githubusercontent.com/u/208695296?v=4

- **Image:** ghcr.io/agentgateway/agentgateway:v1.7.0
- **Start command:** `/app/agentgateway --config '{"config":{"database":{"url":"sqlite:///config/data.db"},"storage":{"mode":"hybrid"}},"gateways":{"default":{"port":4000}},"llm":{"policies":{"apiKey":{"mode":"strict","keys":[{"key":"${AGENTGATEWAY_API_KEY}"}]}}},"mcp":{"policies":{"apiKey":{"mode":"strict","keys":[{"key":"${AGENTGATEWAY_API_KEY}"}]}}},"ui":{"gateways":"default","policies":{"apiKey":{"mode":"strict","keys":[{"key":"${UI_PROXY_TOKEN}"}],"location":{"header":{"name":"x-agw-ui-token"}}}}}}'`
- **Health check:** /healthz/ready

## Documentation

# Deploy and Host agentgateway on Railway

agentgateway is an open source proxy for AI traffic, written in Rust. It puts one endpoint in front of LLM providers (OpenAI compatible API), MCP servers and agent to agent traffic, with a web UI for models, API keys, budgets, guardrails, policies and request logs.

## About Hosting agentgateway

This template runs the official `ghcr.io/agentgateway/agentgateway:v1.7.0` image with a Railway volume at `/config`, where agentgateway keeps a SQLite database with everything you configure in the UI plus request logs. The official image has no shell and by default serves its UI without any login, so the template adds a small Caddy service in front. Caddy is the only public service: it asks for a username and password on the UI and passes API traffic straight through. The gateway itself stays on the private network. API keys are on from the first boot: the LLM and MCP endpoints refuse requests without the generated key. The UI password, the API key and an internal proxy token are generated for you.

## Common Use Cases

- **Unified LLM API**: one OpenAI compatible base URL for OpenAI, Anthropic, Gemini, Bedrock, Azure, Ollama and more
- **MCP gateway**: multiplex several remote MCP servers behind one authenticated `/mcp` endpoint
- **API keys and budgets**: per app or per team keys with spend limits and model allow lists
- **Guardrails and policies**: prompt guards, rate limits, authorization rules, header and body transformations
- **Observability**: request logs and cost analytics in the UI, Prometheus metrics, OpenTelemetry export
- **Private gateway for other Railway services**: keep provider keys off your app containers

## Dependencies for agentgateway Hosting

- **Railway volume** at `/config` (included)
- **Caddy login gateway** (included)
- **Provider API keys**: optional at boot, add providers and models in the UI
- **No database service required**: SQLite is the upstream default. Postgres is an optional alternative

### Deployment Dependencies

- [agentgateway documentation](https://agentgateway.dev/docs/standalone/latest/)
- [Docker install guide](https://agentgateway.dev/docs/standalone/latest/documentation/setup/install/docker/)
- [Configuration reference](https://github.com/agentgateway/agentgateway/blob/v1.7.0/schema/config.md)
- [agentgateway GitHub repository](https://github.com/agentgateway/agentgateway)

### Implementation Details

What is included:

| Service | Image | Public | Role |
|---------|-------|--------|------|
| agentgateway | `ghcr.io/agentgateway/agentgateway:v1.7.0` | No | UI, LLM API, MCP and routes on port 4000, SQLite on the volume |
| Caddy | `caddy:2.11-alpine` | Yes | Login prompt on the UI paths, pass through for the rest |

Key variables:

```env
# agentgateway
PORT=15021
AGENTGATEWAY_API_KEY=agw_sk_${{secret(40)}}
UI_PROXY_TOKEN=${{secret(48)}}
RAILWAY_RUN_UID=0

# Caddy
PORT=8080
UI_USERNAME=admin
UI_PASSWORD=${{secret(24)}}
UI_PROXY_TOKEN=${{agentgateway.UI_PROXY_TOKEN}}
UPSTREAM=${{agentgateway.RAILWAY_PRIVATE_DOMAIN}}:4000
```

The gateway receives its baseline configuration inline in the start command and stores everything you change in the UI in the database on the volume, so your setup survives redeploys.

**First steps after deploy**

1. Open the Caddy service domain and sign in with `UI_USERNAME` (admin) and the generated `UI_PASSWORD` from the Caddy service variables. Anonymous visitors get a 401.
2. Add a provider and a model in the UI. Optionally set `OPENAI_API_KEY` on the agentgateway service and enter `$OPENAI_API_KEY` in the key field so the key is not stored in the database.
3. Call `https:///v1/chat/completions` with `Authorization: Bearer `. Requests without a key are refused, so nobody who finds the URL can spend your provider credits.
4. Add remote MCP servers under MCP and connect clients to `https:///mcp` with the same key.

Good to know: custom HTTP routes you create under Traffic are open unless you add an auth policy to them. stdio MCP servers are not supported by the official image, use remote ones. Keep one replica, since SQLite and Railway volumes are single instance.

## Why Deploy agentgateway on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying agentgateway on Railway, you get a pinned, health checked AI gateway with a login protected UI, generated secrets, persistent storage, managed SSL, and private networking to the rest of your Railway project.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/agentgateway-llm-mcp-gateway-with-ui-log
