Docs

Connect an AI agent

Connect a coding agent to your project through the server's MCP endpoint, which offers each operation of the Zitadel API as a tool.

The Zitadel server answers the Model Context Protocol (MCP) at /api/v1/mcp. MCP is how an AI agent, such as Claude Code or the Copilot agent in VS Code, finds and calls tools. Each operation of the Zitadel API is one tool there, named by its operation ID. A tool call is the operation's own request, so it is authorized, validated and recorded like the same request over HTTP.

The endpoint takes the credential the API takes: your project secret, or a person's token. The credential's scopes decide which tools an agent is shown. A project secret covers every scope, so its agent is shown every tool.

Connect with the configuration setup wrote

zitadel setup writes .mcp.json at your app's root. Claude Code and the Copilot agent in VS Code read it when you start them in that directory:

{
  "mcpServers": {
    "zitadel": {
      "type": "http",
      "url": "http://localhost:8080/api/v1/mcp",
      "headers": {
        "Authorization": "Bearer ${ZITADEL_PROJECT_SECRET:-}"
      },
      "headersHelper": "node -p \"JSON.stringify({Authorization:'Bearer '+JSON.parse(require('fs').readFileSync('.zitadel/secret','utf8')).project_secret})\""
    }
  }
}

The file holds no secret, so commit it with the rest of your app. Each client gets the project secret its own way:

  • Claude Code runs headersHelper in your app's directory. The command reads the project secret from .zitadel/secret, which git ignores. Claude Code runs it only once you trust the folder, and asks before it uses a server from .mcp.json.
  • VS Code runs no helper. It fills ${ZITADEL_PROJECT_SECRET:-} from the environment VS Code was started in, and doesn't read .env files. Export the variable before you start VS Code: .env.development.local holds its value.

Setup doesn't change a configuration you wrote. When .mcp.json already names a server zitadel, or isn't a JSON object, setup leaves the file as it is. When it names other servers, setup adds zitadel beside them and keeps their entries as you wrote them.

Connect another client

Other clients read their own file. Add the endpoint there by hand, with the project secret from the environment:

  • Cursor, in .cursor/mcp.json:

    {
      "mcpServers": {
        "zitadel": {
          "url": "http://localhost:8080/api/v1/mcp",
          "headers": { "Authorization": "Bearer ${env:ZITADEL_PROJECT_SECRET}" }
        }
      }
    }
  • Codex, in .codex/config.toml of a project you trust:

    [mcp_servers.zitadel]
    url = "http://localhost:8080/api/v1/mcp"
    bearer_token_env_var = "ZITADEL_PROJECT_SECRET"

Use your server's address in place of http://localhost:8080: it's the server in zitadel.json.

What the agent may do

  • Writes ask first. An agent is told to confirm with you before a tool that creates, changes or deletes. A call that deletes, revokes, rolls back or deploys asks you through the endpoint itself, and is refused when your client can't ask.
  • A tool's answer can hold a credential. publishApplication answers with a client secret and createInvitation with a link that gives a role. The tool's description tells the agent to pass it to you, or store it where you keep secrets, and to write it nowhere else.
  • Its calls are marked. A request an agent made through the endpoint carries metadata.invoked_by: "mcp" in its request.api event (Find out what happened with events).

An agent with a shell can do the same work with the CLI, which costs its context less: npx @zitadel/cli@latest api <operationId> calls any operation.

Was this helpful?