Python SDK for Metorial - The open source integration platform for agentic AI
Project description
Metorial Python SDK
The official Python SDK for Metorial. Give your AI agents access to tools like Slack, GitHub, SAP, and hundreds more through MCP — without managing servers, auth flows, or infrastructure.
Sign up for a free account to get started.
Complete API Documentation
- Documentation - Documentation and guides
- API Reference - Complete API reference
Installation
pip install metorial
Supported LLM Integrations
This SDK formats MCP tools for each LLM provider. Pass the provider parameter to get tools in the right format.
| Provider | Format | Client Library | Models (non-exhaustive) |
|---|---|---|---|
| OpenAI | provider="openai" |
openai |
gpt-4.1, gpt-4o, o1, o3 |
| Anthropic | provider="anthropic" |
anthropic |
claude-sonnet-4-5, claude-opus-4 |
| Google Gemini | provider="google" |
google-generativeai |
gemini-2.5-pro, gemini-2.5-flash |
| Mistral | provider="mistral" |
mistralai |
mistral-large-latest, codestral-latest |
| DeepSeek | provider="deepseek" |
openai (compatible) |
deepseek-chat, deepseek-reasoner |
| Together AI | provider="togetherai" |
openai (compatible) |
Llama-4, Qwen-3 |
| xAI (Grok) | provider="xai" |
openai (compatible) |
grok-3, grok-3-mini |
Framework Integrations
For popular agent frameworks, we provide helper functions that convert tools to the framework's native format:
| Framework | Import | Example |
|---|---|---|
| AutoGen | from metorial.integrations.autogen import create_autogen_tools |
example |
| CrewAI | from metorial.integrations.crewai import create_crewai_tools |
example |
| Google ADK | from metorial.integrations.google_adk import create_google_adk_tools |
example |
| LlamaIndex | from metorial.integrations.llamaindex import create_llamaindex_tools |
example |
| PydanticAI | from metorial.integrations.pydantic_ai import create_pydantic_ai_tools |
example |
| LangChain | from metorial.integrations.langchain import create_langchain_tools |
example |
| LangGraph | from metorial.integrations.langgraph import create_langgraph_tools |
example |
| OpenAI Agents | from metorial.integrations.openai_agents import create_openai_agent_tools |
example |
| Haystack | from metorial.integrations.haystack import create_haystack_tools |
example |
Quick Start
This example uses PydanticAI with Anthropic Claude and Metorial Search, a built-in web search provider that requires no auth configuration. You just need two environment variables:
METORIAL_API_KEYfrom platform.metorial.comANTHROPIC_API_KEYfrom console.anthropic.com
pip install metorial pydantic-ai python-dotenv
For readability, the README snippets below use bare
await. In a normal.pyscript, wrap them inasync def main()and callasyncio.run(main()).
import os
from metorial import Metorial, metorial_pydantic_ai
from pydantic_ai import Agent
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_pydantic_ai(),
providers=[
{"provider_deployment_id": deployment.id},
],
)
agent = Agent(
"anthropic:claude-sonnet-4-20250514",
system_prompt="You are a helpful research assistant.",
tools=session.tools(),
)
result = await agent.run(
"Search the web for the latest news about AI agents and summarize the top 3 stories."
)
output = getattr(result, "data", None) or getattr(result, "output", str(result))
print(output)
See the full runnable example at
examples/pydantic-ai/.
Authenticating MCP Tool Providers
The Quick Start above used Metorial Search, which requires no authentication. Most providers — Slack, GitHub, SAP, and others — require credentials. Here are the options, from simplest to most flexible.
Key concepts:
- Provider — an MCP tool integration (e.g. Slack, GitHub, Metorial Search). Browse available providers at platform.metorial.com.
- Provider Deployment — an instance of a provider configured for your project. You can create deployments in the dashboard or programmatically via
metorial.provider_deployments.create(). - Auth Credentials — your OAuth app registration (client ID, client secret, scopes).
- Auth Config — an already-authenticated connection with a token, service account, or specific user via an OAuth flow.
Dashboard-Configured Deployments
Some providers (Exa, Tavily) use API keys configured entirely in the dashboard. Just pass the deployment ID — no auth code needed:
providers=[{"provider_deployment_id": "your-exa-deployment-id"}]
Pre-Created Auth Config
An auth config represents an already-authenticated connection to a provider — for example, a user who has completed the OAuth flow for Slack. Once created (via the dashboard or a setup session), reference it by ID:
providers=[
{
"provider_deployment_id": "your-slack-deployment-id",
"provider_auth_config_id": "your-auth-config-id",
}
]
Inline Credentials
Pass credentials directly without pre-creating them in the dashboard:
providers=[
{
"provider_deployment_id": "your-deployment-id",
"provider_auth_config": {
"provider_auth_method_id": "your-auth-method-id",
"credentials": {"access_token": "user-access-token"},
},
}
]
OAuth Flow
For services like Slack or GitHub where each end-user authenticates individually, use setup sessions to handle the OAuth flow:
import os
from metorial import Metorial, metorial_pydantic_ai
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
# 1. Create a setup session for the provider
setup_session = metorial.provider_deployments.setup_sessions.create(
provider_id="your-slack-provider-id",
provider_auth_method_id="oauth",
redirect_url="https://yourapp.com/oauth/callback",
)
# 2. Send the OAuth URL to your user
print(f"Authenticate here: {setup_session.url}")
# 3. Wait for the user to complete OAuth
completed = await metorial.wait_for_setup_session([setup_session])
# 4. Use the auth config in a connected session
session = await metorial.connect(
adapter=metorial_pydantic_ai(),
providers=[
{
"provider_deployment_id": "your-slack-deployment-id",
"provider_auth_config_id": completed[0].auth_config.id,
}
],
)
tools = session.tools()
# Use tools...
Multiple Providers in One Session
Combine providers freely in a single session — each can use a different auth method:
# Create a deployment for Metorial Search
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
providers=[
# Metorial Search (no auth needed)
{"provider_deployment_id": deployment.id},
# Dashboard-configured deployment
{"provider_deployment_id": "your-slack-deployment-id", "provider_auth_config_id": "slack-auth-config-id"},
# Inline credentials
{
"provider_deployment_id": "your-github-deployment-id",
"provider_auth_config": {
"provider_auth_method_id": "github-auth-method-id",
"credentials": {"access_token": "ghp_..."},
},
},
]
Session Templates
Pre-configure provider combinations on the dashboard, then reference them by ID. This is useful when you want to manage which providers and auth configs are used without changing code:
from metorial import metorial_pydantic_ai
# Reference a session template by ID
session = await metorial.connect(
adapter=metorial_pydantic_ai(),
providers=[
{"session_template_id": "your-template-id"},
],
)
tools = session.tools()
# All providers from the template are available
# You can also mix session templates with explicit provider deployments
# in the same providers list
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_pydantic_ai(),
providers=[
{"session_template_id": "your-template-id"},
{"provider_deployment_id": deployment.id},
],
)
Enterprise: Bring Your Own (BYO) Credentials
For enterprise deployments, you have flexible options:
- Shared deployment: Deploy once and share with all users (works well for API key-based tools like Exa, Tavily)
- BYO OAuth: For services like SAP, enterprises can register their own OAuth app credentials:
credentials = await metorial.provider_deployments.auth_credentials.create(
provider_id="your-sap-provider-id",
name="Our SAP OAuth App",
config={
"client_id": "your-client-id",
"client_secret": "your-client-secret",
"scopes": ["read", "write"],
},
)
- Dynamic deployments: Create provider deployments programmatically via the Provider Deployment API.
Session Options
- Recommended entry point: Use
metorial.connect(adapter=..., providers=[...])for new code. It matches the Node SDK and does not require manual close calls. - Compatibility wrapper:
provider_session(...)still exists when you want the older provider-specific session helpers inside anasync with, but it is now just a thin wrapper over the same adapter/session resolution path used byconnect(). - Multiple providers: Pass multiple entries in the
providerslist to combine tools from different MCP servers.
Examples
Check out the examples/ directory for complete working examples:
| Example | Framework | Description |
|---|---|---|
autogen |
AutoGen + OpenAI | AutoGen assistant with tool calls |
crewai |
CrewAI + OpenAI | CrewAI agent with Metorial tools |
google-adk |
Google ADK + Gemini | Google ADK agent with async tool calls |
pydantic-ai |
PydanticAI + Anthropic | PydanticAI agent with tool calls |
langchain |
LangChain + Anthropic | LangChain agent with react pattern |
langgraph |
LangGraph + Anthropic | LangGraph streaming agent |
llamaindex |
LlamaIndex + OpenAI | FunctionAgent with tool calls |
openai-agents |
OpenAI Agents SDK | OpenAI Agents with tool calls |
haystack |
Haystack + OpenAI | Haystack pipeline with tools |
Provider Examples
These examples use connect() directly when you want provider-native tool formats rather than a framework adapter.
OpenAI
import os
from openai import AsyncOpenAI
from metorial import Metorial, metorial_openai
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
openai = AsyncOpenAI(api_key=os.environ["OPENAI_API_KEY"])
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_openai(),
providers=[{"provider_deployment_id": deployment.id}],
)
messages = [{"role": "user", "content": "Search the web for the latest news about AI agents."}]
response = await openai.chat.completions.create(
model="gpt-4o",
messages=messages,
tools=session.tools(),
)
if response.choices[0].message.tool_calls:
results = await session.call_tools(response.choices[0].message.tool_calls)
# Add results to messages and continue conversation...
Anthropic
import os
from anthropic import AsyncAnthropic
from metorial import Metorial, metorial_anthropic
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
anthropic = AsyncAnthropic(api_key=os.environ["ANTHROPIC_API_KEY"])
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_anthropic(),
providers=[{"provider_deployment_id": deployment.id}],
)
response = await anthropic.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1024,
tools=session.tools(),
messages=[{"role": "user", "content": "Search the web for the latest news about AI agents."}],
)
if response.stop_reason == "tool_use":
tool_calls = [b for b in response.content if b.type == "tool_use"]
results = await session.call_tools(tool_calls)
# Add results to messages and continue conversation...
Google Gemini
import os
import google.generativeai as genai
from metorial import Metorial, metorial_google
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
genai.configure(api_key=os.environ["GOOGLE_API_KEY"])
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_google(),
providers=[{"provider_deployment_id": deployment.id}],
)
model = genai.GenerativeModel("gemini-2.5-pro", tools=session.tools())
chat = model.start_chat()
response = chat.send_message("Search the web for the latest news about AI agents.")
for part in response.parts:
if fn := part.function_call:
result = await session.call_tool(fn.name, dict(fn.args))
# Continue conversation with result...
Mistral
import os
from mistralai import Mistral
from metorial import Metorial, metorial_mistral
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
mistral = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_mistral(),
providers=[{"provider_deployment_id": deployment.id}],
)
response = await mistral.chat.complete_async(
model="mistral-large-latest",
tools=session.tools(),
messages=[{"role": "user", "content": "Search the web for the latest news about AI agents."}],
)
if response.choices[0].message.tool_calls:
results = await session.call_tools(response.choices[0].message.tool_calls)
# Add results to messages and continue conversation...
OpenAI-compatible Models (DeepSeek, Together, xAI)
import os
from openai import AsyncOpenAI
from metorial import Metorial, metorial_openai_compatible
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
xai_compatible = AsyncOpenAI(
api_key=os.environ["OPENAI_COMPATIBLE_API_KEY"],
base_url="https://your-openai-compatible-endpoint/v1",
)
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_openai_compatible(),
providers=[{"provider_deployment_id": deployment.id}],
)
response = await xai_compatible.chat.completions.create(
model="your-model-name",
tools=session.tools(),
messages=[{"role": "user", "content": "Search the web for the latest news about AI agents."}],
)
if response.choices[0].message.tool_calls:
results = await session.call_tools(response.choices[0].message.tool_calls)
# Add results to messages and continue conversation...
Framework Integration Examples
LangChain / LangGraph
import os
from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent
from metorial import Metorial, metorial_langchain
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_langchain(),
providers=[{"provider_deployment_id": deployment.id}],
)
llm = ChatAnthropic(model="claude-sonnet-4-20250514")
agent = create_react_agent(llm, session.tools())
result = await agent.ainvoke(
{"messages": [("user", "Search the web for the latest news about AI agents and summarize the top 3 stories.")]}
)
print(result["messages"][-1].content)
PydanticAI
import os
from pydantic_ai import Agent
from metorial import Metorial, metorial_pydantic_ai
metorial = Metorial(api_key=os.environ["METORIAL_API_KEY"])
deployment = metorial.provider_deployments.create(
name="Metorial Search",
provider_id="metorial-search",
)
session = await metorial.connect(
adapter=metorial_pydantic_ai(),
providers=[{"provider_deployment_id": deployment.id}],
)
agent = Agent("anthropic:claude-sonnet-4-20250514", tools=session.tools())
result = await agent.run(
"Search the web for the latest news about AI agents and summarize the top 3 stories."
)
print(result.output)
Error Handling
from metorial import (
Metorial,
AuthenticationError,
NotFoundError,
RateLimitError,
OAuthRequiredError,
metorial_openai,
)
metorial = Metorial()
try:
session = await metorial.connect(
adapter=metorial_openai(),
providers=[{"provider_deployment_id": "your-deployment-id"}],
)
tools = session.tools()
except AuthenticationError:
print("Check your METORIAL_API_KEY")
except NotFoundError:
print("Deployment not found - verify your deployment ID")
except OAuthRequiredError:
print("This provider requires OAuth - see the OAuth section above")
except RateLimitError:
print("Rate limited - try again later")
License
MIT License - see LICENSE for details.
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file metorial-2.3.2.tar.gz.
File metadata
- Download URL: metorial-2.3.2.tar.gz
- Upload date:
- Size: 1.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d1d8bf470e0b24b4b3de64e64c71f26996927a84db9c11eee19078965fcf42b
|
|
| MD5 |
42a5832a0f23723e4cad17ae1e05e7d1
|
|
| BLAKE2b-256 |
63d83c51243ac6a5f29d1ec1df445e9cfd58f0f8656ceedae2acffa706e4309c
|
Provenance
The following attestation bundles were made for metorial-2.3.2.tar.gz:
Publisher:
release.yml on metorial/metorial-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metorial-2.3.2.tar.gz -
Subject digest:
5d1d8bf470e0b24b4b3de64e64c71f26996927a84db9c11eee19078965fcf42b - Sigstore transparency entry: 1206375810
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@9086df9d33a745286c2838e89336193531fea4c4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/metorial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9086df9d33a745286c2838e89336193531fea4c4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file metorial-2.3.2-py3-none-any.whl.
File metadata
- Download URL: metorial-2.3.2-py3-none-any.whl
- Upload date:
- Size: 4.7 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e45395b6e370e01da267e346af0e50cd6a0601fe3f698e4317d2ccf5d6dc151d
|
|
| MD5 |
720a515ac0aa6b7ac007d17c37f4d742
|
|
| BLAKE2b-256 |
840d279ed15b44a81375a88912af3a3f9d6af5c73df315184bc4f52034bf1665
|
Provenance
The following attestation bundles were made for metorial-2.3.2-py3-none-any.whl:
Publisher:
release.yml on metorial/metorial-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
metorial-2.3.2-py3-none-any.whl -
Subject digest:
e45395b6e370e01da267e346af0e50cd6a0601fe3f698e4317d2ccf5d6dc151d - Sigstore transparency entry: 1206375831
- Sigstore integration time:
-
Permalink:
metorial/metorial-python@9086df9d33a745286c2838e89336193531fea4c4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/metorial
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9086df9d33a745286c2838e89336193531fea4c4 -
Trigger Event:
workflow_dispatch
-
Statement type: