Skip to content

Require a caller on the agent and Google Drive MCP servers; add GET /mcp - #231

Merged
antiv merged 2 commits into
mainfrom
mcp-require-auth
Oct 14, 2026
Merged

antiv merged 2 commits into
mainfrom
mcp-require-auth

Conversation

@antiv

@antiv antiv commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Problem

Two MCP servers answered every route without credentials:

  • /agents/<name>/mcp: anyone who reached port 8000 could run any agent in MCP_EXPOSED_AGENTS, spending the server's LLM keys. Per-user budgets didn't apply, and neither did the agent's allowed_for_roles, because the tool call reaches the agent over A2A without the caller's identity.
  • /gdrive/mcp: anyone could list, search and read Google Drive files, and see their sharing permissions, through the server's service account.

/images/mcp already required a signed-in caller. docs/dev/mcp-servers.md claimed every MCP endpoint did.

Change

  • New shared/utils/mcp/mcp_auth.py:
    • require_mcp_user reuses get_pat_user, the gate the OpenAI-compatible API uses. It accepts a personal access token, Basic auth, the login token or a dashboard session, from an admin or a role in ALLOWED_API_ROLES.
    • agent_allowed reads the agent's allowed_for_roles and asks RBACMiddleware.check_agent_access. An agent with no roles is admin-only.
  • Agent MCP routes, except health and OPTIONS, require a caller (401) who may use that agent (403).
  • Google Drive MCP routes, except health and OPTIONS, require a caller.
  • New GET /mcp lists the exposed agents the caller may use, with name, description and MCP URL.
  • The agent servers' initialize response now includes serverInfo.title and serverInfo.description, plus instructions. Without them lhm plugin init (LobeHub market) fails with "Could not infer a plugin description".

Breaking

Clients that call these servers without credentials will now get 401. They need to send Authorization: Bearer mate_pat_... (or Basic auth). This includes other MATE instances that consume these agents through mcp_servers_config. ${VAR} interpolation in headers keeps the token out of the config row. There is deliberately no switch to restore the old behaviour.

Not changed

  • /images/mcp keeps its dashboard-user check and still doesn't accept personal access tokens. The docs now say so.
  • Agent health still shows the agent's name and description publicly.

Tests

  • shared/test/test_mcp_auth.py:
    • 401 with no token and with a wrong one
    • 403 without access to the agent
    • 200 with access
    • health and preflight stay public
    • Google Drive routes
    • /mcp lists only allowed agents
    • agent_allowed role parsing
  • On the old code the Google Drive auth test fails (200 instead of 401).
  • Full suite: 1497 tests OK.

Docs

  • docs/dev/mcp-servers.md: new "Who may call" section, /mcp, auth line corrected, personal access tokens for clients.
  • docs/dev/openai-api-and-mcp.md: same, briefly.
  • README MCP section updated.
  • docs/reference/api.md regenerated.
  • gen_docs.py --check and drift --base origin/main are clean.

antiv added 2 commits October 14, 2026 20:09
The agent MCP servers (/agents/<name>/mcp) and the Google Drive MCP server
(/gdrive/mcp) answered every route without credentials: anyone who reached
port 8000 could run exposed agents on the server's provider keys, or list and
read Drive files through the server's service account.

Every route but health and CORS preflight now takes the same callers as the
OpenAI-compatible API (get_pat_user: personal access token, Basic auth, login
token or session, with a role in ALLOWED_API_ROLES). An agent's routes also
check the agent's allowed_for_roles, since the tool call reaches the agent
over A2A without the caller's identity.

GET /mcp lists the exposed agents the caller may use, with their MCP URLs.

The agent servers' initialize response now carries the agent's description
in serverInfo, which MCP registries such as the LobeHub market read.
@antiv
antiv merged commit 28f5431 into main Oct 14, 2026
2 checks passed
@antiv
antiv deleted the mcp-require-auth branch October 14, 2026 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant