How to Configure Pydantic AI CockroachDB MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a pydantic ai cockroachdb mcp server by linking your agent to a database client. Next, you pass database login credentials and expose query tools to the model. Engineering teams often start by giving the agent a broad admin role during testing. That shortcut lets the model read or change any table in the cluster. If an agent makes a mistake, broad roles allow bad queries to run right away. How a pydantic ai cockroachdb mcp server works Pydantic AI gives developers a structured fram

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a pydantic ai cockroachdb mcp server by linking your agent to a database client. Next, you pass database login credentials and expose query tools to the model. Engineering teams often start by giving the agent a broad admin role during testing. That shortcut lets the model read or change any table in the cluster. If an agent makes a mistake, broad roles allow bad queries to run right away.

How a pydantic ai cockroachdb mcp server works

Pydantic AI gives developers a structured framework to build type-safe agents in Python. The Model Context Protocol, or MCP, offers a standard way to link tools to models. When you pair them, the MCP server acts as a bridge to CockroachDB. Your agent sends a structured tool call to the MCP server over standard streams. The server translates that request into a database query and runs it against your cluster.

To make this work, you first create a dedicated SQL user inside CockroachDB. You assign a specific role to this user that defines its table privileges. Next, you store the database host details and login keys where the server can read them. You then register the MCP server as a tool source inside your Pydantic AI agent. When a user prompts the app, the model inspects the database schema and runs queries.

What native roles solve and what they miss

Native CockroachDB roles help you restrict which tables the MCP server can touch. You can grant read-only permissions on specific schemas and block access to billing tables. You can also require TLS certificates so the server logs in over an encrypted link. These native controls decide who can log in and which objects they can reach.

Still, static database roles cannot check what individual queries do while they run. Once the MCP server logs in, the database trusts every command from that session. A read-only role still lets an agent pull millions of rows in one big query. It also lets the model read raw emails, phone numbers, or card numbers from tables. If a prompt tricks the agent, a write role allows drops or updates without human approval.

Kubernetes API Server Access + AI Agent Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing agent database permissions in production

Running AI agents against live databases requires more than a static login key. Teams need to know which user or agent triggered a specific SQL statement. When ten agents share one MCP server login, database logs only show that single shared account. You lose the trail of who asked the question that caused a slow query.

You also need a way to filter sensitive columns before results reach the language model. Data masking rewrites matched fields like national IDs or card numbers in query results. This keeps private customer data out of model prompts and third-party logs. Adding query review and field masking turns a risky agent setup into a safe workflow.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

How does Pydantic AI talk to the CockroachDB MCP server?

Pydantic AI connects to the MCP server using standard input and output or HTTP streams. The agent reads the tool definitions and sends structured requests when it needs database data.

Should my agent use an admin role for CockroachDB?

No, you should never give an AI agent an admin role in your database. Create a narrow role with only the exact read or write grants the agent needs.

How can I protect private data when agents query tables?

Database roles only block whole tables, so they cannot hide specific fields inside allowed rows. You need dynamic data masking to rewrite emails, phone numbers, and card numbers in results.

The query runs. The emails stay hidden.