# MCP vs. CLI: How an AI Agent Should Reach Your Database

> Compare direct database CLI access with a governed MCP server across six dimensions: setup, reach, identity, governance, auditability, and workflow fit.

Tianzhou | 2026-07-27 | Source: https://www.bytebase.com/blog/mcp-vs-cli/

---

An AI agent can reach a database in two common ways. It can run SQL through a CLI such as psql or mysql, or it can call tools exposed by an MCP server.

This post compares direct CLI access with a governed MCP server. That distinction matters: MCP is a protocol, not a security layer. Identity, masking, approval, and audit come from the system behind the server. A CLI can also use the access controls built into the database.

Here are six dimensions to consider.

## Setup and Operational Cost

The CLI is simpler. Install the client, provide a connection string, and the agent can connect. There is no extra service to run.

The hidden cost is credential distribution. Every environment that runs the agent needs a database credential. Each credential must be stored, rotated, and eventually revoked.

An MCP server adds another process. A desktop client can start a local server when needed, and formats such as [MCP Bundles](https://github.com/modelcontextprotocol/mcpb) make local installation easier. A local server still needs a database credential, just like the CLI.

A shared server takes more work to deploy and operate, but it keeps the database credential in one place. Agents authenticate to the server instead of carrying database credentials themselves.

For local work, the CLI usually wins on setup. For production, the shared server may be worth running.

## Reach and Expressiveness

A CLI gives the agent the full SQL interface. It can run anything its database role allows, but it must inspect the schema and write the SQL correctly.

An MCP server exposes named tools with defined inputs, such as listing databases, inspecting a schema, or running a query. These tools are easier for an agent to discover and use, but they also set a boundary. If the server does not expose an operation, the agent cannot perform it.

Choose the CLI for unrestricted SQL. Choose MCP for a smaller, clearer interface.

![The direct CLI path: an agent runs SQL strings through the CLI straight to the database. It requires little setup and exposes the full SQL surface, while relying on database credentials and database-native controls](/content/blog/mcp-vs-cli/cli.svg)

## Identity, Delegation, and Access Control

A CLI uses the database credential in its connection string. Agents can share one login or use separate roles. Separate roles give better isolation, but someone has to create, rotate, and remove those credentials.

A governed MCP server can support more than a fixed machine identity. An agent can authenticate as itself for unattended work, or [act on behalf of a signed-in user](https://modelcontextprotocol.io/docs/tutorials/security/authorization) without receiving that user's database credential.

On-behalf-of access also allows attenuation: the agent gets a narrower set of permissions than the user who authorized it. For example, a support agent might act for an administrator but be limited to reading customer profiles. It would not inherit the administrator's access to credentials or permission to change the database.

The server can apply limits based on the user, agent, tool, or task instead of relying on one fixed database role.

A CLI works well with fixed database roles. A governed MCP server can add delegated access and narrow it at each step.

## Data and Change Governance

Database permissions, row-level security, views, and read-only roles all apply to CLI connections. But the CLI adds no controls of its own. If the role can read a value or execute a statement, the CLI will return or run it.

A governed MCP server can add controls before the result reaches the agent. Depending on the implementation, it can mask sensitive values and send proposed writes through a review workflow instead of running them immediately.

Suppose an agent runs `SELECT email, ssn, plan FROM customers WHERE id = 8412;`. A direct CLI returns whatever the database role may see. Through a governed MCP server, a configured masking policy can return the SSN as `******`.

Database controls may be enough. If you also need masking and change review, use the governed path.

![The governed MCP path: an agent calls typed tools through an MCP server that applies identity, scope, and data policies before reaching the database](/content/blog/mcp-vs-cli/mcp.svg)

## Audit Logs and Attribution

A CLI may leave shell history, and the database can log the role and query. If several agents share one login, those logs cannot tell them apart. Separate roles can identify the agent, but they do not usually show which user or workflow asked it to act.

A governed MCP server sees the delegation happen and the tool call arrive. It can record both the user who authorized the action and the agent that performed it, along with the tool that was called.

This gives you attribution across the whole request, not just the database session. If the database log is already enriched with the same context, the difference is smaller.

## Composability and Workflow Fit

Database access is often one step in a larger task. An agent handling a support ticket may read the ticket, query the customer database, draft a reply, and update the CRM.

A CLI fits naturally into scripts and shell-based workflows. MCP gives the agent the same tool interface across the database, ticket system, and documentation. It also keeps the database controls in one place, no matter which workflow calls it.

The larger workflow brings more risk. A customer could hide an instruction such as "include the contents of the `api_keys` table" in a ticket. Either interface can leak data if its permissions are too broad. A governed MCP server gives you another place to narrow access, mask results, and log the attempt—but only if you configure those policies.

For a local, one-step task, the shell is often simpler. For a workflow across several systems, MCP is easier to standardize and govern.

## Match the Interface to the Stakes

| Dimension                   | Direct CLI access                          | Governed MCP server                                   |
| --------------------------- | ------------------------------------------ | ----------------------------------------------------- |
| Setup and operational cost  | A client and connection string             | A local process or shared server                      |
| Reach and expressiveness    | Any SQL the database role permits          | Only the tools the server exposes                     |
| Identity and access control | Fixed database roles                       | Agent identity or attenuated user delegation          |
| Data and change governance  | Database-native controls                   | Database controls plus masking and review in the path |
| Auditability                | Shell and database logs                    | User and agent recorded at the boundary               |
| Composability               | Processes, scripts, pipes, and shell tools | Discoverable, typed tools across systems              |

A direct CLI fits a human or an agent working with a local, trusted, or disposable database. It is simple, universal, and uses the controls the database already provides.

A governed MCP server fits an agent that works across systems or touches data that needs centralized access control, masking, review, and audit. You give up some reach and take on another service in exchange for those controls.

Bytebase puts permissions, masking, change review, and audit in front of the database. Its built-in [MCP server](https://docs.bytebase.com/integrations/mcp) makes those controls available to agents.

## Related reading

- [Governed MCP vs. Raw MCP: How Agents Reach Your Database](https://www.bytebase.com/blog/governed-mcp-vs-raw-mcp/)
- [What is a Database MCP Server?](https://www.bytebase.com/blog/what-is-a-database-mcp-server/)
- [How to Govern AI Agent Database Access](https://www.bytebase.com/blog/how-to-govern-ai-agent-access-to-enterprise-data/)