Connect
pydantic-ai logo

Pydantic AI

Pydantic AI's MCPServerStreamableHTTP class wraps any remote MCP server with typed tool calls. Drop Dock into an Agent and you get fully-typed Dock tool invocations.

Client
Pydantic AI
Typed agent framework. First-class MCP client.
HTTP JSON-RPC (streamable-http)
Dock MCP
trydock.ai/api/mcp
37 tools · OAuth 2.1 + DCR · Bearer
Auth path
1
Mint a dk_ key in Dock Settings → API keys.
2
Paste it as Authorization: Bearer dk_… in the client config.
3
Client calls Dock MCP directly on every request.

Prerequisites

  • Python 3.10+.
  • pydantic-ai-slim[mcp] installed.
  • A Dock dk_ key.
agent.pypython
import os
from pydantic_ai import Agent
from pydantic_ai.mcp import MCPServerStreamableHTTP

dock = MCPServerStreamableHTTP(
    url="https://trydock.ai/api/mcp",
    headers={"Authorization": f"Bearer {os.environ['DOCK_API_KEY']}"},
)

agent = Agent(
    # any pydantic-ai model id, "anthropic:…", "openai:…", "google:…", etc.
    model_id,
    mcp_servers=[dock],
)

async with agent.run_mcp_servers():
    result = await agent.run("List my Dock workspaces.")
    print(result.data)

Troubleshooting

Symptom
Fix
Agent raises on tool schema validation
Pydantic AI validates tool schemas strictly. If Dock returns an extra field Pydantic doesn't expect, upgradepydantic-ai to the latest (schema handling relaxed mid-2025).

Frequently asked questions

How do I connect Dock to Pydantic AI?
Add Dock as a remote MCP server in Pydantic AI. Either let Pydantic AI's OAuth 2.1 + DCR flow handle auth (recommended; no credential ceremony), or paste a scoped Dock `dk_` API key in Pydantic AI's MCP config under the `Authorization: Bearer dk_…` header.
Does Pydantic AI work with Dock's MCP server?
Yes. Dock exposes 43 MCP tools at `https://trydock.ai/api/mcp` over HTTP transport with OAuth 2.1 + DCR and Bearer-token auth. Any MCP-spec-compliant client, including Pydantic AI, discovers them via the standard `tools/list` handshake. Learn more →
How do I limit which Dock workspaces Pydantic AI can write to?
When you mint the `dk_` key for Pydantic AI in Settings → API keys, pick the workspace from the dropdown. The key returns 403 on every other workspace regardless of what the prompt asks. To scope across multiple, mint multiple keys or add the agent as an explicit member of each. Learn more →
How do I see what Pydantic AI did in my Dock workspace?
Open the workspace in your browser. Every row Pydantic AI created or updated is stamped with the agent's identity (orb + name) in the createdBy / updatedBy field. The workspace activity feed shows every action chronologically. Learn more →
How do I undo a row Pydantic AI wrote to Dock?
Open the row, click the kebab menu, choose Delete (soft-delete preserves history). For bulk reverts use the activity feed to find the agent's session and delete its rows in batch. To prevent future writes, revoke Pydantic AI's `dk_` key in Settings → API keys.
Can multiple Pydantic AI sessions share state through Dock?
Yes. Every Pydantic AI session reads and writes the same workspace, so handoffs across machines or across long-running multi-session workflows just work. The Dock workspace IS the shared state; no separate message bus required.
Does Pydantic AI need OAuth or a dk_ API key for Dock?
Either works. OAuth 2.1 + DCR is the recommended path: Pydantic AI hits Dock's discovery endpoint at `/.well-known/oauth-authorization-server` and auto-registers as a client. The `dk_` Bearer token path is fine for owned-code agents and CI scripts; pick whichever fits your stack. Learn more →
How do I call Dock's MCP server from Pydantic AI?
Use Pydantic AI's MCP support: `mcp_servers=[MCPServerHTTP(url='https://trydock.ai/api/mcp', headers={'Authorization': 'Bearer dk_...'})]`. Pass to `Agent(model='claude-sonnet-4-5', mcp_servers=mcp_servers)`.
Can Pydantic AI's typed responses write structured rows to Dock?
Yes. Define a Pydantic model for your row shape, have the agent return an instance, then call Dock's `create_row` with the model dict. Type-safe end-to-end from prompt to Dock row.
How do I let Pydantic AI agents subscribe to Dock events?
Register a Dock webhook (POST `/api/webhooks` with the events you care about). Have your Pydantic AI agent's HTTP endpoint receive the webhook payload, validate the signature, and trigger the appropriate agent run.

Related

Updated