Add Metorial tools to an OpenAI Agents SDK agent
Pass session.tools() from the metorial_openai_agents adapter to an Agent in Python, or point MCPServerStreamableHttp at a Metorial session URL in TypeScript.
This guide takes you from an empty folder to an OpenAI Agents SDK agent that searches the web through Metorial. In Python you pass session.tools() from the metorial_openai_agents adapter to Agent. In TypeScript you point the SDK's MCPServerStreamableHttp at a Metorial session URL.
What you'll learn
- How to create an API key and a provider deployment from the CLI
- How to give the agent Metorial tools in Python and TypeScript
- How to see the tool calls the agent made
Before you start
- Install the CLI and sign in
- An OpenAI API key
- Python 3.10 or later, or Node.js
Set up Metorial with the CLI
Find your instance
An instance is one environment of a project. List yours and note the ID of the one the agent should use:
Create an API key
Copy the secret from the output. It starts with metorial_sk_ and is shown only once.
Deploy a provider
Metorial Search is a built-in web search provider that needs no credentials.
Copy the deployment ID from the output. It starts with pde_.
Export the values
Build the agent
Create the project
Write the agent
Save this as agent.py or agent.ts. The Python SDK has an adapter for the Agents SDK. The TypeScript SDK does not, so the TypeScript version creates a session and connects the Agents SDK's own MCP client to it.
Run it
Check it worked
The first line lists the tools, then the agent prints its summary. Metorial prefixes each tool with the provider name and adds metorial_connection_status, a diagnostic tool, to every session.
List the tool calls Metorial recorded for the deployment:
Use other apps and each user's own account
Find a provider and deploy it the same way, then add its deployment ID to providers. One session can hold several.
Apps such as Slack need a sign-in. Pass the user's provider auth config next to the deployment ID, as provider_auth_config_id in Python and providerAuthConfigId in TypeScript. Let each user connect their own account shows how to get one for each user.
Troubleshooting
Invalid API key status=401
The Python SDK raises this AuthenticationError when the key is wrong. In TypeScript the message is [METORIAL ERROR]: unauthorized - Invalid API key. Check that METORIAL_API_KEY holds the full secret and belongs to the instance where you created the deployment.
ValueError: api_key is required
METORIAL_API_KEY is empty in the shell that runs the script.
ImportError: openai-agents is required for OpenAI Agents SDK integration. Install it with: pip install openai-agents
The adapter could not import the agents package. Install openai-agents in the same virtual environment as metorial.
Provider requires an auth config to be provided
A provider deployment in the session needs a sign-in and got no provider auth config. Add the user's provider_auth_config_id to that entry.
Next steps
- Let each user connect their own account: per-user OAuth for Slack, Gmail, GitHub and other apps
- Limit the tools an agent can use: serve only some of a provider's tools
- Connect any MCP client: the session URL and headers the TypeScript sample uses
- The official Python example:
metorial-admin example create metorial-openai-agents-sdk