1+ import DetailsWrap from '@site/src /components/DetailsWrap';
2+
13# MCP Server for Databend
24
35[ 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:
2729
2830For detailed DSN format and examples, see [ Connection String Documentation] ( https://docs.databend.com/developer/drivers/#connection-string-dsn ) .
2931
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 ` |
3436
3537### Step 2: Install Dependencies
3638
@@ -50,6 +52,7 @@ pip install packaging openai agno openrouter sqlalchemy fastapi mcp-databend
5052Now create your ChatBI agent that uses mcp-databend to interact with your database.
5153
5254Create a file ` agent.py ` :
55+ <DetailsWrap >
5356
5457<details >
5558<summary >Click to view agent.py code</summary >
@@ -76,16 +79,16 @@ def check_env_vars():
7679 " DATABEND_DSN" : " https://docs.databend.com/developer/drivers/#connection-string-dsn" ,
7780 " OPENROUTER_API_KEY" : " https://openrouter.ai/settings/keys"
7881 }
79-
82+
8083 missing = [var for var in required if not os.getenv(var)]
81-
84+
8285 if missing:
8386 print (" ❌ Missing environment variables:" )
8487 for var in missing:
8588 print (f " • { var} : { required[var]} " )
8689 print (" \n Example: export DATABEND_DSN='...' OPENROUTER_API_KEY='...'" )
8790 sys.exit(1 )
88-
91+
8992 print (" ✅ Environment variables OK" )
9093
9194check_env_vars()
@@ -94,7 +97,7 @@ class DatabendTool:
9497 def __init__ (self ):
9598 self .mcp = None
9699 self .dsn = os.getenv(" DATABEND_DSN" )
97-
100+
98101 def create (self ):
99102 env = os.environ.copy()
100103 env[" DATABEND_DSN" ] = self .dsn
@@ -104,7 +107,7 @@ class DatabendTool:
104107 timeout_seconds = 300
105108 )
106109 return self .mcp
107-
110+
108111 async def init (self ):
109112 try :
110113 await self .mcp.connect()
@@ -144,12 +147,12 @@ async def lifespan(app: FastAPI):
144147 if not await databend.init():
145148 logger.error(" Failed to initialize Databend" )
146149 raise RuntimeError (" Databend connection failed" )
147-
150+
148151 agent.tools.append(tool)
149152 logger.info(" ChatBI initialized successfully" )
150-
153+
151154 yield
152-
155+
153156 if databend.mcp:
154157 await databend.mcp.close()
155158
@@ -168,7 +171,7 @@ if __name__ == "__main__":
168171```
169172
170173</details >
171-
174+ </ DetailsWrap >
172175### Step 4: Configure Environment
173176
174177Set up your API keys and database connection:
@@ -190,11 +193,12 @@ python agent.py
190193```
191194
192195You should see:
196+
193197```
194198✅ Environment variables OK
195199🤖 Starting MCP Server for Databend
196200Open 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
198202INFO: Started server process [189851]
199203INFO: Waiting for application startup.
200204INFO:agent:✓ Connected to Databend
@@ -216,11 +220,13 @@ cd agent-ui && npm run dev
216220```
217221
218222** Connect to Your Agent:**
223+
2192241 . Open [ http://localhost:3000 ] ( http://localhost:3000 )
2202252 . Select "localhost:7777" as your endpoint
2212263 . Start asking questions about your data!
222227
223228** Try These Queries:**
229+
224230- "Show me all databases"
225231- "What tables do I have?"
226232- "Describe the structure of my tables"
@@ -231,4 +237,4 @@ cd agent-ui && npm run dev
231237- ** GitHub Repository** : [ databendlabs/mcp-databend] ( https://github.com/databendlabs/mcp-databend )
232238- ** PyPI Package** : [ mcp-databend] ( https://pypi.org/project/mcp-databend )
233239- ** 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