This sample shows how to connect an AI agent to the Predactiv MCP server using OpenAI and its Responses API.
Unlike a client-side agent loop, this sample uses OpenAI's native MCP connector: the
MCP server definition is handed to the Responses API, and OpenAI's infrastructure connects
to the server, discovers its tools, and runs the tool-calling loop server-side. Your code
makes a single responses.create call and reads back the final answer.
- Authenticate —
oauth_token_lib.get_bearer_token()exchanges yourCLIENT_IDandCLIENT_SECRETfor an OAuth2 bearer token (client-credentials flow). - Connect & discover tools — the request declares the Predactiv server as an
mcptool (server_label,server_url,authorization). OpenAI connects to the server and discovers its tools dynamically. No tools are hardcoded. - Run the agent — GPT connects to the MCP server, calls its tools as needed, and
returns a final response.
require_approval: "never"lets the model call the tools without a manual approval round-trip.
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 OpenAI API key — this sample uses
gpt-5.4-minias the agent's LLM. Set it as theOPENAI_API_KEYenvironment variable.
Two separate credentials.
OPENAI_API_KEYauthenticates your calls to OpenAI.CLIENT_ID/CLIENT_SECRETauthenticate to the Predactiv MCP server viaoauth_token_lib. Both must be set.
From this openai/ 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. The model is set in the responses.create call
(model="gpt-5.4-mini") — swap it for any model your key can access.
Responses.create() got an unexpected keyword argument 'messages'— The Responses API usesinput, notmessages(that's the Chat Completions API). Passinput=GOAL.401 Unauthorizedfrom the MCP server — Theauthorizationfield expects the raw access token; OpenAI adds theAuthorization: Bearer …header itself. Don't prefix the token withBearer(a double prefix causes a 401). If it persists, verify your credentials withpython ../oauth-token-lib/oauth_token_lib.py.output_textis empty — The model likely stopped on anmcp_approval_requestwithout calling the tool. Setrequire_approval: "never"on the MCP tool. The sample also dumpsresponse.outputitems when there's no text, so you can see what came back.- OpenAI authentication errors — Make sure
OPENAI_API_KEYis set and valid.
- Predactiv MCP server:
https://mcp.predactiv.com - OpenAI Responses API: https://platform.openai.com/docs/api-reference/responses
- Model Context Protocol: https://modelcontextprotocol.io