Repository navigation
Add an MCP server over the Database Agent API - #6
Merged
Merged
Conversation
mcp-server/ is a stdio MCP server (database-agent-mcp) with four tools: list_agents, ask_database, list_conversations and get_conversation. Every tool calls the existing REST routes with an existing credential (per-agent keys or the operator key), so authentication, query caps, model configuration, table visibility, SQL access policy and execution stay in the API. Results return the answer, generated SQL, column-labelled rows, chart metadata and the session id used for follow-ups. Two server changes the adapter needs (DA-MCP-001): - Chat with a session_id now requires the session to belong to the agent. History was read by session_id alone, so a key for one agent could replay another agent's conversation into its model context. - Saved-conversation replay additively serves the stored column-labelled result block per turn; existing fields are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/mcp.md covers the tools, credentials, a Claude Code .mcp.json that keeps keys out of files, claude mcp add, the equivalent REST calls, security notes and how the integration was verified. README and docs/api.md link to it, and docs/api.md lists the session routes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
mcp-server/is a stdio MCP server (database-agent-mcp) that lets Claude Code and other MCP clients use Database Agent agents. It is a thin adapter over the existing REST API: each tool is an ordinary API request made with an existing credential, so authentication, agent-key scope, query caps, model configuration, table visibility, SQL access policy and execution all stay in the API. It holds no database credentials and does not generate or run SQL.list_agentsGET /v1/agents(operator key) orGET /v1/agents/{id}per agent key, plusGET …/databases(host, user and password are not returned)ask_databasePOST /v1/agents/{id}/chat?stream=false, orPOST …/sessions/{session_id}/messagesto continue a conversationlist_conversationsGET /v1/agents/{id}/sessionsget_conversationGET /v1/agents/{id}/sessions/{session_id}Tools return structured content: answer,
answered, generated SQL, column-labelled rows (row_count,truncated,max_rowsup to 1000), chart type/data/metadata, follow-ups andsession_id. API errors become MCP tool errors with the server's reason (401/403/404/429/model configuration). Recommended credential: per-agent keys (DATABASE_AGENT_AGENT_KEYS=AGENT_ID=KEY,…); the operator key is supported for single-operator installs. Plain HTTP to a non-loopback host is refused.Two API changes the adapter needs (DA-MCP-001)
session_idalone, so a key for agent A could pass a session from agent B and have B's conversation replayed into A's model context (and A's turn appended to B's session). Chat now returns 404 for a session that does not belong to the agent, before history is read or a model is called (ensure_session_belongs_to_agent).GET …/sessions/{id}previously returned only bare rows without column names; each assistant message now also hasresult(columns,rows,row_count,truncated) from the block already stored per turn. Additive; existing fields are unchanged.Both are recorded in
docs/source-preservation.json. Known limit, documented indocs/mcp.md: the saved replay route returns SQL and rows regardless of the agent'sshow_sql_query/show_db_result. The adapter applies those settings to saved turns as the live route does, but the route itself does not, so a direct API caller with the same key can still read them.Verification
mcp-adapterjob runstests/mcp(in-memory and stdio MCP client sessions against a synthetic API that mirrors the credential rules) andtests/backend/test_session_scope.py. A deliberate mutation (dropping the saved-SQL visibility gate) turns the visibility test red.sample_saleswith its read-only account), using the MCP Python SDK over stdio: 27/27 checks, including SQL + rows (North 250.00 / South 200.00), a bar-chart suggestion, a follow-up in the same session, saved conversation with labelled rows, an agent hiding SQL/rows, unknown key → 401, another agent's key → 403, foreign session → 404, delete/drop/update requests producing no SQL with the data unchanged afterwards, and a table the DB account can read but the agent's visibility excludes not being queried.claude -pwith the documented.mcp.json): list_agents → ask_database → follow-up withsession_id→ get_conversation, correct rows; and a 403 surfaced as a tool error with another agent's key.claude mcp add+claude mcp listshowed✔ Connected.pip install "git+…#subdirectory=mcp-server"(from this branch) anduvx --from ./mcp-server database-agent-mcp.🤖 Generated with Claude Code