Repository navigation
Description
Summary
Introduce optional authentication for MCP server when exposed over HTTP/WebSocket:
- IP allowlist (default
*, supports exact IP and CIDR) - Optional bearer token required for HTTP routes, WebSocket upgrades, and tool/resource execution
- Unity UI “Auth” section to configure allowlist and token
- MCP clients prompted for token when server signals auth is enabled
Background / Problem
The MCP server currently binds to 0.0.0.0 and exposes HTTP routes, WebSocket hub, and tool execution with no authentication. Anyone with network reach can register tools or invoke high-privilege tools (e.g., runtime compilation), leading to remote code execution.
Goals
- Keep current “no-auth” behaviour unless explicitly enabled.
- Provide defence-in-depth: IP filter at ingress + token check before tool/resource dispatch.
- Minimal friction for users: simple token, flexible IP allowlist, clear UX in Unity UI and clients.
- Backward compatible and easily documented.
Non-Goals
- Full RBAC, mTLS, or per-project scoped tokens (could be future work).
Requirements
- Config surface:
auth_enabled(bool),allowed_ips(list; supports*, CIDR, single IP),auth_token(string from env/CLI/Unity UI). Empty token means “no token required.” - Ingress enforcement: Apply IP allowlist and token checks on HTTP routes and WebSocket upgrades; reject with 401/403 and clear messages.
- Tool dispatch enforcement: Before executing any tool/resource, re-check token (prevents alternate path bypass).
- Unity UI: New “Auth” section to edit allowlist and token; default allowlist
*; token optional. - Client behaviour: When auth is enabled, server signals “auth required” so MCP clients prompt and send
Authorization: Bearer <token>. - Observability: Startup log stating auth state and allowlist; warn if auth enabled but token empty.
- Docs: How to enable, sample config, client usage.
Proposed Approach
-
Config wiring
Add fields:auth_enabled,allowed_ips,auth_token.
Sources: env vars, CLI flags. -
Ingress middleware (HTTP + WebSocket)
Check IP allowlist.
If auth enabled and token set, require bearer token.
Respond with 401/403 when necessary. -
Tool dispatch hook
Enforce same token check before executing any tool/resource. -
Unity UI
New “Auth” panel with allowlist and masked token field. -
Client signal
Handshake/meta flag for “auth_required”. -
Docs & examples
Clear README and UI steps.
Config Examples
-
Env:
UNITY_MCP_AUTH_ENABLED=1UNITY_MCP_ALLOWED_IPS=127.0.0.1,10.0.0.0/8UNITY_MCP_AUTH_TOKEN=supersecret
-
CLI:
mcp-for-unity --transport http --http-url http://localhost:8080 --auth-enabled --auth-token duq3NNkWiiarxEETlwpoZFiyn0GCzaVGNva2RMn/y6g --allowed-ip *
Testing (targeted)
- Allowlist:
- Accept request from allowed IP; reject from non-allowed.
- CIDR match pass/fail.
- Token:
- 401 on missing/incorrect token when enabled.
- Pass with correct bearer.
- Tool dispatch:
- Direct tool call without token rejected even if route passed.
- WebSocket:
- Upgrade denied without token when enabled; allowed with correct token.
- Regressions:
- Auth disabled: legacy behaviour intact.
Rollout / Risk
- Backward compatibility: auth disabled by default.
- Minimal risk to existing users; new checks only when enabled.
- Potential usability risk if users enable auth but forget token—mitigated with clear startup logs and 401 messaging.
Open Questions
- Default allowlist: keep
*or prefer RFC1918 by default? - Should empty token + enabled be permitted, or warn+block? (suggest warn but allow)
- Should plugins use a separate token vs. shared token?
Activity
Jordonh18 commentedon Dec 5, 2025
Create a draft pull request: #434 still a work in progress at the moment.
msanatan commentedon Jan 24, 2026
Hi @Jordonh18, I've been working on this some more. I've come to realize that this may not be the best approach. The MCP server should be focused on just that, being a performant MCP server. Authorization is a bit out of scope for it. However, we do need auth to be hosted remotely in a secure manner - as what we have isn't enough.
So the change I'm making does a few things:
This way the MCP server and plugin is decoupled from the logic of authorizing users. As an example, Coplay hosts this server remotely. With this system we can have users sign into Coplay, and create API keys for the Unity MCP server. However, this is an open source product, it's not tied to Coplay services, or any specific vendor except Unity for obvious reasons. This set up allows anyone to set their own URLs to get the same secure configuration. And this is the approach we'll take.
It's also common and recommended for MCP services to use the OAuth2 flow for authorization. That's something we can do in the future, and it'll be easier if keep the server decoupled form auth logic.
Thanks for all your effort, this PR (and the previous ones) are greatly appreciated. But I think this approach is more sustainable moving forward
CC @dsarno @Scriptwonder
As you've noticed, this is a mono-repo. So there's value in adding a separate authorization server as a production ready service that could mint and validate API keys. The
docker-composefile can spin up both of them so users can test locally before deploying. If you're still keen, that option would be welcomedmsanatan commentedon Jan 30, 2026
FYI, rate limiting should be coming in soon. Allow lists will be useful as well
msanatan commentedon Jan 30, 2026
And we're using API keys instead of Auth tokens, which are longer lived than OAuth tokens. OAuth 2 support looks like a worthy venture.