Metadata-Version: 2.5
Name: ory-pydantic-ai
Version: 1.10.1
Summary: Ory Agent Security for Pydantic AI — per-tool authorization, activity logging, and identity propagation via a WrapperToolset. Built on ory-argus.
Author: Ory
License-Expression: Apache-2.0
Keywords: agent,ai,authorization,ory,permissions,pydantic-ai
Requires-Python: >=3.10
Requires-Dist: ory-argus<2,>=1
Requires-Dist: pydantic-ai-slim>=0.0.40
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# ory-pydantic-ai

Ory Agent Security for [Pydantic AI](https://ai.pydantic.dev).

Wraps any toolset in an Ory-gating `WrapperToolset` so every tool call is authorized
against Ory Permissions, audited, and tied to the user → agent identity — built on
[`ory-argus`](https://pypi.org/project/ory-argus/).

```bash
pip install ory-pydantic-ai
```

```python
from pydantic_ai import Agent
from ory_pydantic_ai import wrap_toolset

agent = Agent(model, toolsets=[wrap_toolset(my_toolset)])
```

In **enforce** mode a denied tool never runs and the model receives the denial as a failed tool
result: pydantic-ai's `ToolFailed` where available (it does not consume the tool's retry
budget, so repeated denies never end the run), otherwise the denial text as the tool result. In **observe**
mode (default) the tool runs and a `permission.observe_deny` activity event is recorded.

## MCP servers

Tools from an MCP server toolset — `MCPToolset` (or the `MCPServer*` classes of older
releases), directly or behind `.prefixed()` / `.renamed()` — are checked as
`McpServer:<server>` and `McpTool:<server>:<tool>` instead of plain tools:

```python
from pydantic_ai.mcp import MCPToolset, load_mcp_toolsets

github = MCPToolset("https://api.githubcopilot.com/mcp/", id="github")
agent = Agent(model, toolsets=[wrap_toolset(github), *map(wrap_toolset, load_mcp_toolsets("mcp.json"))])
```

The guard walks from each called tool to the server toolset that listed it. It reports the
server as the `.prefixed()` prefix closest to the server, else the toolset `id`, else the
server-reported `server_info.name` (else a legacy `tool_prefix`), and the server's raw tool name
with prefixes and renames undone. It also sends hashed fingerprints of the server's URL host or
launched package, so Agent Security matches the server to its catalog whatever it is named;
launch arguments and URLs themselves are not sent. Give servers an `id` or a prefix so the
reported name is meaningful. Wrap each MCP toolset (or a toolset containing it) once; tools from
other toolsets keep their native checks.

Credentials come from the shared `~/.config/ory-agent-plugins/config.json`.
