This sample shows how to connect an AI agent to the Predactiv MCP server using Anthropic Claude directly.
Unlike a client-side agent loop, this sample uses Claude's native MCP connector: the MCP
server definition is handed to the Messages API, and Anthropic's infrastructure connects to
the server, discovers its tools, and runs the tool-calling loop server-side. Your code makes
a single messages.create call and reads back the final answer.
Contrast with the
mcp-sdk/sample, which uses the raw MCP Python SDK and runs the tool-calling loop client-side. Here, Anthropic owns the connection and the loop.
- Authenticate —
oauth_token_lib.get_bearer_token()performs the Predactiv OAuth2 client-credentials exchange and returns a bearer token, passed to the MCP server asauthorization_token. - Connect & discover tools — the
mcp_serversparameter declares the Predactiv server (type,name,url,authorization_token). The matchingmcp_toolsetentry intools(linked bymcp_server_name) enables those tools for the model. - Run the agent — Claude connects to the MCP server, lists its tools, calls them as
needed, and returns a final response. The
mcp-client-2025-11-20beta flag enables the connector.
The Predactiv MCP tools expose the data platform: audiences, datasets, datasources,
destinations, filters/predictors, and insights (predactiv_* tool families).
- Python 3.9+
- A Predactiv account with API credentials (
CLIENT_IDandCLIENT_SECRET). Contact Predactiv if you don't have these. - An Anthropic API key — this sample uses
claude-haiku-4-5as the agent's LLM. Set it as theANTHROPIC_API_KEYenvironment variable.
Two separate credentials.
ANTHROPIC_API_KEYauthenticates your calls to Claude.CLIENT_ID/CLIENT_SECRETauthenticate to the Predactiv MCP server viaoauth_token_lib. Both must be set.
From this claude/ directory:
# (recommended) create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # on Windows: .venv\Scripts\activate
# install dependencies (also installs the shared oauth-token-lib package)
pip install -r requirements.txtSet the following environment variables:
export CLIENT_ID=your-predactiv-client-id
export CLIENT_SECRET=your-predactiv-client-secret
export ANTHROPIC_API_KEY=your-anthropic-api-keypython agent.pyThe sample's default goal is:
Get list of my audiences from the Predactiv MCP server and return it to me.
Edit the GOAL constant in agent.py to ask the agent to do something else with
your Predactiv data. The model is set in the messages.create call (model="claude-haiku-4-5")
— swap it for a more capable model (e.g. claude-sonnet-4-6, claude-opus-4-8) if your task
needs it.
CLIENT_ID and CLIENT_SECRET environment variables must be set.— Export both variables (see Configuration) before running.401 Unauthorizedfrom the MCP server — Your credentials are invalid or expired. Verify them, or runpython ../oauth-token-lib/oauth_token_lib.pyto confirm a token can be obtained.429 rate_limit_errorfrom Anthropic — The MCP connector injects the server's full tool catalog into each request as input tokens, so a single call can be large. If you hit a429, wait ~60 seconds between runs, use a model with more headroom, or request an increase at https://console.anthropic.com/settings/limits.AttributeErrorreading the response —response.contentis a mixed list of blocks (MCP tool-use, tool-result, and text). The sample joins only thetextblocks to build the final answer — don't assumecontent[0]is text.- Anthropic authentication errors — Make sure
ANTHROPIC_API_KEYis set and valid.
- Predactiv MCP server:
https://mcp.predactiv.com - Anthropic MCP connector: https://docs.claude.com/en/docs/agents-and-tools/mcp-connector
- Model Context Protocol: https://modelcontextprotocol.io