Skip to content

MCP Integration

Use dbward from AI-powered IDEs (Cursor, GitHub Copilot, Kiro) via the Model Context Protocol. The AI can query databases, run migrations, and check request status — all through dbward’s approval workflow.

  • AI never gets DB credentials — all operations go through dbward’s approval engine
  • Same workflow for humans and AI — production queries still require human approval
  • Full audit trail — every AI-initiated operation is logged with the AI tool as actor

Ensure you have a working client configuration. For stdio mode, the CLI needs to know your server URL and credentials:

Global config (~/.config/dbward/config.toml):

[server]
url = "https://dbward.internal:3000"
token = "dbw_..."

Or use OIDC: dbward login

dbward supports two transports: stdio (local binary) and Remote HTTP (server-hosted, no local install needed).

Add to .cursor/mcp.json:

{
"mcpServers": {
"dbward": {
"command": "dbward",
"args": ["mcp"],
"env": {}
}
}
}

Add to .vscode/mcp.json:

{
"servers": {
"dbward": {
"command": "dbward",
"args": ["mcp"]
}
}
}

Add to .kiro/settings/mcp.json:

{
"mcpServers": {
"dbward": {
"command": "dbward",
"args": ["mcp"],
"transportType": "stdio"
}
}
}

The dbward server exposes MCP at /mcp. Team members don’t need the CLI installed — just point their IDE at the server:

{
"mcpServers": {
"dbward": {
"type": "streamable-http",
"url": "https://your-server.example.com/mcp"
}
}
}
{
"servers": {
"dbward": {
"type": "http",
"url": "https://your-server.example.com/mcp"
}
}
}
{
"mcpServers": {
"dbward": {
"transportType": "streamable-http",
"url": "https://your-server.example.com/mcp"
}
}
}

Authentication: Remote HTTP uses the same token or OIDC as the REST API. The IDE passes credentials via the Authorization header. Ensure your dbward.toml has a valid token or that you’ve run dbward login.

stdioRemote HTTP
Requires local dbward binary
Works offline (local dev)
Centralized for teams
Tools available129 (excludes local-only migration tools)
Prompts available64 (excludes file-dependent prompts)
Elicitation supportIDE-dependentIDE-dependent

Ask your AI assistant: “What tables are in the database?” — it should use dbward_inspect_schema to answer.

If the AI can’t connect, run dbward doctor to check that the server URL and token are correctly configured.

Full parameter reference: MCP Reference

ToolDescription
dbward_execute_queryExecute SQL (goes through approval workflow)
dbward_inspect_schemaInspect schema (list tables or describe columns)
dbward_preflight_sqlAnalyze SQL before submitting (risk, policy, EXPLAIN)
ToolDescription
dbward_wait_requestWait for request completion and return result
dbward_list_pendingList requests awaiting approval
dbward_who_can_approveShow who can approve a request
dbward_find_similar_requestsFind similar past requests
ToolDescription
dbward_migrate_statusShow migration status
dbward_migrate_upApply migrations
dbward_migrate_downRollback migrations
dbward_migrate_createCreate migration files (local)
ToolDescription
dbward_explain_policy_failureExplain why a request was blocked

When the AI executes a query that requires approval:

  1. AI calls dbward_execute_query → request created (status: pending)
  2. If the IDE supports elicitation, dbward asks the user for confirmation directly in the IDE
  3. Otherwise, the AI reports the request ID and waits
  4. A human approves via CLI, another IDE, or Slack
  5. AI calls dbward_wait_request to wait for approval and result
  6. Once complete, the result is returned directly

AI agents should call dbward_preflight_sql before submitting SQL to avoid polluting the approval queue with unsafe or blocked queries:

  1. AI drafts SQL based on user request
  2. AI calls dbward_preflight_sql to validate
  3. If status is blocked — AI reads fix_hints and next_actions, rewrites the SQL, and retries preflight
  4. If status is warning — AI informs the user of risks before proceeding
  5. If status is requestable — AI calls dbward_execute_query to submit

This loop lets the AI converge on safe SQL without human intervention or creating unnecessary requests. The preflight call is lightweight and does not require approval.

The MCP server exposes read-only resources:

ResourceDescription
dbward://migrations/statusCurrent migration state
dbward://requests/pendingPending approval requests
dbward://audit/recentRecent audit events
dbward://requests/{id}Specific request details (template)
dbward://schema/{database}Table list with row counts (from agent snapshot)
dbward://schema/{database}/{table}Column, constraint, and index details for a table

Schema resources return data from agent-collected snapshots (no live DB query needed).

dbward://schema/app → all tables (name, schema, rows, column count)
dbward://schema/app/users → full details for 'users' table
dbward://schema/app/public.orders → schema-qualified lookup

The server automatically resolves the best environment (production > staging > development) based on snapshot availability and your permissions. The response includes environment and collected_at so you know which snapshot you’re seeing.

If no snapshot is available yet, start an agent for the database — it collects schema on startup.

Pre-built prompts for common AI workflows:

PromptDescription
review_migrationReview a migration for safety issues
explain_requestExplain what a request will do
draft_migrationGenerate migration SQL from a description
draft_rollbackGenerate rollback SQL for a migration
summarize_audit_trailSummarize recent audit events
prepare_approval_commentDraft an approval comment

You: “Add an index on users.email for faster lookups”

AI: I’ll create a migration for that. [calls dbward_migrate_create with name “add_users_email_index”]

Created db/migrations/20260508_add_users_email_index/up.sql. Here’s the SQL:

CREATE INDEX CONCURRENTLY idx_users_email ON users (email);

You: “Apply it to staging”

AI: [calls dbward_migrate_up with environment “staging”]

✓ Migration applied to staging (auto-approved).

You: “Now apply to production”

AI: [calls dbward_migrate_up with environment “production”]

⚠ Request req_m3x4 requires approval from dba-team. I’ll check back when it’s approved.

[waits with dbward_wait_request]

✓ Approved by bob@example.com. Migration applied successfully.

  • The AI tool authenticates as the user’s identity (their token or OIDC session)
  • The AI cannot bypass approval workflows — --emergency is blocked via MCP
  • All AI-initiated operations appear in the audit log
  • The AI never sees database credentials

When a query requires approval, dbward uses MCP’s Elicitation feature to pause and wait:

  1. AI calls dbward_execute_query
  2. Server responds: “approval required”
  3. MCP tool uses elicitation to inform the user and wait (timeout: 300 seconds)
  4. If a reason is required by the workflow, elicitation prompts the user for it
  5. Once approved (via CLI, API, or Slack), the tool resumes and returns the result

If the IDE doesn’t support elicitation, the tool falls back to polling with dbward_wait_request.