Skip to content

Commit 6f3b59c

Browse files
committed
docs: add OpenAI Codex support and AI agent context to Lightdash MCP integration
1 parent de2a70e commit 6f3b59c

File tree

6 files changed

+120
-54
lines changed

6 files changed

+120
-54
lines changed
44 KB
Loading
8.28 KB
Loading
103 KB
Loading
178 KB
Loading
85.1 KB
Loading

references/integrations/lightdash-mcp.mdx

Lines changed: 120 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ icon: "hexagon-nodes"
77
Available to all Lightdash Cloud users.
88
</Check>
99

10-
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) enables AI assistants (e.g. ChatGPT, Claude) and custom agents to directly interact with your Lightdash data. This integration allows MCP clients to explore your data models, search for metrics and dimensions, and provide data-driven insights - all through natural conversation. You can use MCP with existing AI assistants or integrate it into your own custom agents and automated workflows. MCP uses secure OAuth authentication and respects all your existing access controls, ensuring data remains protected.
10+
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) enables AI assistants (e.g. ChatGPT, Claude, OpenAI Codex) and custom agents to directly interact with your Lightdash data. This integration allows MCP clients to explore your data models, search for metrics and dimensions, and provide data-driven insights - all through natural conversation. You can use MCP with existing AI assistants or integrate it into your own custom agents and automated workflows. MCP uses secure OAuth authentication and respects all your existing access controls, ensuring data remains protected.
1111

1212
With MCP, your AI assistant becomes a data analyst that can:
1313

1414
- Browse and understand your data models
1515
- Find relevant metrics and dimensions
16+
- Run queries and generate visualizations
17+
- Leverage your AI agents' domain expertise and verified questions
1618
- Switch between different projects seamlessly
1719
- Respect your data governance and access controls
1820

@@ -29,7 +31,7 @@ Setting up MCP is quick and straightforward. You can connect your AI assistant t
2931
### Prerequisites
3032

3133
- A Lightdash Cloud account or Enterprise account with MCP enabled
32-
- An MCP-compatible AI assistant (e.g., Claude.ai, Claude Desktop, ChatGPT)
34+
- An MCP-compatible AI assistant (e.g., Claude.ai, Claude Desktop, ChatGPT, OpenAI Codex)
3335

3436
### Network requirements
3537

@@ -148,6 +150,31 @@ ChatGPT support for MCP is coming soon\! Stay tuned for updates.
148150
</Accordion>
149151
*/}
150152

153+
#### OpenAI Codex
154+
155+
<Accordion title="Setup instructions">
156+
1. **Navigate to Settings**
157+
158+
Go to **Settings > MCP Servers** and click **Add Server**.
159+
160+
2. **Configure Connection**
161+
162+
Select **Streamable HTTP** as the transport type and enter your Lightdash MCP URL.
163+
164+
<Frame>
165+
![Select Streamable HTTP and enter your Lightdash instance MCP URL](/images/references/integrations/lightdash-mcp/codex-01-add-mcp-server.png)
166+
</Frame>
167+
- **URL:** `https://<your_instance_name>.lightdash.cloud/api/v1/mcp`
168+
169+
3. **Authenticate**
170+
171+
Once the server is created, an **Authenticate** option will appear in the MCP Servers list. Click it to complete the OAuth flow with your Lightdash account.
172+
173+
<Frame>
174+
![Click Authenticate next to the Lightdash server to complete the OAuth flow](/images/references/integrations/lightdash-mcp/codex-02-oauth-flow.png)
175+
</Frame>
176+
</Accordion>
177+
151178
#### Claude Code CLI
152179

153180
For developers using Claude Code CLI:
@@ -216,78 +243,41 @@ This will open an interactive inspector where you can explore available tools an
216243

217244
{/* TODO: Add screenshots of the MCP inspector interface */}
218245

219-
## Configuring your AI assistant
220-
221-
Since MCP provides raw tools without built-in intelligence, your AI assistant needs proper instructions to use Lightdash MCP effectively. We recommend adding custom instructions to guide the AI in using the tools correctly.
222-
223-
<Accordion title="Setting up custom instructions for Claude">
224-
<Frame>
225-
![Setting up custom instructions for Lightdash MCP in Claude](/images/references/integrations/lightdash-mcp/setting-up-custom-instructions-01-claude.png)
226-
</Frame>
227-
Here's a suggested template for optimizing Lightdash MCP usage. Feel free to modify these instructions based on your specific needs and use cases:
228-
229-
```
230-
## Lightdash Tool Usage Best Practices
231-
232-
### Initial Data Discovery Pattern
233-
1. **Start with explore discovery**: Use `find_explores` with `exploreName: null` to see all available tables
234-
2. **Examine table descriptions** to identify the most relevant explore for your query
235-
3. **Search for specific fields** using `find_fields` with descriptive search terms
236-
4. **Execute queries** once you have the correct field IDs
237-
238-
### Common Parameter Mistakes to Avoid
239-
- **find_explores**: Pass `null` (not boolean `true`) for exploreName to get all explores
240-
- **find_explores**: Pass _exact explore name_ as `exploreName` if you want to zoom in on particular explore
241-
- **find_fields**: Always use the exact `fieldId` values returned from field searches
242-
- **Page parameters**: Use numbers (e.g., `1` by default) . NEVER use `NaN`or `"null"` (null as a string)
243-
244-
### Field Search Strategy
245-
- Search for business terms (e.g., "basket total", "partner name") not technical field names
246-
- Use multiple search queries in one call to find related fields efficiently
247-
- Look for both dimensions (for grouping) and metrics (for aggregation)
248-
249-
### When to Use run_sql vs run_metric_query
250-
- **Prefer `run_metric_query`** for standard analysis using defined metrics and dimensions — it leverages the semantic layer and ensures consistent definitions
251-
- **Use `run_sql`** for ad-hoc queries, cross-table joins not modeled in explores, or when the user explicitly requests raw SQL
252-
- `run_sql` defaults to 500 rows (max 5000) — use the `limit` parameter to control result size
253-
- Use the SQL dialect appropriate for the connected warehouse (e.g., PostgreSQL, BigQuery, Snowflake)
254-
```
255-
256-
<Info>
257-
For Claude Code CLI users, you can add these instructions to your project's `CLAUDE.md` file instead of configuring them in the web interface.
258-
</Info>
259-
</Accordion>
246+
## Built-in prompt
247+
248+
The Lightdash MCP server includes a built-in **`lightdash-analyst`** prompt with guidelines for querying data effectively — covering explore selection, query building, visualization rules, and more. MCP clients that support prompts (like Claude) can use this automatically, so you don't need to configure custom instructions manually.
249+
250+
<Info>
251+
The built-in prompt also adapts to the active AI agent context. When an agent is selected, the prompt automatically includes the agent's instructions, available explores, and verified questions.
252+
</Info>
260253

261254
## What it can do
262255

263256
### Core capabilities
264257

265258
MCP provides AI assistants with powerful tools to interact with your Lightdash data:
266259

267-
#### System information
268-
269-
- **Get Lightdash version** - Check the current version of your Lightdash instance
270-
271260
#### Project management
272261

273262
- **List projects** - View all accessible projects in your organization
274263
- **Set active project** - Switch context between different projects (required before accessing any data)
275264
- **Get current project** - Check which project is currently active
276265

277266
<Info>
278-
**Important:** An active project must be set before MCP can retrieve any data. Your AI assistant will typically handle this automatically by listing available projects and asking you to select one if none is currently active.
267+
An active project must be set before MCP can retrieve any data. Your AI assistant will typically handle this automatically by listing available projects and asking you to select one.
279268
</Info>
280269

281-
#### Data exploration tools
270+
#### Data exploration
282271

283-
- **Find explores** - Browse available data models (explores) and understand their structure
284-
- **Find fields** - Search for specific metrics and dimensions across your data models
285-
- **Find dashboards** - Locate existing dashboards by name or content
286-
- **Find charts** - Search through saved charts and visualizations
272+
- **List explores** - See all available data models in the current project at a glance
273+
- **Find explores** - Search for relevant data models using natural language (e.g., "customer orders")
274+
- **Find fields** - Search for specific metrics and dimensions by business terms (e.g., "total revenue", "order date")
275+
- **Search field values** - Look up valid values for a field, useful for building filters
276+
- **Find content** - Search for existing charts and dashboards by name or description
287277

288278
#### Query execution
289279

290-
- **Run metric query** - Execute queries using your semantic layer's metrics and dimensions
280+
- **Run metric query** - Execute queries using your semantic layer's metrics and dimensions, and generate visualizations (tables, bar charts, line charts, pie charts, and more)
291281
- **Run SQL** - Execute arbitrary SQL queries directly against the project's data warehouse. Useful for ad-hoc analysis or queries that don't fit the explore-based model. Returns up to 500 rows by default (configurable up to 5,000).
292282

293283
<Info>
@@ -298,6 +288,15 @@ MCP provides AI assistants with powerful tools to interact with your Lightdash d
298288
**Security best practice:** Ensure the database credentials configured in your Lightdash connection have **read-only (viewer) access** to your warehouse. Since `run_sql` executes arbitrary SQL, a connection with write permissions could allow AI agents to modify or delete warehouse data.
299289
</Warning>
300290

291+
#### Agent context
292+
293+
- **List agents** - Discover available AI agents and their areas of expertise
294+
- **Set agent** - Activate an agent to scope your session to its explores, instructions, and verified questions
295+
- **Get current agent** - Check which agent is active and view its full context
296+
- **Clear agent** - Remove agent scoping and return to the full project context
297+
298+
These tools are covered in detail in the [Using AI agent context](#using-ai-agent-context) section below.
299+
301300
### Example conversations
302301

303302
Here are some examples of how you can interact with AI assistants using MCP:
@@ -320,6 +319,73 @@ Here are some examples of how you can interact with AI assistants using MCP:
320319
</Accordion>
321320
</AccordionGroup>
322321

322+
## Using AI agent context
323+
324+
If your organization has [Lightdash AI agents](/guides/ai-agents) configured, you can reuse their configuration in your MCP sessions.
325+
326+
### How is this different from Lightdash AI agents?
327+
328+
[Lightdash AI agents](/guides/ai-agents) are a fully managed experience inside Lightdash and Slack. They handle everything end-to-end: interpreting your question, picking the right data, running queries, and presenting results. They include tailored optimizations like conversation memory, self-improvement, and evaluations that are not available through MCP.
329+
330+
MCP gives you more flexibility: you can combine Lightdash data with other tools, write code alongside your analysis, or build custom workflows. But the AI assistant driving the MCP session is generic and doesn't have the specialized tuning that Lightdash AI agents provide out of the box.
331+
332+
Agent context via MCP lets you reuse your agents' configuration (curated explores, verified questions, and instructions) in an MCP session. This gives your AI assistant better guidance, but it's not a replacement for the full Lightdash AI agents experience.
333+
334+
### What you get from agent context
335+
336+
When you activate an agent in your MCP session, your AI assistant receives:
337+
338+
- **Scoped explores**: only the data models relevant to that agent's domain
339+
- **Verified questions**: curated example queries that demonstrate correct usage of the data model
340+
- **Custom instructions**: domain-specific rules like _"Always filter orders by status = 'completed'"_
341+
342+
### Example workflow
343+
344+
1. **Set your project** with `set_project`
345+
2. **Browse available agents** with `list_agents` (e.g., "Sales Analyst", "Marketing Metrics")
346+
3. **Activate an agent** with `set_agent` to load its context
347+
4. **Ask your questions**: your AI assistant will use the agent's explores, instructions, and verified questions to guide its queries
348+
349+
<AccordionGroup>
350+
<Accordion title="Listing available agents in a project">
351+
<Frame>
352+
![Listing available AI agents in a project](/images/references/integrations/lightdash-mcp/examples-04-list-agents.png)
353+
</Frame>
354+
</Accordion>
355+
<Accordion title="Setting an agent and viewing its explores">
356+
<Frame>
357+
![Setting an AI agent and viewing its available explores](/images/references/integrations/lightdash-mcp/examples-05-set-agent-and-see-explores.png)
358+
</Frame>
359+
</Accordion>
360+
<Accordion title="Asking a question with agent context">
361+
This agent was configured with the following instructions:
362+
363+
```
364+
You are a Sales analyst for Jaffle Shop. Your role is to answer questions
365+
about revenue, orders, customers and subscriptions.
366+
367+
Key guidelines:
368+
- Use the orders explore as the starting point for revenue and order
369+
volume questions.
370+
- Always include a time dimension when showing trends. Default to monthly
371+
granularity unless the user specifies otherwise.
372+
- Format currency values in CAD.
373+
```
374+
375+
When asked _"Can you show me revenue so far?"_, the response automatically followed these instructions:
376+
377+
<Frame>
378+
![Asking a question with agent context applied for better results](/images/references/integrations/lightdash-mcp/examples-06-ask-question-with-agent-context.png)
379+
</Frame>
380+
</Accordion>
381+
</AccordionGroup>
382+
383+
<Tip>
384+
You can also access agent context as a **resource** using the URI pattern `lightdash://agents/{agentUuid}/context`. MCP clients that support resources can load this directly as structured data.
385+
</Tip>
386+
387+
The built-in `lightdash-analyst` prompt automatically adapts when an agent is active, appending the agent's instructions, explores, and verified questions to the base guidelines.
388+
323389
## Best practices
324390

325391
To get the most value from MCP, ensure your Lightdash data is well-organized and documented. See our [AI agents best practices guide](/guides/ai-agents#best-practices) for detailed recommendations on:

0 commit comments

Comments
 (0)