This sample shows how to connect an AI agent to the Predactiv MCP server using
LangChain and
langchain-mcp-adapters.
The agent authenticates to Predactiv, discovers the available tools from the MCP server at runtime, and lets a large language model call those tools to work with your Predactiv data platform (audiences, datasets, datasources, destinations, and more).
- Authenticate —
oauth_token_lib.auth_headers()exchanges yourCLIENT_IDandCLIENT_SECRETfor an OAuth2 bearer token (client-credentials flow) and returns theAuthorizationheader. - Connect & discover tools —
MultiServerMCPClientconnects to the Predactiv MCP server over HTTP and fetches its tools dynamically. No tools are hardcoded, so your agent always sees the latest set the server exposes. - Run the agent — the MCP tools are bound to an LLM via
create_agent, and the agent is invoked with a natural-language goal.
- Python 3.9+
- A Predactiv account with API credentials (
CLIENT_IDandCLIENT_SECRET). Contact Predactiv if you don't have these. - An OpenAI API key — this sample uses
gpt-5.4-minias the agent's LLM. Set it as theOPENAI_API_KEYenvironment variable.
OpenAI is just the demonstration LLM — not a requirement. This sample is model-agnostic: LangChain works with any chat model that supports tool calling. To use a different LLM, swap the
ChatOpenAI(...)client for another LangChain chat model (e.g.ChatAnthropic), install its integration package, set that provider's API key, and update theOPENAI_MODELconstant at the top ofagent.py. The Predactiv MCP side is unchanged.
From this langchain/ 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 OPENAI_API_KEY=your-openai-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.
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.- OpenAI authentication errors — Make sure
OPENAI_API_KEYis set and valid.
- Predactiv MCP server:
https://mcp.predactiv.com - Model Context Protocol: https://modelcontextprotocol.io