|
1 | | -# Metabase FastMCP Server |
| 1 | +# Metabase MCP Server |
2 | 2 |
|
3 | | -A FastMCP (Model Context Protocol) server for Metabase, built with Python. This server provides tools to interact with Metabase databases, execute queries, manage cards, and work with collections. |
4 | | - |
5 | | -## Features |
6 | | - |
7 | | -- List and manage Metabase databases |
8 | | -- Execute SQL queries and saved questions/cards |
9 | | -- Create and manage cards (questions) |
10 | | -- Work with collections |
11 | | -- List tables and fields |
12 | | -- API Key authentication |
| 3 | +A FastMCP server for Metabase integration that provides tools to interact with Metabase databases, execute queries, manage cards (questions), and work with collections. |
13 | 4 |
|
14 | 5 | ## Installation |
15 | 6 |
|
16 | | -### Quick Start with uv (Recommended) |
17 | | - |
18 | | -1. **Install uv** if not already installed: |
19 | | -```bash |
20 | | -curl -LsSf https://astral.sh/uv/install.sh | sh |
21 | | -``` |
22 | | - |
23 | | -2. **Clone and setup**: |
24 | 7 | ```bash |
| 8 | +# Clone the repository |
25 | 9 | git clone <repository-url> |
26 | 10 | cd metabase-mcp |
27 | | -uv sync # Install dependencies and create virtual environment |
28 | | -``` |
29 | 11 |
|
30 | | -3. **Configure environment**: |
31 | | -```bash |
32 | | -# Create .env file with your Metabase configuration |
33 | | -echo "METABASE_URL=http://localhost:3000" > .env |
34 | | -echo "METABASE_API_KEY=your-api-key-here" >> .env |
| 12 | +# Install dependencies |
| 13 | +uv sync |
35 | 14 | ``` |
36 | 15 |
|
37 | 16 | ## Configuration |
38 | 17 |
|
39 | | -Set the following environment variables in your `.env` file: |
40 | | - |
41 | | -- `METABASE_URL`: Your Metabase instance URL |
42 | | -- `METABASE_API_KEY`: Your Metabase API key |
43 | | - |
44 | | -## Usage |
45 | | - |
46 | | -### Run the Server |
| 18 | +Set required environment variables in a `.env` file: |
47 | 19 |
|
48 | 20 | ```bash |
49 | | -# STDIO transport (default for MCP integration) |
50 | | -uv run server.py |
51 | | - |
52 | | -# SSE transport (for web applications) |
53 | | -uv run server.py --sse |
54 | | - |
55 | | -# HTTP transport |
56 | | -uv run server.py --http |
| 21 | +METABASE_URL=https://your-metabase-instance.com |
| 22 | +METABASE_API_KEY=your-api-key-here |
| 23 | + |
| 24 | +# Optional settings (defaults shown) |
| 25 | +MCP_TRANSPORT=streamable-http # or "stdio" for IDE integration |
| 26 | +HOST=0.0.0.0 |
| 27 | +PORT=8080 |
| 28 | +LOG_LEVEL=INFO |
| 29 | + |
| 30 | +# HTTP Client Configuration (optional) |
| 31 | +HTTP_CONNECT_TIMEOUT=10.0 # Connection timeout in seconds (1.0-60.0) |
| 32 | +HTTP_READ_TIMEOUT=30.0 # Read timeout in seconds (5.0-300.0) |
| 33 | +HTTP_ENABLE_HTTP2=false # Enable HTTP/2 support |
57 | 34 | ``` |
58 | 35 |
|
59 | | -### Claude Desktop Integration |
| 36 | +## Running |
60 | 37 |
|
61 | | -To integrate with Claude Desktop, add the configuration to `~/Library/Application\ Support/Claude/claude_desktop_config.json`: |
| 38 | +```bash |
| 39 | +# Default (HTTP transport) |
| 40 | +uv run python -m src |
62 | 41 |
|
63 | | -```json |
64 | | -{ |
65 | | - "mcpServers": { |
66 | | - "metabase-mcp": { |
67 | | - "command": "uv", |
68 | | - "args": ["run", "python", "/path/to/metabase-mcp-kmlx/server.py"], |
69 | | - "cwd": "/path/to/metabase-mcp-kmlx" |
70 | | - } |
71 | | - } |
72 | | -} |
| 42 | +# STDIO transport (for IDE integration) |
| 43 | +MCP_TRANSPORT=stdio uv run python -m src |
73 | 44 | ``` |
74 | 45 |
|
75 | 46 | ## Available Tools |
76 | 47 |
|
77 | 48 | ### Database & Schema Tools |
78 | | -- `list_databases`: List all databases in Metabase |
79 | | -- `list_tables`: List all tables in a database with formatted output |
80 | | -- `get_table_fields`: Get all fields/columns in a table |
| 49 | +- **`list_databases`** - List all databases in Metabase |
| 50 | +- **`list_tables(database_id)`** - List tables in a database with formatted markdown output |
| 51 | +- **`get_table_fields(table_id, limit=20)`** - Get fields/columns in a table |
81 | 52 |
|
82 | 53 | ### Card & Query Tools |
83 | | -- `list_cards`: List all questions/cards in Metabase (WARNING: Large dataset) |
84 | | -- `list_cards_paginated`: List cards with pagination to avoid timeout issues |
85 | | -- `execute_card`: Execute a Metabase question/card and get results |
86 | | -- `execute_query`: Execute a SQL query against a Metabase database |
87 | | -- `create_card`: Create a new question/card in Metabase |
| 54 | +- **`list_cards`** - List all questions/cards (WARNING: Large dataset, may timeout) |
| 55 | +- **`list_cards_paginated(limit=50, offset=0, filter_type="all")`** - List cards with pagination |
| 56 | +- **`list_cards_by_collection(collection_id)`** - List cards in a specific collection |
| 57 | +- **`execute_card(card_id, parameters=None)`** - Execute a Metabase question/card |
| 58 | +- **`execute_query(database_id, query, native_parameters=None)`** - Execute SQL query |
| 59 | +- **`create_card(name, database_id, query, description=None, collection_id=None, visualization_settings=None)`** - Create new card |
88 | 60 |
|
89 | | -### Collection Management Tools |
90 | | -- `list_collections`: List all collections in Metabase |
91 | | -- `list_cards_by_collection`: List cards in a specific collection (focused dataset) |
92 | | -- `create_collection`: Create a new collection in Metabase |
| 61 | +### Collection Management |
| 62 | +- **`list_collections`** - List all collections |
| 63 | +- **`create_collection(name, description=None, color=None, parent_id=None)`** - Create new collection |
93 | 64 |
|
94 | 65 | ### Smart Search Tools |
95 | | -- `search_metabase`: Universal search using Metabase search API (cards, dashboards, collections) |
96 | | -- `find_candidate_collections`: Find collections by name/description matching (fast) |
97 | | -- `search_cards_in_collections`: Search for cards within specific collections (targeted) |
| 66 | +- **`search_metabase(query, limit=20, models=None, archived=False, search_native_query=None)`** - Search using Metabase API |
| 67 | +- **`find_candidate_collections(query, limit_collections=10)`** - Find collections matching query |
| 68 | +- **`search_cards_in_collections(query, collection_ids, limit=25, offset=0)`** - Search cards within specific collections |
98 | 69 |
|
99 | | -## Development |
| 70 | +## Health Check |
100 | 71 |
|
101 | | -### Development Setup |
| 72 | +The server provides a `/ping` endpoint for health checks when running with HTTP transport. |
102 | 73 |
|
103 | | -```bash |
104 | | -# Install development dependencies (Python 3.12+) |
105 | | -uv sync --group dev |
106 | | - |
107 | | -# Run tests |
108 | | -uv run pytest |
| 74 | +## Integration |
109 | 75 |
|
110 | | -# Format and lint code |
111 | | -uv run ruff check . # Lint |
112 | | -uv run ruff format . # Format |
113 | | -uv run black . # Alternative formatter |
114 | | -uv run isort . # Import sorting |
115 | | - |
116 | | -# Type checking |
117 | | -uv run mypy server.py |
118 | | -``` |
| 76 | +For Claude Desktop or Cursor IDE integration, set `MCP_TRANSPORT=stdio` in your environment. |
0 commit comments