Skip to content

Please add dbcode-disconnect / dbcode-connect MCP tools for file-based database lock management #1034

@IainColledge

Description

@IainColledge

What

Add dbcode-disconnect and dbcode-connect MCP tools that allow agents to programmatically disconnect and reconnect named database connections.

Why (problem/use case)

DuckDB uses exclusive file locking — only one process can hold a write connection at a time. When an AI agent uses dbcode-execute-query to inspect data (e.g., validating a dbt model output), DBCode holds the connection open. Any subsequent build tool (dbt, DuckDB CLI) that needs write access fails with:

IO Error: Cannot open file "...duckdb": The process cannot access the file because it is being used by another process.

Today the only workaround is asking the user to manually click disconnect in the DBCode panel — breaking the agent's autonomous workflow. With dbcode-disconnect / dbcode-connect, an agent could:

  1. Connect → query to validate results → disconnect
  2. Run dbt build / DuckDB CLI commands
  3. Reconnect → query to verify

This is a common pattern in data engineering workflows where agents alternate between querying results and running build pipelines against the same database file.

Additional Context

  • This only affects file-based databases with exclusive locking (DuckDB, SQLite). Server-based databases like Fabric/Postgres are unaffected — multiple concurrent connections work fine.
  • The existing dbcode-get-connections tool already returns connection IDs, so dbcode-disconnect / dbcode-connect could accept those same IDs.
  • Suggested signatures:
    • dbcode-disconnect(connectionId) — close the connection, release file lock
    • dbcode-connect(connectionId) — reopen a previously configured connection
  • Ideally dbcode-execute-query could also accept an autoDisconnect: true parameter that closes the connection after returning results, for fire-and-forget validation queries.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions