<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
  <channel>
    <title><![CDATA[Lorena Bălan - Elasticsearch Labs]]></title>
    <description><![CDATA[Articles and tutorials from the Search team at Elastic]]></description>
    <copyright><![CDATA[© 2026. Elasticsearch B.V. All Rights Reserved]]></copyright>
    <image>
      <title><![CDATA[Lorena Bălan - Elasticsearch Labs]]></title>
      <url>https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt1121c0bf0e8a6e65/6a88da6340a1841030ef456f/search-labs-thumbnail.png</url>
      <link>https://www.elastic.co/search-labs/author/lorena-bălan</link>
    </image>
    <link>https://www.elastic.co/search-labs/author/lorena-bălan</link>
    <atom:link href="https://www.elastic.co/search-labs/rss/author/lorena-bălan.xml" rel="self" type="application/rss+xml"/>
    <language><![CDATA[en]]></language>
    <lastBuildDate>Tue, 01 Dec 2026 17:07:22 GMT</lastBuildDate>
  <item>
    <title><![CDATA[Who's asking? Per-user Elasticsearch access for Amazon Bedrock AgentCore agents]]></title>
    <description><![CDATA[Every tool call runs as whoever is signed in, and revoking one user's access leaves everyone else working. Here's how to wire AgentCore Gateway to Elastic Cloud Serverless through an OAuth MCP client.]]></description>
    <content:encoded><![CDATA[<p>Most Amazon Bedrock AgentCore agents serve more than one person, and those people rarely have access to the same data. A support engineer needs customer tickets, while a contractor should only see the public docs. If your agent connects to Elasticsearch with a single API key, both of these users query as the same Elastic identity, and the agent could return data that the requester isn’t meant to see.</p><p>In this post, I connect AgentCore Gateway to an Elastic Cloud Serverless (Serverless) project through an<a href="https://www.elastic.co/docs/deploy-manage/app-connections/oauth-clients"> OAuth Model Context Protocol (MCP) client</a> instead. Each user signs in to Elastic once and authorizes the gateway. From then on, every tool call runs as the user who is signed in, with the roles that their account allows. I also cover how to revoke one user without rotating a key or impacting anyone else. OAuth MCP clients are available on Serverless.</p><p>The first call runs all nine steps shown in the following image. Every call after that runs four. Steps 4–7  are one-time sign-in and consent. After that, the user's JSON Web Token (JWT) goes to the gateway and their Elastic access token comes back, so the search runs as them.</p><p>You don't need a finished app or an AgentCore runtime to follow along. I share the scripts to run in place of the Return URL and AgentCore agent (Runtime) boxes shown below.</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt417e3f984a218a99/6b0d09233893232fa3ea3039/image16.png" alt="Architecture diagram: Amazon Bedrock AgentCore Gateway querying Elasticsearch over MCP with per-user OAuth" /><h2>What you need before connecting AgentCore to Elasticsearch</h2><ul><li><p>An Elastic Cloud Serverless project. MCP clients that use OAuth <a href="https://www.elastic.co/docs/deploy-manage/app-connections/create-oauth-client">are only available</a> on Serverless projects.</p></li><li><p>Read access to <a href="https://www.elastic.co/docs/explore-analyze/ai-features/elastic-agent-builder">Elastic Agent Builder</a> in that project (required for creating the MCP client).</p></li><li><p>An AWS account with access to <a href="https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/what-is-bedrock-agentcore.html">Amazon Bedrock AgentCore</a> in a Region where it's available, plus permission to use AgentCore Identity, AgentCore Gateway, Amazon Cognito, and AWS Secrets Manager.</p></li><li><p>For the optional test scripts:</p></li><ul><li><p>Python 3.13 or later.</p></li><li><p><code>curl</code>.</p></li><li><p><code>jq</code>.</p></li><li><p>Either <a href="https://github.com/FiloSottile/mkcert"><code>mkcert</code></a> or <code>OpenSSL</code> to create a local certificate.</p></li></ul></ul><h2>Create an OAuth MCP client in Elastic Cloud Serverless</h2><p>To let AgentCore talk to your project, you first need to create an OAuth MCP client. AgentCore uses this client to talk to the <a href="https://www.elastic.co/docs/explore-analyze/ai-features/agent-builder/mcp-server">Agent Builder MCP server</a> and to access the same MCP tools that your Agent Builder agent has. Find more details in the <a href="https://www.elastic.co/docs/deploy-manage/app-connections/create-oauth-client">documentation here</a>, or follow the steps below:</p><ol><li><p>Switch to the <a href="https://www.elastic.co/docs/deploy-manage/manage-spaces">Kibana space</a> whose agents and tools AgentCore should use. The client is tied to this space, and you can't change it later.</p></li><li><p>Go to <strong>Agents</strong> → <strong>Tools</strong> → <strong>Manage all tools</strong> → <strong>Manage MCP</strong> → <strong>Manage MCP Clients (OAuth)</strong> → <strong>Add MCP client</strong>.</p></li><li><p>Name your client (for example, <code>AgentCore Gateway</code>), and pick a logo.</p></li><li><p>Select <code>Remote</code> under the <strong>Redirect URI type</strong> section.</p></li><li><p>For now, fill in the <strong>Remote URL</strong> with any HTTPS URL, such as <code>https://example.com</code>. You’ll update it later.</p></li><li><p>Check the <strong>Generate confidential MCP client</strong> box, and store the generated secret safely.</p></li><li><p>Create a client.</p></li></ol><h2>Set up AgentCore Identity with your Elastic OAuth client</h2><p>Next, set up the AWS resources that the gateway depends on. If you don’t have an application to test with yet, the optional helper scripts below let you complete the authorization step locally.</p><h3>Create the AgentCore Identity OAuth client for Elastic</h3><p>1. Store the client secret (from Step 6, above) in <strong>AWS Secrets Manager</strong>. For example:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltdb6c1a390f67ce5b/6b0d098fda47c48559be0300/image24.png" alt="AWS Secrets Manager Choose secret type page with Other type of secret and a clientSecret key/value pair" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blta361125194f3b299/6b0d09b180e541db6647b9ba/image12.png" alt="AWS Secrets Manager storing the Elastic OAuth MCP client secret as elastic-serverless-project-mcp-client" /><p>2. In the <strong>Build</strong> tab, go to <strong>Amazon Bedrock AgentCore</strong> → <strong>Identity</strong>.</p><p>3. Create an <strong>Outbound Auth</strong> with an <strong>OAuth client</strong>:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltdb9a4ee78f162aae/6b0d09deafd7864b61b3dcb3/image7.png" alt="AgentCore Identity Outbound Auth panel with the Add OAuth client option open in the dropdown" /><p>4. Select <code>Customized provider</code> and <code>Manual config</code>.</p><p>5. Select <code>Client secret post</code> as your <strong>Client authentication method</strong>:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltf846b7636cf7d87e/6b0d0a312a5ecb2a153717a9/image2.png" alt="AgentCore Identity OAuth client setup with Customised provider, Manual config and Client secret post selected" /><p>6. To get the correct values for <strong>Issuer</strong>, <strong>Authorization endpoint</strong>, and <strong>Token endpoint</strong>, open a terminal and run the following:</p><p>a. Get the OAuth authorization server used by your project:</p>export KIBANA_URL="..." 
# Leave SPACE_PATH empty if you created the client in the default space.
# For any other space, set it to /s/&lt;space-id&gt;, e.g. /s/marketing
export SPACE_PATH="..."
curl -s "$KIBANA_URL/.well-known/oauth-protected-resource$SPACE_PATH/api/agent_builder/mcp" | jq<p>Example response:</p>{
  "authorization_servers": [
    "https://oauth.iam.eu-west-1.aws.svc.elastic.cloud/oauth2"
  ],
  "resource": "https://&lt;your-project&gt;.kb.&lt;region&gt;.aws.elastic.cloud/api/agent_builder/mcp"
}<p>b. Take the authorization server URL from the response, and insert <code>/.well-known/oauth-authorization-server</code> after the host:</p>curl -s "https://oauth.iam.eu-west-1.aws.svc.elastic.cloud/.well-known/oauth-authorization-server/oauth2" | jq<p>Example response:</p>{
  "issuer": "https://oauth.iam.eu-west-1.aws.svc.elastic.cloud/oauth2",
  "authorization_endpoint": "https://oauth.iam.eu-west-1.aws.svc.elastic.cloud/oauth2/authorize",
  "token_endpoint": "https://oauth.iam.eu-west-1.aws.svc.elastic.cloud/oauth2/token",
  "response_types_supported": [
    "code"
  ],
  "grant_types_supported": [
    "authorization_code",
    "refresh_token"
  ],
  "code_challenge_methods_supported": [
    "plain",
    "S256"
  ],
  "token_endpoint_auth_methods_supported": [
    "none",
    "client_secret_post"
  ],
  "scopes_supported": [
    "all"
  ],
  "client_id_metadata_document_supported": false
}<p>7. Add <code>code</code> as the <strong>response type.</strong></p><p>8. Copy the client ID from the AgentCore OAuth client that you created in the previous section, in your Serverless project:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt6c0f9b6b5d37235b/6b0d0ed14499b45d5c514759/image23.png" alt="Elastic MCP clients panel highlighting the Client ID for the AgentCore Gateway OAuth client" /><p>9. Link the client secret from your Secrets Manager.</p><p>10. Create a client.</p><p>11. Now, as promised, let’s update the Remote URL of the client that we created in the Serverless project. Copy the <strong>Callback URL</strong> from your newly created identity, and paste it as the <strong>Remote URL</strong> in your Elastic OAuth MCP client:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt682d2e57c19908b9/6b0d0ca32a5ecbab163717b4/image6.png" alt="AgentCore Identity provider details for oauth-client-elastic-cloud with the Callback URL to paste into Elastic" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltf68aae4468b3448e/6b0d0cc4da47c45962be0320/image9.png" alt="Elastic OAuth MCP client Redirect URI type set to Remote with the AgentCore Identity callback URL" /><h2>Test locally without an app or AgentCore runtime (optional)</h2><h3>Run a local HTTPS callback server for the OAuth redirect</h3><p>When creating a gateway target, you need to provide a Return URL. This is an endpoint in your app that the authorization page can redirect to, to complete the flow. AWS redirects here with a session ID. This endpoint must then call <code>CompleteResourceTokenAuth</code>, which checks that the user who started the session is the same user completing it. If you don’t already have this in your codebase, you can use <a href="https://gist.github.com/lorenabalan/ca8bae5cbf0f8d943add6af2a3c2fb10">this sample code</a> to stand up a small local server on <code>localhost:9090</code>. The server runs over HTTPS because Elastic doesn't accept plain HTTP redirect URIs, and Chrome blocks the consent redirect from reaching <code>http://localhost</code>.</p><p>Before you run the server, make sure that you:</p><p>1. Export AWS credentials that can complete the authorization and look up your gateway targets. The server calls these AgentCore actions:</p>{
   "Version": "2012-10-17",
   "Statement": [
     {
       "Effect": "Allow",
       "Action": [
         "bedrock-agentcore:CompleteResourceTokenAuth",
         "bedrock-agentcore:ListGateways",
         "bedrock-agentcore:ListGatewayTargets",
         "bedrock-agentcore:GetGatewayTarget"
       ],
       "Resource": "*"
     }
   ]
}# run this in AWS CloudShell and copy-paste the output into your terminal window
aws configure export-credentials --format env<p>2. Install the necessary dependencies:</p>python3 -m venv .venv
source .venv/bin/activate
pip install boto3 requests fastapi uvicorn bedrock-agentcore<p>3. Create self-signed certificates:</p>brew install mkcert
mkcert -install          # one-time: create and trust the local CA
mkdir -p certs
mkcert -cert-file certs/localhost.pem -key-file certs/localhost-key.pem localhost 127.0.0.1
# so that the test script trusts the certificate
export CALLBACK_CA_FILE="$(mkcert -CAROOT)/rootCA.pem"<p>Or via OpenSSL:</p>mkdir -p certs
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -days 365 \
  -keyout certs/localhost-key.pem \
  -out certs/localhost.pem \
  -subj "/CN=localhost" \
  -addext "subjectAltName=DNS:localhost,IP:127.0.0.1"<p>Click <strong>Advanced</strong> → <strong>Proceed to localhost</strong> when in Chrome.</p><p>Now run the server in your terminal window:</p>python oauth2_callback_server.py --region &lt;your-aws-region&gt;<h3>Run the test script against your gateway</h3><p>If you want to test the integration in a lightweight script, rather than directly in AWS, you can download <a href="https://gist.github.com/lorenabalan/ba52038b48a4b370f4a92ce5a4f4e9c0">this file</a> and run it on your local machine:</p># From the Cognito app client that AgentCore created for your gateway
export CLIENT_ID=...
export CLIENT_SECRET=...
# Get these from the Invocation Code on the Gateway page
export TOKEN_URL=...
export GATEWAY_URL=...
python gateway_elastic_test.py<img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt4a9cdce8f6f2252c/6b0d0dd2da47c42838be0324/image25.png" alt="Amazon Cognito app client for the AgentCore Gateway, showing a one hour access token expiration" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt7f5b9db731be7786/6b0d0dfc10f470525a14075d/image1.png" alt="Terminal output: AgentCore Gateway returns 22 Elastic MCP tools and lists dummy-data and visible-index-only-test" /><h2>Create an AgentCore Gateway with an MCP target</h2><p>Finally, we’re ready to create the integration point on the AgentCore side. There are two target options:</p><ul><li><p><strong>A default, </strong><a href="https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-target-MCPservers.html"><strong>aggregated MCP target</strong></a><strong>.</strong> On gateway creation, this caches the list of tools of the source MCP server and only refreshes it when explicitly synced or when the gateway is updated. Use this if your application triggers a sync regularly or based on events; otherwise, the cache has the potential to go stale.</p></li><li><p><strong>A </strong><a href="https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-target-http-passthrough.html"><strong>passthrough MCP target</strong></a><strong>.</strong> This sends a <code>tools/list</code> request to the source MCP server every time, so a revoked or expired authorization shows up sooner.</p></li></ul><p></p><p><strong>Aggregated (default)</strong></p><p><strong>Passthrough</strong></p><p>Tool list</p><p>Cached, refreshed when you sync the target</p><p>Fetched from Elastic on every <code>tools/list</code></p><p>MCP URL</p><p><code>&lt;gateway&gt;/mcp</code></p><p><code>&lt;gateway&gt;/&lt;target name&gt;/mcp</code>; remove <code>/mcp</code> from the MCP Endpoint</p><p>Where to send <code>forceAuthentication</code></p><p><code>tools/call</code></p><p><code>tools/list</code></p><p>A revoked token shows up</p><p>On the next tool call</p><p>On the next tool list</p><p>1. Create an AgentCore Gateway with MCP version <strong>2025-11-25</strong> enabled. This spec version adds <a href="https://modelcontextprotocol.io/specification/2025-11-25/client/elicitation">URL-mode elicitation</a> and is the latest version that the Agent Builder MCP server currently supports. (Leave all other default options in place in steps 1 and 2.)</p><p>2. Select <code>MCP target</code> as <strong>target protocol</strong> and <code>MCP server</code> as <strong>target type</strong>.</p><p>3. (Optional) Select <strong><code>passthrough - advanced</code></strong>, if you don’t want a cache of available tools that you need to manually refresh.</p><p>4. Copy the MCP server URL from the Elastic OAuth MCP client in your Serverless project, and paste it under <strong>MCP Endpoint</strong>.
Note: If you’re using a passthrough target, remove the <code>/mcp</code> suffix from the MCP server URL. AWS adds it by default.</p><p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltb2187ca71e8d8d99/6b0d0e81dae41d652bc78053/image19.png" alt="Elastic MCP clients panel showing the AgentCore Gateway client ID and the MCP server URL to copy" /></p><p>5. Make sure that <strong><code>OAuth client</code></strong> is selected as <strong>Outbound Auth configuration</strong> and, in the dropdown, pick the AgentCore OAuth client that you created earlier.</p><p>6. Under <strong>Additional configurations</strong>, select <a href="https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/gateway-using-auth-ex-3lo.html"><strong><code>Authorization code grant (3LO)</code></strong></a> under <strong>Auth grant type.</strong></p><p></p><p>7.For <strong>Return URL</strong>, add your app’s endpoint where you complete the authorization with the session ID sent by AWS. If you don’t have this yet, use the server provided in the previous section: <strong><code>https://localhost:9090/oauth2/callback</code></strong>.</p><p>8. Add the <code>all</code> scope.</p><p>9. Create a gateway:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltdef0df801756fbbe/6b0d113837cf44d049b9a222/image3.png" alt="AgentCore Gateway Review and create page showing gateway details, JWT inbound identity and the Elastic MCP target" /><p>10. Close any notification pop-ups at the top of the page, after you read them. For example:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt79a1d76857c312c8/6b0d11584474741fd900371d/image26.png" alt="AWS banners confirming the gateway was created and the Elastic MCP target requires authorisation" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt99c8acfbc8505e8a/6b0d1169e4fef326d1ff2108/image15.png" alt="AWS notification listing the Cognito user pool, domain, scope and app client created for the gateway" /><p>11. Authorize your target from the provided link, either from the notifications or from the <strong>Targets</strong> table:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt0199cf4050a3f8e0/6b0d11d7c5d779ad0eae2022/image17.png" alt="AgentCore Gateway target target-elastic-serverless-mcp showing Needs authorisation status at path /mcp" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt6a79de8d21a62b8a/6b0d11ea60c81cc6003f8b81/image5.png" alt="AgentCore Gateway Targets table with the Elastic MCP target unsynced and a Needs authorisation link" /><p>12. You should see a page similar to this one:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt98100e39b698b8a0/6b0d121837cf447ddbb9a226/image14.png" alt="Elastic consent screen where AgentCore Gateway requests access to the Agent Builder MCP server" /><p>13. If you used the local callback server for Return URL, you should see logs similar to the following:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt4c5efe1c92f017d3/6b0d124f9d4b52dd5949370a/200ok.png" alt="Local OAuth2 callback server logs on https://127.0.0.1:9090 completing the 3LO flow with a 200 OK" /><p>14. After completing the authorization, your target should show up in <code>Ready</code> status:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltbf4f75adfe44f9e1/6b0d1270907b6a148a135c02/ready.png" alt="AgentCore Gateway Targets table showing the Elastic MCP target in Ready status after authorisation" /><h2>Test per-user Elasticsearch permissions with Cognito users</h2><p>By default, creating the gateway also creates a user pool in <a href="https://aws.amazon.com/cognito/">Amazon Cognito</a>, an AWS service for user management and authorization/authentication. It holds the app client that your application uses to connect to the gateway, along with the users who can call the gateway directly.</p><p>1. Go to <strong>Amazon Cognito</strong> → <strong>User pools</strong>. Click on the auto-generated user pool. Open the <strong>Users</strong> page (under the <strong>User management</strong> tab), and add multiple users. You can think of each Cognito user as an Elastic user.</p><p>2. Update the app client. Go to <strong>Amazon Cognito</strong> → <strong>App clients</strong>. Click on the auto-generated app client. Then, turn on the <code>Sign in with username and password: ALLOW_USER_PASSWORD_AUTH</code> option.</p><p>3. Make your users’ passwords permanent by running the following in CloudShell:</p>aws cognito-idp admin-set-user-password --region eu-north-1 --user-pool-id &lt;user-pool-id&gt; --username alice --password &lt;password&gt; --permanent
aws cognito-idp admin-set-user-password --region eu-north-1 --user-pool-id &lt;user-pool-id&gt; --username bob --password &lt;password&gt; --permanent<p>4. Now run <code>COGNITO_USERNAME=bob COGNITO_PASSWORD=&lt;password&gt; python gateway_elastic_test.py</code>, and authorize as an Elastic user with a limited role.</p><p>For example, I used <code>bob</code> to log in as a separate, limited user, which I had attached to my Serverless project with a custom role. Here’s that role as returned by <code>GET _security/role/limited_role</code>:</p>{
  "limited_role": {
    "cluster": [],
    "indices": [
      {
        "names": [
          "visible-index-only-*"
        ],
        "privileges": [
          "read",
          "view_index_metadata"
        ],
        "field_security": {
          "grant": [
            "*"
          ],
          "except": []
        },
        "allow_restricted_indices": false
      }
    ],
    "applications": [
      {
        "application": "kibana-.kibana",
        "privileges": [
          "feature_agentBuilder.read"
        ],
        "resources": [
          "space:default"
        ]
      }
    ],
    "run_as": [],
    "metadata": {},
    "transient_metadata": {
      "enabled": true
    }
  }
}<p>The <code>applications</code> entry gives the role Read access to Agent Builder in the <code>default</code> space. If your MCP client lives in another space, change <code>space:default</code> to <code>space:&lt;your-space-id&gt;</code>.</p><p>To create a similar role from the Dev Tools console, send <code>PUT _security/role/limited_role</code> with the indices and applications sections as the request body. (See the <a href="https://www.elastic.co/docs/api/doc/elasticsearch-serverless/operation/operation-security-put-role">create or update roles API</a>.) You can also <a href="https://www.elastic.co/docs/deploy-manage/users-roles/serverless-custom-roles">create the role in the UI</a>.</p><p>When I call the test script as <code>bob</code> and authorize as the limited Elastic user, I see only the <code>visible-index-only-test</code> index, not <code>dummy-data</code>:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blta70ae48660d2d606/6b0d132e7b1d45398dc5acab/CallingTarget.png" alt="Terminal comparison: Cognito user bob lists only visible-index-only-test, while the other user also sees dummy-data" /><p>The gateway and tool remain the same, as does the OAuth MCP client. The only thing that changes is who's signed in: AgentCore Gateway calls your Agent Builder tools as that user, and Elastic returns what their role allows. The agent never has to know the difference.</p><p>You can also create multiple <em>client credentials</em> app clients in Cognito and add them to the gateway under <code>Inbound Auth configurations</code>. This is useful if, for example, you need multiple apps or agents to connect to your gateway.</p><h2>How to revoke a user's Elasticsearch access through AgentCore</h2><p>Revoking a user's connection to the OAuth MCP client removes their access through the agent, while their Elastic account and roles stay exactly as they are. For example, consider the contractor mentioned at the beginning of this post, who could only see a subset of what a permanent support engineer sees. Let's say that the contract wraps up and the contractor moves to a project in another part of the company. They'll still need Elasticsearch now and then, just not through the AgentCore agent anymore. Revoking their connection to the OAuth MCP client is all it takes, and everyone else using the agent carries on without noticing.</p><p>If you have the <a href="https://www.elastic.co/docs/deploy-manage/app-connections/revoke-oauth-client#revoke-oauth-client-before-you-begin">necessary admin permissions</a> on your Serverless project, you can manage connections to your various OAuth clients and <a href="https://www.elastic.co/docs/deploy-manage/app-connections/revoke-oauth-client">revoke them</a> from the settings panel:</p><ol><li><p>Go to your Serverless project, <strong>Admin and settings</strong> → <strong>Application Connections</strong>.</p></li><li><p>Select the client whose connections you want to revoke.</p></li><li><p>Revoke all connections.</p></li><li><p>(Optional) Alternatively, you can click on <strong><code>List View</code></strong> in the top-right corner and delete individual connections, rather than a whole grouping of them.</p></li></ol><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt626dd1f23a988a00/6b0d135f3893232a26ea30d3/image18.png" alt="Elastic Application connections page with one AgentCore Gateway connection selected for revoking" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt951f9581a8f968ff/6b0d13747b1d452139c5acaf/image13.png" alt="Elastic Revoke connection dialog for the AgentCore Gateway MCP client, noting the client stays registered" /><p>Revoking a connection takes effect immediately on the Elastic side. The next request that reaches your project with a revoked token is rejected, and you'll see responses like this:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltcee75d3d916b30a8/6b0d1398175b8e6df94aed36/McpException.png" alt="Revoked Elastic access: alice's AgentCore Gateway tool call fails with an MCP authorization error" /><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt85cc056d06e4e56f/6b0d13bc80e541389147b9e3/image11.png" alt="Passthrough MCP target returns HTTP 401 with a WWW-Authenticate header pointing to the Elastic OAuth resource" /><p>AgentCore Gateway doesn't start a new authorization when this happens. It keeps sending the stored access token until that token expires, so your agent's tool calls fail during that window (up to one hour). Once the token expires, the gateway asks the user to authorize again, and the authorization link is in the <code>WWW-Authenticate</code> header or the response body:</p><img src="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/bltc2dc633934bb12c9/6b0d13e72a5ecb0a0e371809/JVK.png" alt="AgentCore Gateway asks Cognito user bob to open an Elastic authorization URL before the tool call runs" /><p>If you want to immediately trigger a reauthorization instead of waiting for the token to expire, run the following:</p>FORCE_AUTHENTICATION=1 COGNITO_USERNAME=alice COGNITO_PASSWORD=&lt;password&gt; python gateway_elastic_test.py<p>This passes <code>forceAuthentication: true</code> in the request’s <code>_meta</code> . Under the hood, this ignores the old stored token and prompts for reauthorization. After you authorize, the script retries the request with the new token.</p><h2>AgentCore calls the tools; Elasticsearch decides who sees what</h2><p>We’ve completed the full chain. We saw how to set up an OAuth MCP client in Elastic and how to tie it to an AgentCore Identity. Plus, we saw how to use the two to connect an AgentCore Gateway to a Serverless project and query it over MCP.</p><p>Picture this setup a year from now: the support team has doubled, two contractors have come and gone, someone has moved from support over to finance. Yet your agent hasn't changed once. Everyone signs in to Elastic. They authorize the gateway and ask the same questions of the same tools, getting back only what their own role allows. When someone's job changes, you change their role. When they no longer need the agent, you revoke their connection.</p><p>Try it yourself, following the steps detailed above, and let us know your thoughts in <a href="https://www.elastic.co/community">our forums</a>. For more information on how OAuth works for the Elasticsearch MCP server, see <a href="https://www.elastic.co/search-labs/blog/elasticsearch-mcp-server-oauth-authentication">Elasticsearch MCP server OAuth authentication</a>.</p>]]></content:encoded>
    <link>https://www.elastic.co/search-labs/blog/amazon-bedrock-agentcore-elasticsearch-mcp-oauth</link>
    <guid isPermaLink="true">https://www.elastic.co/search-labs/blog/amazon-bedrock-agentcore-elasticsearch-mcp-oauth</guid>
    <category><![CDATA[Agentic AI]]></category>
    <category><![CDATA[Integrations]]></category>
    <category><![CDATA[Elastic Cloud Serverless]]></category>
    <dc:creator><![CDATA[Lorena Bălan]]></dc:creator>
    <enclosure url="https://static-www.elastic.co/v3/assets/bltefdd0b53724fa2ce/blt203fb21d7bed460e/6b0d081d4474742452003704/image22.png" length="0" type="image/png"/>
    <pubDate>Tue, 01 Dec 2026 15:30:00 GMT</pubDate>
  </item>
  </channel>
</rss>