1
+ import DetailsWrap from '@site/src /components/DetailsWrap';
2
+
1
3
# MCP Server for Databend
2
4
3
5
[ mcp-databend] ( https://github.com/databendlabs/mcp-databend ) is an MCP (Model Context Protocol) server that enables AI assistants to interact directly with your Databend database using natural language.
@@ -27,10 +29,10 @@ First, you need a Databend database to connect to:
27
29
28
30
For detailed DSN format and examples, see [ Connection String Documentation] ( https://docs.databend.com/developer/drivers/#connection-string-dsn ) .
29
31
30
- | Deployment | Connection String Example |
31
- | ------------| ---------------------------|
32
- | ** Databend Cloud** | ` databend://user:pwd@host:443/database?warehouse=wh ` |
33
- | ** Self-hosted** | ` databend://user:pwd@localhost:8000/database?sslmode=disable ` |
32
+ | Deployment | Connection String Example |
33
+ | ------------------ | ------------------------------------------------------------- |
34
+ | ** Databend Cloud** | ` databend://user:pwd@host:443/database?warehouse=wh ` |
35
+ | ** Self-hosted** | ` databend://user:pwd@localhost:8000/database?sslmode=disable ` |
34
36
35
37
### Step 2: Install Dependencies
36
38
@@ -50,6 +52,7 @@ pip install packaging openai agno openrouter sqlalchemy fastapi mcp-databend
50
52
Now create your ChatBI agent that uses mcp-databend to interact with your database.
51
53
52
54
Create a file ` agent.py ` :
55
+ <DetailsWrap >
53
56
54
57
<details >
55
58
<summary >Click to view agent.py code</summary >
@@ -76,16 +79,16 @@ def check_env_vars():
76
79
" DATABEND_DSN" : " https://docs.databend.com/developer/drivers/#connection-string-dsn" ,
77
80
" OPENROUTER_API_KEY" : " https://openrouter.ai/settings/keys"
78
81
}
79
-
82
+
80
83
missing = [var for var in required if not os.getenv(var)]
81
-
84
+
82
85
if missing:
83
86
print (" ❌ Missing environment variables:" )
84
87
for var in missing:
85
88
print (f " • { var} : { required[var]} " )
86
89
print (" \n Example: export DATABEND_DSN='...' OPENROUTER_API_KEY='...'" )
87
90
sys.exit(1 )
88
-
91
+
89
92
print (" ✅ Environment variables OK" )
90
93
91
94
check_env_vars()
@@ -94,7 +97,7 @@ class DatabendTool:
94
97
def __init__ (self ):
95
98
self .mcp = None
96
99
self .dsn = os.getenv(" DATABEND_DSN" )
97
-
100
+
98
101
def create (self ):
99
102
env = os.environ.copy()
100
103
env[" DATABEND_DSN" ] = self .dsn
@@ -104,7 +107,7 @@ class DatabendTool:
104
107
timeout_seconds = 300
105
108
)
106
109
return self .mcp
107
-
110
+
108
111
async def init (self ):
109
112
try :
110
113
await self .mcp.connect()
@@ -144,12 +147,12 @@ async def lifespan(app: FastAPI):
144
147
if not await databend.init():
145
148
logger.error(" Failed to initialize Databend" )
146
149
raise RuntimeError (" Databend connection failed" )
147
-
150
+
148
151
agent.tools.append(tool)
149
152
logger.info(" ChatBI initialized successfully" )
150
-
153
+
151
154
yield
152
-
155
+
153
156
if databend.mcp:
154
157
await databend.mcp.close()
155
158
@@ -168,7 +171,7 @@ if __name__ == "__main__":
168
171
```
169
172
170
173
</details >
171
-
174
+ </ DetailsWrap >
172
175
### Step 4: Configure Environment
173
176
174
177
Set up your API keys and database connection:
@@ -190,11 +193,12 @@ python agent.py
190
193
```
191
194
192
195
You should see:
196
+
193
197
```
194
198
✅ Environment variables OK
195
199
🤖 Starting MCP Server for Databend
196
200
Open http://localhost:7777 to start chatting!
197
- INFO Starting playground on http://127.0.0.1:7777
201
+ INFO Starting playground on http://127.0.0.1:7777
198
202
INFO: Started server process [189851]
199
203
INFO: Waiting for application startup.
200
204
INFO:agent:✓ Connected to Databend
@@ -216,11 +220,13 @@ cd agent-ui && npm run dev
216
220
```
217
221
218
222
** Connect to Your Agent:**
223
+
219
224
1 . Open [ http://localhost:3000 ] ( http://localhost:3000 )
220
225
2 . Select "localhost:7777" as your endpoint
221
226
3 . Start asking questions about your data!
222
227
223
228
** Try These Queries:**
229
+
224
230
- "Show me all databases"
225
231
- "What tables do I have?"
226
232
- "Describe the structure of my tables"
@@ -231,4 +237,4 @@ cd agent-ui && npm run dev
231
237
- ** GitHub Repository** : [ databendlabs/mcp-databend] ( https://github.com/databendlabs/mcp-databend )
232
238
- ** PyPI Package** : [ mcp-databend] ( https://pypi.org/project/mcp-databend )
233
239
- ** Agno Framework** : [ Agno MCP] ( https://docs.agno.com/tools/mcp/mcp )
234
- - ** Agent UI** : [ Agent UI] ( https://docs.agno.com/agent-ui/introduction )
240
+ - ** Agent UI** : [ Agent UI] ( https://docs.agno.com/agent-ui/introduction )
0 commit comments