Connect an MCP host to Elastic Agent Builder

After an OAuth client is created, configure your MCP host, usually your AI agent, with the client ID and MCP server URL, then complete the OAuth authorization flow to establish the connection. After completing the setup, your MCP host has an authorized OAuth connection to Elastic Agent Builder and can run its tools with your permissions.

This page covers several common MCP hosts:

  • Claude Code CLI
  • Claude desktop app
  • claude.ai
  • ChatGPT
  • Cursor
  • Amazon Bedrock AgentCore Gateway

Other OAuth 2.1 hosts follow the same general pattern, so consult your host's documentation for the specific configuration format.

Confirm the following before you configure your MCP host:

  • You have an MCP host that supports OAuth 2.1 with a pre-registered client ID. Hosts that rely solely on dynamic client registration are not supported.
  • You have the client ID and MCP server URL for the OAuth client, copied exactly as Kibana displays them. Each client works only with that MCP server URL, which is the MCP endpoint of one Kibana space. You either created the client yourself or received these values from the person who did.
  • You have access to the Serverless project that the OAuth client is scoped to, not just organization-level access. The connection acts with your own permissions in that project, so you also need the privileges required for the tools you'll run through the MCP server, such as Elastic Agent Builder access and Read access to any data those tools query. To learn more, refer to Permissions.

Complete the following steps to start using your OAuth client in your MCP host.

  1. Configure your MCP host

    Choose the instructions for your host.

  2. Authorize the connection

    The first time your MCP host tries to use the configured server, it opens a browser window and starts the OAuth authorization flow.

    Note

    Some tools might require additional manual steps. For example, Claude Code CLI requires that you enter /mcp or run claude mcp login <mcp-server-name> before the browser window opens.

    1. Your browser opens to an Elastic Cloud sign-in page. Sign in with your Elastic Cloud credentials. If you have an active session, you are not prompted to log in again.
    2. The Connect and authorize page opens, showing which project the OAuth client is requesting access to. Click Authorize to grant access.
    3. The browser confirms the authorization is complete. Close the tab and return to your MCP host.

    Authorization creates a new app connection that's scoped to your account and to the OAuth client's project and space. The connection name is auto-generated in the format <client-name>#<word-pair>. This connection is visible in both Kibana and the Elastic Cloud Console.

    If you click Deny on the Connect and authorize page, then no connection is created. The host retries the flow the next time you use a tool, or you can restart the host to trigger a fresh attempt.

    All application connections mirror the permissions of the user that authorizes the connection. If you authorize the connection and you have read and write permissions, then so will your connected application.

    When a user's permissions change, the change applies on the next token refresh; changes to a custom role apply immediately.

    You can use a secondary user with limited permissions to restrict what the connected application can access. Permissions follow the user who authorizes the connection, so ensure that user is signed in before authorizing it. This user does not need to be the same account used to create the OAuth client or manage application connections.

  3. Verify the connection

    This step is optional. To ensure that the connection is registered in Kibana, you can check the number of currently active connections for your client.

    In Kibana, go to Agent Builder → Tools library, click Manage MCP, and select Manage MCP clients (OAuth) to confirm the connection count for your client has increased. If you don't see it within a minute of authorizing, refresh the page.

    You can also check your connection in the Elastic Cloud Console at Organization → Application connections.

The host shows an error and doesn't open a browser.

Confirm the {MCP_SERVER_URL} in your config matches exactly what Kibana displays. The correct URL ends with /api/agent_builder/mcp. A typo, extra slash, or doubled path segment will prevent the OAuth discovery step from completing.

Authorization fails with "does not match the client's registered resource" or requests fail with a 400 VALIDATION.OAUTH error.

The MCP server URL in your host's config doesn't match the MCP server URL of the OAuth client. The error you see depends on when the mismatch is detected:

  • During authorization: Authorization fails with an invalid_request error stating that the resource doesn't match the client's registered resource.
  • During requests: If the host reuses tokens it obtained for a different MCP server URL, or doesn't send the MCP server URL during authorization, requests to the MCP server fail with the 400 error.

Common causes:

  • The client was created in a different space than the one in the URL.
  • The URL adds, removes, or changes the /s/<space-id> segment, for example by adding /s/default to a default-space URL.
  • The client is an older client that works only with the default space, even though it was created in a custom space. Its MCP server URL has no /s/<space-id> segment.

To fix it:

  1. Create a client in the space you want to connect to, or use an existing client from that space.
  2. Update your host's config with that client's ID and the MCP server URL that Kibana displays for it.
  3. Clear the host's cached OAuth credentials, as described in your MCP host's documentation. Until you clear them, most hosts don't prompt you to authorize again.

Authorization completed but no connection appears in Kibana.

Confirm you have access to the Serverless project associated with the OAuth client. If your account doesn't have project access, the authorization step fails silently.

The host shows a new sign-in prompt after a period of inactivity.

Connections expire after 30 days without use. Complete the authorization flow again to re-establish the connection.

The authorization flow fails after you wait on the authorization page.

The MCP host's local callback server times out if the Connect and authorize page is left open too long before you click Authorize. Start the flow again and click Authorize promptly without leaving the page open.

Amazon Bedrock AgentCore Gateway calls fail with an authorization error after you revoke a connection.

AgentCore keeps using the revoked access token until it expires, which takes up to one hour. After that, AgentCore prompts the user to authorize again.

You need to start fresh with a new connection.

Consult your MCP host's documentation for how to clear cached OAuth credentials and force a new authorization. Most hosts maintain only one connection for each MCP server URL, so reconfiguring with the same URL reuses the existing connection unless the cached credentials are cleared.

When access is no longer needed, revoke the connection.