Skip to content

Adding MCP Servers

The LTG API Portal works as an MCP gateway — a single entry point that wraps many upstream MCP servers. Customers authenticate once with Authentik OAuth + their ltg_* API key, and get access to every wrapped MCP’s tools through one connection.

This guide walks you through adding a new MCP server to the platform end-to-end.

Architecture

Customer (Claude Desktop)
│
│ mcp-remote → OAuth (Authentik) + X-API-Key: ltg_xxx
▼
LTG MCP Gateway (apps/mcp-server) ← single entry point
│
│ 1. Verify Authentik access token (who)
│ 2. Validate ltg_xxx key (quota, rate limit, billing)
│ 3. Route to upstream by tool prefix
▼
Upstream MCPs (private Railway services)
├─ LogicMonitor MCP → lm_* tools
├─ Stripe MCP → stripe_* tools
└─ Any new MCP → prefix_* tools

Customers never see upstream URLs, bearer tokens, or credentials. Everything flows through our gateway with unified auth and usage tracking.

OAuth2 / Authentik — One Application, Every MCP

You do not register a new Authentik application per MCP. The gateway (apps/mcp-server) is the single OAuth2 client registered in Authentik. Everything wrapped behind it reuses that flow.

Authentik Application: "LTG MCP Gateway" ← one application, forever
├─ Client ID / Secret → held by apps/mcp-server
├─ Redirect URIs → https://mcp-server-production-ba1f.up.railway.app/callback
└─ Scopes → openid profile email

When a customer connects via mcp-remote:

  1. OAuth (who): Claude Desktop → mcp-remote → Authentik login → access token issued to the gateway (not the upstream)
  2. API key (what plan): X-API-Key: ltg_xxx → validated against portal subscription (quota, rate limit, product entitlement)
  3. Upstream bearer (server-side): gateway forwards with Authorization: Bearer <MCP_BEARER_TOKEN> from the credentials vault

The upstream MCP never sees the Authentik token or the ltg_* key — only the server-side bearer. This means:

  • ✅ No Authentik admin changes when adding an MCP
  • ✅ No per-MCP client IDs, redirect URIs, or scopes
  • ✅ Upstreams don’t need to support OAuth2 — plain bearer is enough
  • ✅ Token rotation on one upstream doesn’t affect customers
  • ✅ Revoking a customer = revoke their ltg_* key, not their OAuth session

If you ever need to replace the gateway’s Authentik application (e.g. domain change), update the AUTHENTIK_* env vars on apps/mcp-server and restart — no upstream MCP is affected.

Requirements for the Upstream MCP

Any MCP you want to wrap needs:

  • Streamable HTTP transport (preferred) or SSE
  • Bearer token auth via Authorization: Bearer <token> header
  • Health check endpoint (/healthz or similar)
  • Dockerfile for Railway deployment
  • Configurable via env vars for credentials

Most open-source MCPs already support all of these. If yours doesn’t, fork it and add a small Express wrapper.

Step 1 — Deploy the MCP to Railway

1a. Create a new Railway service

Terminal window
railway add --service my-mcp

Choose “Empty Service” when prompted.

Option A: GitHub source

  • Railway dashboard → your service → Settings → Source → connect GitHub repo
  • Set branch + root directory
  • Railway auto-deploys on push

Option B: Deploy from local clone

Terminal window
git clone https://github.com/<owner>/<mcp-repo>.git /tmp/my-mcp
cd /tmp/my-mcp
railway link --project <project-id> --service my-mcp
railway up -d

1c. Set env vars

Terminal window
# Generate a secure bearer token — this is the upstream auth our gateway uses
BEARER=$(openssl rand -base64 32)
railway variables --service my-mcp \
--set "MCP_TRANSPORT=streamable-http" \
--set "MCP_ADDRESS=0.0.0.0:\${PORT}" \
--set "MCP_ENDPOINT_PATH=/mcp" \
--set "MCP_BEARER_TOKEN=$BEARER" \
--set "MCP_READ_ONLY=true" \
--set "NODE_ENV=production" \
--set "PORT=3000"
# Plus whatever credentials the MCP needs (e.g. LM_COMPANY, LM_BEARER_TOKEN)
railway variables --service my-mcp \
--set "MY_API_KEY=<from vendor>" \
--set "MY_API_SECRET=<from vendor>"

1d. Keep it private

Do NOT generate a public domain. The upstream MCP should only be reachable from inside your Railway project via the internal DNS:

http://my-mcp.railway.internal:3000/mcp

Customers will connect through our MCP gateway, not the upstream directly. This keeps your bearer tokens and vendor credentials server-side.

1e. Verify

From any service in the same Railway project (e.g. the portal shell):

Terminal window
curl http://my-mcp.railway.internal:3000/healthz
# → "ok"

Step 2 — Store the Bearer Token in the Portal Credentials Vault

  1. Portal → Credentials → Add Credential
  2. Fill in:
    • Name: My MCP Gateway Token
    • Provider: my-mcp
    • Grant Type: bearer
    • Secret: the MCP_BEARER_TOKEN value from Step 1c

The vault encrypts the secret at rest and shows a masked preview (abcd••••xyz). The actual value is only read by the gateway when forwarding requests.

Step 3 — Register the MCP in the Portal Registry

  1. Portal → MCP Servers → Register MCP Server
  2. Fill in:
Field Value
Name My MCP
Description Short description customers will see
Server URL http://my-mcp.railway.internal:3000/mcp
Transport STREAMABLE-HTTP
Auth Type Bearer Token
API Key / Token (paste the same MCP_BEARER_TOKEN value)
  1. Under Gateway Wrapping:

    • ✅ Enable Gateway Wrapping
    • Tool Prefix: mymcp_ (short namespace, trailing underscore)
    • Product ID: (optional) — link to a subscription product to gate access
  2. Click Register Server

Step 4 — Discover Tools

On the MCP server detail page:

  1. Click Discover Tools
  2. Verify the tool count and spot-check a few names
  3. Status should flip from UNKNOWN / OFFLINE to ONLINE

Tools are now cached in the portal and ready for the gateway to re-export.

Step 5 — (Optional) Create a Product for Resale

If you want to charge for this MCP as a distinct SKU:

  1. Portal → Products → Add Product
  2. Name it to match the Product ID you set in Step 3 (e.g. my-mcp)
  3. Link it to pricing plans in Packages (e.g. Pro-only, Enterprise-only)
  4. Customers must subscribe to this product to use the wrapped tools

Without a product ID, all authenticated customers with any active subscription can use the tools.

Step 6 — Test from the Portal

On the MCP server detail page:

  1. Invoke Tool dropdown → pick a read-only tool (e.g. list_resources)
  2. Fill in required params
  3. Click Run Tool — real upstream data comes back

This confirms the portal can reach the upstream MCP with the stored credentials.

Step 7 — Test from Claude Desktop

Edit your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):

{
"mcpServers": {
"ltg": {
"command": "bash",
"args": [
"-c",
"exec npx -y mcp-remote@latest https://mcp-server-production-ba1f.up.railway.app/mcp --header 'X-API-Key: ltg_YOUR_KEY_HERE'"
]
}
}
}

Then:

  1. Restart Claude Desktop
  2. OAuth popup appears → sign in with Authentik
  3. List MCP tools — you should see your new mymcp_* tools alongside the built-in portal/ConnectWise tools
  4. Invoke a tool — it routes through our gateway → validates subscription → forwards to upstream → response returned

Step 8 — Verify Usage Tracking

Every gateway call counts against the customer’s ltg_* subscription:

  • Portal → Usage page → see the call appear in Recent Requests
  • Portal → Usage → click the subscription → see /mcp/mymcp_<tool> in Top Endpoints
  • Customer’s callCount / callCountToday increments
  • Plan rate limits and daily quotas enforced automatically

Monitoring

Signal Where to look
Upstream crashes / errors Railway → your MCP service → Logs
Customer invocations Portal → Audit Log → filter by mcp_server.tool_called
Usage breakdown Portal → Usage → Top Endpoints
Per-subscription drill-in Portal → Usage → click subscription row

Troubleshooting

Symptom Likely Cause Fix
Tool not discovered Gateway Enabled unchecked, or status=offline Discover Tools again, verify upstream is running
401 from upstream MCP_BEARER_TOKEN mismatch Check credentials vault matches Railway env var
Subscription required: ... Customer lacks the product Subscribe them to the product, or remove Product ID
429 rate limited Plan quota exceeded Upgrade plan or wait for reset
Tool name collision Two upstreams exposing same name Set distinct Tool Prefix values
Gateway not loading upstream Background cache stale Restart mcp-server, or wait 60s

Updating an MCP

  • Code updates: if connected to GitHub, Railway auto-redeploys on push. Otherwise run railway up -d from the local clone.
  • Env var changes: Railway redeploys automatically on variable update.
  • Token rotation: update both the Railway env var AND the credentials vault entry. Portal mcp-server picks up the new credential within 60s.
  • New tools added upstream: click Refresh on the MCP server detail page to re-discover.

Pattern Summary

Adding a new MCP is now a repeatable 7-step process:

  1. Deploy MCP as a private Railway service with a bearer token
  2. Store the token in the portal Credentials Vault
  3. Register in MCP Servers with Gateway Wrapping enabled
  4. Discover tools
  5. (Optional) Create a Product for monetization
  6. Test via portal Invoke Tool
  7. Customers use it automatically through their existing Claude connection

No changes to customer configuration. No per-upstream OAuth flows. One API key, one subscription, one set of rate limits — every wrapped MCP inherits the same auth, billing, and observability.