Skip to main content

Pydantic AI

Connect UNIZO MCP to Pydantic AI with built-in MCP server support.

Overview

Pydantic AI includes native MCP integration via the mcp_servers parameter, enabling seamless connection to UNIZO MCP server.

Prerequisites

Before setting up the MCP integration, you'll need:

  • Unizo API Key: Used for authentication (found in the Unizo Console)
  • Python 3.10+: Required for Pydantic AI
  • OpenAI API Key: For the underlying LLM

Installation

uv add pydantic-ai python-dotenv openai

Or using pip:

pip install pydantic-ai python-dotenv openai

Authentication

Step 1: Generate a Service Key

Use your Unizo API key to generate a service key for MCP authentication:

curl --location 'https://api.unizo.ai/api/v1/serviceKeys' \
--header "apiKey: {unizo_api_key}" \
--header "Content-Type: application/json" \
--data '{
"name": "MCP Ticketing Integration",
"subOrganization": {
"name": "{YOUR_CUSTOMER_NAME}",
"externalKey": "{YOUR_CUSTOMER_UNIQUE_IDENTIFIER}"
},
"integration": {
"target": {
"categorySelectors": [
{
"type": "TICKETING"
}
]
}
}
}'

Required Parameters:

ParameterDescription
apiKeyYour Unizo API key (found in the Unizo Console)
nameDescriptive name for the integration (e.g., "MCP Ticketing Integration")
subOrganization.nameYour organization name (e.g., "Acme Inc")
subOrganization.externalKeyUnique identifier (UUID format recommended)

Response:

{
"state": "ACTIVE",
"displayId": "{UNIZO_SERVICE_KEY}",
...
}

Important: Save the displayId from the response — this is your service key for authenticating with the MCP server.

Step 2: Configure Environment Variables

Create a .env file in your project root:

UNIZO_SERVICE_KEY=your_service_key_from_displayId
OPENAI_API_KEY=your_openai_api_key

Quick Start

Connect to UNIZO MCP and create an agent:

import os
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStreamableHTTP
from dotenv import load_dotenv

load_dotenv()

# Create agent with Unizo MCP server
agent = Agent(
model="openai:gpt-4",
mcp_servers=[
MCPServerStreamableHTTP(
url="https://api.unizo.ai/mcp",
headers={
"servicekey": os.getenv('UNIZO_SERVICE_KEY'),
"x-mcp-scopes": "ticketing" # check for other category scopes
}
)
]
)

# Query the agent
result = agent.run_sync("List ticketing integrations for {connector_name}")
print(result.data)

Headers:

  • servicekey: Your Unizo service key (from the authentication step)
  • x-mcp-scopes: Comma-separated scopes (ticketing, vms, or both)