Integrating an AI Agent with ESS using MCP
This guide walks through connecting an AI agent or other application to the ESS MCP Service, which lets it request access to users' data and read that data through Model Context Protocol (MCP) tools.
Overview
A typical MCP client workflow is:
Obtain an ESS Access Token for the MCP Service from the Platform Management service.
Connect to the MCP Service with an MCP client, sending the token on every request.
Use the MCP tools to request access to a user's resources, wait for the user to approve, and then read the resources.
The token identifies an ESS agent. Every MCP tool acts as that agent: it can only see the Access Requests that agent created and the Access Grants issued to it.
Prerequisites
For the ESS operator
Before a developer can obtain a token for the MCP Service, an ESS operator must set up the following. Without it, token requests fail, for example with invalid_client.
An ESS 3.5.0 or later deployment with the MCP Service. Its base URL is
https://mcp.<ESS Domain>/api.For an AI agent:
The host of the agent's client ID on the domain allow list.
An active agent account bound to the client ID.
For an application acting for a signed-in user:
The user's Identity Provider trusted by ESS.
The user's Identity Provider identity mapped to their ESS account.
For the developer
An MCP client that supports MCP protocol revision
2026-07-28. The MCP Service refuses earlier revisions.For an AI agent: a Client ID Metadata Document published at an HTTPS URL, and the private key that signs the client assertion. See Step 1.
For an application acting for a signed-in user: a way to sign the user in with their Identity Provider and get their ID token. See Step 1.
Step 1: Get an ESS Access Token
An application can obtain a token in one of two ways. In both cases, request the token for the MCP Service by setting resource to its URL, and request the scopes for the tools the application needs.
AI agents: Client Credentials with CIMD
An AI agent that acts on its own behalf authenticates with a Client ID Metadata Document (CIMD) and the OAuth 2.0 client_credentials grant. Before it can obtain a token, an ESS operator must add the agent's host to the domain allow list and bind its client ID to an agent account. See Client Credentials with CIMD for how to publish the document and create the client assertion.
To request a token, send a client_credentials request to the Platform Management service's token endpoint. This example uses a signed client assertion as proof of the agent's identity:
Applications acting for a signed-in user: Token Exchange
An application acting for a user who signs in with your Identity Provider exchanges the user's token for an ESS Access Token. See Token Exchange.
To request a token, send a token exchange request to the Platform Management service's token endpoint. This example presents the user's ID token from your Identity Provider as the subject token:
A successful response contains the ESS Access Token in access_token, and its lifetime in seconds in expires_in.
Step 2: Connect to the MCP Service
Send the ESS Access Token in the Authorization header, and the MCP protocol revision in the Mcp-Protocol-Version header, of every request to the MCP Service:
The MCP Service supports only protocol revision 2026-07-28, over the Streamable HTTP transport. This revision is stateless: there is no initialize handshake or session, and every request is a POST to the base URL. An MCP client that supports this revision sends the Mcp-Protocol-Version header itself. If you build requests by hand, include it: a POST without the header, or with a different revision, is refused with 400.
An MCP client that follows the MCP authorization specification can also discover how to get a token: a request without a token is answered 401 with a challenge that points to the MCP Service's protected resource metadata.
Step 3: Use the MCP Tools
For each tool's parameters and responses, see the MCP Service reference.
Check for an existing Access Grant. Use
hasMatchingAccessGrantto check whether the user has already granted the agent access to the resource. SetdataSubjectto the identifier of the user who owns the resource. If so, go to step 4.Request access. Use
requestAccessto create an Access Request for the resource, withdataSubjectset to the same identifier. It returns the Access Request URL.Wait for approval. The user reviews the Access Request in a separate application; it cannot be approved through the MCP Service. Use
checkAccessRequestStatuswith the Access Request URL until its status changes frompendingtogranted,deniedorcanceled.Read the resource. Use
getResourcewith the resource URL. ESS checks that the agent can read the resource, for example through an Access Grant issued to it. The result is an MCP embedded resource: read the content fromresource.text, and its URL, content type and ETag fromresource.uri,resource.mimeTypeandresource._meta.etag.
For example, a successful getResource call returns:
Try It with MCP Inspector
To try the MCP tools without building a client, use a version of MCP Inspector that supports protocol revision 2026-07-28, such as 2.12.0.
MCP Inspector cannot obtain the ESS Access Token for you. Its built-in sign-in uses a browser authorization flow, which needs an authorization endpoint, and ESS has none. Get a token with the request in Step 1 and give it to MCP Inspector in a header.
Save the following configuration in an
mcp.jsonfile:Start MCP Inspector with this configuration, selecting the
modernprotocol era, which is the one that implements revision2026-07-28. The default era makes MCP Inspector send aninitializerequest, which the MCP Service does not implement:This lists the MCP Service's tools. To call a tool, use
--method tools/call --tool-name <tool> --tool-arg <name>=<value>.
Errors
401 response from the MCP Service
The token is missing, invalid or expired. Obtain a new token and retry.
403 response with an insufficient_scope challenge
The token lacks the scope the tool requires. Obtain a token that includes the scope named in the challenge, and retry.
invalid_client, invalid_scope or invalid_target from the token endpoint
The client could not authenticate, or requested a scope or resource it is not allowed. See Error Responses.
A tool returns an error
The tool could not complete, for example because the resource does not exist or the agent cannot read it. The error message explains why.
Best Practices
Request only the scopes you need. A client that only manages Access Requests does not need
mcp:storage:read.Check for existing Access Grants first to avoid creating duplicate Access Requests.
Give a clear purpose in Access Requests, to help users decide.
Poll with backoff while waiting for approval, because approval is done by a person.
Renew tokens before they expire. ESS Access Tokens are short-lived (5 minutes by default) and no refresh token is issued; use
expires_into request a new token in time.Use canonical resource URIs (the
/sc/form) for durable references.Keep tokens and keys secret. Never expose them in client-side code or logs.
Additional Resources
Last updated