The Metabase AI Assistant is an MCP (Model Context Protocol) server that connects Claude Desktop and Claude Code to Metabase and PostgreSQL databases. It enables AI-powered data analysis by providing direct database access along with Metabase API integration for creating models, SQL queries, metrics, and dashboards.
# Clone the repository
git clone https://github.com/onmartech/metabase-ai-assistant.git
cd metabase-ai-assistant
# Install dependencies
npm install
# Create environment file
cp .env.example .env
Edit the .env
file with your credentials:
# Metabase Configuration
METABASE_URL=http://your-metabase-instance.com
METABASE_USERNAME=your_username
METABASE_PASSWORD=your_password
METABASE_API_KEY=your_metabase_api_key
# AI Provider (at least one required)
ANTHROPIC_API_KEY=your_anthropic_key
# or
OPENAI_API_KEY=your_openai_key
# Application Settings
LOG_LEVEL=info
To integrate with Claude Desktop:
Edit the configuration file located at ~/Library/Application Support/Claude/claude_desktop_config.json
:
{
"mcpServers": {
"metabase-ai-assistant": {
"command": "node",
"args": ["/path/to/your/metabase-ai-assistant/src/mcp/server.js"],
"env": {
"METABASE_URL": "http://your-metabase-instance.com",
"METABASE_USERNAME": "your_username",
"METABASE_PASSWORD": "your_password",
"ANTHROPIC_API_KEY": "your_anthropic_key"
}
}
}
}
After saving the configuration, restart Claude Desktop to activate the MCP tools.
For Claude Code integration:
# Install the MCP server globally
npm link
# Verify installation
which metabase-ai-mcp
npm list -g | grep metabase-ai-assistant
Ensure your .env
file is properly configured with your Metabase credentials.
# Test the MCP server directly
node src/mcp/server.js
# Test with environment variables
export METABASE_URL="http://your-instance.com"
export METABASE_USERNAME="your_username"
export METABASE_PASSWORD="your_password"
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | node src/mcp/server.js
In Claude Code, ask: "What MCP tools do you have available?"
You should see 27 Metabase AI Assistant tools available, including database tools, Metabase tools, AI-powered tools, and documentation tools.
Start the interactive command-line interface:
npm start
import { MetabaseClient } from './src/metabase/client.js';
import { MetabaseAIAssistant } from './src/ai/assistant.js';
// Create client
const client = new MetabaseClient({
url: 'http://your-metabase.com',
username: 'user',
password: 'pass'
});
// Initialize AI Assistant
const assistant = new MetabaseAIAssistant({
metabaseClient: client,
aiProvider: 'anthropic',
anthropicApiKey: 'your-key'
});
// Create model
const model = await assistant.createModel(
'Customer segmentation model',
databaseId
);
// Generate SQL query
const sql = await assistant.generateSQL(
'Total sales for the last 30 days',
schema
);
// Create sales model
await assistant.createModel(
'Daily sales summary - product, category, amount',
databaseId
);
// Define metrics
await assistant.createMetric(
'Average basket value',
tableId
);
// Create dashboard
await assistant.createDashboard(
'E-Commerce Executive Panel',
questions
);
// Customer segmentation query
const sql = await assistant.generateSQL(
'Customer segments using RFM analysis',
schema
);
// Churn prediction model
await assistant.createModel(
'Customer churn prediction model',
databaseId
);
// Income-expense analysis
await assistant.createQuestion(
'Monthly profit-loss statement',
databaseId
);
// Budget comparison dashboard
await assistant.createDashboard(
'Budget vs Actual',
budgetQuestions
);
# Install PM2 globally
npm install -g pm2
# Start MCP server with PM2
npm run pm2:start
# Monitor and manage
npm run pm2:logs
npm run pm2:restart
npm run pm2:stop
# Auto-restart on system reboot
pm2 startup
pm2 save
# Build and run with Docker Compose
npm run docker:run
# Monitor logs
npm run docker:logs
# Stop containers
npm run docker:stop
# Copy service file
sudo cp metabase-ai-mcp.service /etc/systemd/system/
# Enable and start service
sudo systemctl enable metabase-ai-mcp
sudo systemctl start metabase-ai-mcp
# Monitor service
sudo systemctl status metabase-ai-mcp
sudo journalctl -u metabase-ai-mcp -f
npm link
was run successfullywhich metabase-ai-mcp
echo $METABASE_URL
node src/mcp/server.js
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "metabase-ai-assistant" '{"command":"node","args":["/path/to/your/metabase-ai-assistant/src/mcp/server.js"],"env":{"METABASE_URL":"http://your-metabase-instance.com","METABASE_USERNAME":"your_username","METABASE_PASSWORD":"your_password","ANTHROPIC_API_KEY":"your_anthropic_key"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"metabase-ai-assistant": {
"command": "node",
"args": [
"/path/to/your/metabase-ai-assistant/src/mcp/server.js"
],
"env": {
"METABASE_URL": "http://your-metabase-instance.com",
"METABASE_USERNAME": "your_username",
"METABASE_PASSWORD": "your_password",
"ANTHROPIC_API_KEY": "your_anthropic_key"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"metabase-ai-assistant": {
"command": "node",
"args": [
"/path/to/your/metabase-ai-assistant/src/mcp/server.js"
],
"env": {
"METABASE_URL": "http://your-metabase-instance.com",
"METABASE_USERNAME": "your_username",
"METABASE_PASSWORD": "your_password",
"ANTHROPIC_API_KEY": "your_anthropic_key"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect