Skip to content

Commit 189dc74

Browse files
committed
MCP: Update to @bytebase/dbhub@0.2.3
- New resource `db://schemas` - New argument `schema` for prompt `generate_sql` - New arguments `schema` and `table` for prompt `explain_db`
1 parent b0824b2 commit 189dc74

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

framework/mcp/example_dbhub.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
command="npx",
1515
args=[
1616
"-y",
17-
"@bytebase/dbhub@0.1",
17+
"@bytebase/dbhub@0.2.3",
1818
"--transport=stdio",
1919
#"--transport=sse",
2020
#"--port=8080",
@@ -43,18 +43,21 @@ async def run():
4343

4444
# Validate database content.
4545
db = DatabaseAdapter("crate://crate@localhost:4200/")
46-
db.run_sql("CREATE TABLE IF NOT EXISTS public.testdrive (id INT, data TEXT)")
47-
db.run_sql("INSERT INTO public.testdrive (id, data) VALUES (42, 'Hotzenplotz')")
46+
db.run_sql("CREATE TABLE IF NOT EXISTS testdrive.dbhub (id INT, data TEXT)")
47+
db.run_sql("INSERT INTO testdrive.dbhub (id, data) VALUES (42, 'Hotzenplotz')")
4848
db.refresh_table("public.testdrive")
4949

50-
# Read a few resources.
51-
# FIXME: Only works on schema=public, because the PostgreSQL adapter hard-codes `WHERE table_schema = 'public'`.
52-
# https://github.com/bytebase/dbhub/blob/09424c8513c8c7bef7f66377b46a2b93a69a57d2/src/connectors/postgres/index.ts#L89-L107
53-
await client.read_resource("db://tables")
50+
# Read available resources.
51+
await client.read_resource("db://schemas")
5452

55-
# Get a few prompts.
56-
await client.get_prompt("generate_sql", arguments={"description": "Please enumerate the highest five mountains.", "dialect": "postgres"})
57-
await client.get_prompt("explain_db", arguments={"target": "testdrive"})
53+
# Invoke available prompts.
54+
await client.get_prompt("generate_sql", arguments={
55+
"description": "Please enumerate the highest five mountains.",
56+
"dialect": "postgres",
57+
"schema": "sys",
58+
})
59+
await client.get_prompt("explain_db", arguments={"schema": "testdrive"})
60+
await client.get_prompt("explain_db", arguments={"schema": "testdrive", "table": "dbhub"})
5861

5962

6063
if __name__ == "__main__":

framework/mcp/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,11 @@ def test_dbhub():
108108
assert b"Calling tool: list_connectors" in p.stdout
109109
assert b"dsn: postgres://postgres" in p.stdout
110110

111-
assert b"Reading resource: db://tables" in p.stdout
111+
assert b"Reading resource: db://schemas" in p.stdout
112+
assert b"- doc" in p.stdout
113+
assert b"- sys" in p.stdout
112114
assert b"- testdrive" in p.stdout
113115

114116
assert b"Getting prompt: explain_db" in p.stdout
115-
assert b"Table: testdrive" in p.stdout
117+
assert b"Table: dbhub in schema 'testdrive'" in p.stdout
116118
assert b"Structure:\\n- id (integer)\\n- data (text)" in p.stdout

0 commit comments

Comments
 (0)