|
| 1 | +--- |
| 2 | +title: Langfuse MCP Server |
| 3 | +sidebarTitle: MCP Server |
| 4 | +description: Native Model Context Protocol (MCP) server for Langfuse, enabling AI assistants to interact with your Langfuse data programmatically. |
| 5 | +--- |
| 6 | + |
| 7 | +# Langfuse MCP Server |
| 8 | + |
| 9 | +Langfuse includes a native [Model Context Protocol](https://modelcontextprotocol.io) (MCP) server that enables AI assistants and agents to interact with your Langfuse data programmatically. |
| 10 | + |
| 11 | +Currently, the MCP server is available for [Prompt Management](/docs/prompt-management/overview) and will be extended to the rest of the Langfuse data platform in the future. If you have feedback or ideas for new tools, please [share them on GitHub](https://github.com/orgs/langfuse/discussions/10605). |
| 12 | + |
| 13 | +<Callout type="info"> |
| 14 | + |
| 15 | +This is the authenticated MCP server for the Langfuse data platform. There is also a public MCP server for the Langfuse documentation ([docs](/docs/docs-mcp)). |
| 16 | + |
| 17 | +</Callout> |
| 18 | + |
| 19 | +## Configuration |
| 20 | + |
| 21 | +The Langfuse MCP server uses a stateless architecture where each API key is scoped to a specific project. Use the following configuration to connect to the MCP server: |
| 22 | + |
| 23 | +<Tabs items={["Cloud EU", "Cloud US", "HIPAA US", "Self-Hosted"]}> |
| 24 | + |
| 25 | +<Tab> |
| 26 | + |
| 27 | +- Endpoint: `https://cloud.langfuse.com/api/public/mcp` |
| 28 | +- Transport: `streamableHttp` |
| 29 | +- Authentication: Basic Auth via authorization header |
| 30 | + |
| 31 | +</Tab> |
| 32 | + |
| 33 | +<Tab> |
| 34 | + |
| 35 | +- Endpoint: `https://us.langfuse.com/api/public/mcp` |
| 36 | +- Transport: `streamableHttp` |
| 37 | +- Authentication: Basic Auth via authorization header |
| 38 | + |
| 39 | +</Tab> |
| 40 | + |
| 41 | +<Tab> |
| 42 | + |
| 43 | +- Endpoint: `https://hipaa.langfuse.com/api/public/mcp` |
| 44 | +- Transport: `streamableHttp` |
| 45 | +- Authentication: Basic Auth via authorization header |
| 46 | + |
| 47 | +</Tab> |
| 48 | + |
| 49 | +<Tab> |
| 50 | + |
| 51 | +- Endpoint: `https://your-domain.com/api/public/mcp` |
| 52 | +- Transport: `streamableHttp` |
| 53 | +- Authentication: Basic Auth via authorization header |
| 54 | + |
| 55 | +</Tab> |
| 56 | + |
| 57 | +</Tabs> |
| 58 | + |
| 59 | +## Available Tools |
| 60 | + |
| 61 | +The MCP server provides five tools for comprehensive prompt management. |
| 62 | + |
| 63 | +<Callout type="warning"> |
| 64 | + **Both read and write tools are available by default.** If you only want to |
| 65 | + use read-only tools, configure your MCP client with an allowlist to restrict |
| 66 | + access to write operations (`createTextPrompt`, `createChatPrompt`, |
| 67 | + `updatePromptLabels`). |
| 68 | +</Callout> |
| 69 | + |
| 70 | +### Read Operations |
| 71 | + |
| 72 | +- **`getPrompt`** - Fetch a specific prompt by name with optional label or version |
| 73 | + |
| 74 | + - Supports filtering by production/staging labels |
| 75 | + - Returns compiled prompt with metadata |
| 76 | + - Read-only operation (auto-approved by clients) |
| 77 | + |
| 78 | +- **`listPrompts`** - List all prompts in the project |
| 79 | + - Optional filtering by name, tag, or label |
| 80 | + - Cursor-based pagination support |
| 81 | + - Returns prompt metadata and available versions |
| 82 | + |
| 83 | +### Write Operations |
| 84 | + |
| 85 | +- **`createTextPrompt`** - Create a new text prompt version |
| 86 | + |
| 87 | + - Supports template variables with `{{variable}}` syntax |
| 88 | + - Optional labels, config, tags, and commit message |
| 89 | + - Automatic version incrementing |
| 90 | + |
| 91 | +- **`createChatPrompt`** - Create a new chat prompt version |
| 92 | + |
| 93 | + - OpenAI-style message format (role + content) |
| 94 | + - Supports system, user, and assistant roles |
| 95 | + - Template variables in message content |
| 96 | + |
| 97 | +- **`updatePromptLabels`** - Manage labels across prompt versions |
| 98 | + - Add or move labels between versions |
| 99 | + - Labels are unique (auto-removed from other versions) |
| 100 | + - Cannot modify the auto-managed `latest` label |
| 101 | + |
| 102 | +## Set up |
| 103 | + |
| 104 | +<Steps> |
| 105 | + |
| 106 | +### Get Authentication Header |
| 107 | + |
| 108 | +1. Navigate to your project settings and create or copy a **project-scoped API key**: |
| 109 | + - Public Key: `pk-lf-...` |
| 110 | + - Secret Key: `sk-lf-...` |
| 111 | +2. Encode the credentials to base64 format: |
| 112 | + ```bash filename="your-base64-token" |
| 113 | + echo -n "pk-lf-your-public-key:sk-lf-your-secret-key" | base64 |
| 114 | + ``` |
| 115 | + |
| 116 | +### Client Setup |
| 117 | + |
| 118 | +<Tabs items={["Claude Code", "Cursor", "Other MCP Clients"]}> |
| 119 | + |
| 120 | +<Tab> |
| 121 | + |
| 122 | +1. Register the Langfuse MCP server with a single command, replace `{your-base64-token}` with your encoded credentials: |
| 123 | + |
| 124 | + ```bash filename="terminal" /{your-base64-token}/ |
| 125 | + # Langfuse Cloud (EU) |
| 126 | + claude mcp add --transport http langfuse https://cloud.langfuse.com/api/public/mcp \ |
| 127 | + --header "Authorization: Basic {your-base64-token}" |
| 128 | + |
| 129 | + # Langfuse Cloud (US) |
| 130 | + claude mcp add --transport http langfuse https://us.langfuse.com/api/public/mcp \ |
| 131 | + --header "Authorization: Basic {your-base64-token}" |
| 132 | + |
| 133 | + # Self-Hosted (HTTPS required) |
| 134 | + claude mcp add --transport http langfuse https://your-domain.com/api/public/mcp \ |
| 135 | + --header "Authorization: Basic {your-base64-token}" |
| 136 | + |
| 137 | + # Local Development |
| 138 | + claude mcp add --transport http langfuse http://localhost:3000/api/public/mcp \ |
| 139 | + --header "Authorization: Basic {your-base64-token}" |
| 140 | + ``` |
| 141 | + |
| 142 | +2. Verify the connection by asking Claude Code to `list all prompts in the project`. Claude Code should use the `listPrompts` tool to return the list of prompts. |
| 143 | + |
| 144 | +</Tab> |
| 145 | + |
| 146 | +<Tab> |
| 147 | + |
| 148 | +1. Open Cursor Settings (`Cmd/Ctrl + Shift + J`) |
| 149 | +2. Navigate to **Tools & Integrations** tab |
| 150 | +3. Click **"Add Custom MCP"** |
| 151 | +4. Add your Langfuse MCP server configuration, replace `{your-base64-token}` with your encoded credentials: |
| 152 | + |
| 153 | +<Tabs items={["Cloud EU", "Cloud US", "HIPAA US", "Self-Hosted"]}> |
| 154 | + |
| 155 | +<Tab> |
| 156 | + |
| 157 | +```json filename="mcp.json" /{your-base64-token}/ |
| 158 | +{ |
| 159 | + "mcp": { |
| 160 | + "servers": { |
| 161 | + "langfuse": { |
| 162 | + "url": "https://cloud.langfuse.com/api/public/mcp", |
| 163 | + "headers": { |
| 164 | + "Authorization": "Basic {your-base64-token}" |
| 165 | + } |
| 166 | + } |
| 167 | + } |
| 168 | + } |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +</Tab> |
| 173 | +<Tab> |
| 174 | + |
| 175 | +```json filename="mcp.json" /{your-base64-token}/ |
| 176 | +{ |
| 177 | + "mcp": { |
| 178 | + "servers": { |
| 179 | + "langfuse": { |
| 180 | + "url": "https://us.cloud.langfuse.com/api/public/mcp", |
| 181 | + "headers": { |
| 182 | + "Authorization": "Basic {your-base64-token}" |
| 183 | + } |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | +} |
| 188 | +``` |
| 189 | + |
| 190 | +</Tab> |
| 191 | +<Tab> |
| 192 | + |
| 193 | +```json filename="mcp.json" /{your-base64-token}/ |
| 194 | +{ |
| 195 | + "mcp": { |
| 196 | + "servers": { |
| 197 | + "langfuse": { |
| 198 | + "url": "https://hipaa.cloud.langfuse.com/api/public/mcp", |
| 199 | + "headers": { |
| 200 | + "Authorization": "Basic {your-base64-token}" |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | + } |
| 205 | +} |
| 206 | +``` |
| 207 | + |
| 208 | +</Tab> |
| 209 | +<Tab> |
| 210 | + |
| 211 | +```json filename="mcp.json" /{your-base64-token}/ |
| 212 | +{ |
| 213 | + "mcp": { |
| 214 | + "servers": { |
| 215 | + "langfuse": { |
| 216 | + "url": "https://your-domain.com/api/public/mcp", |
| 217 | + "headers": { |
| 218 | + "Authorization": "Basic {your-base64-token}" |
| 219 | + } |
| 220 | + } |
| 221 | + } |
| 222 | + } |
| 223 | +} |
| 224 | +``` |
| 225 | + |
| 226 | +</Tab> |
| 227 | +</Tabs> |
| 228 | + |
| 229 | +5. Save the file and restart Cursor |
| 230 | +6. The server should appear in the MCP settings with a green dot indicating it's active |
| 231 | + |
| 232 | +</Tab> |
| 233 | + |
| 234 | +<Tab> |
| 235 | + |
| 236 | +- Endpoint: `/api/public/mcp` |
| 237 | + - EU: `https://cloud.langfuse.com/api/public/mcp` |
| 238 | + - US: `https://us.langfuse.com/api/public/mcp` |
| 239 | + - HIPAA: `https://hipaa.langfuse.com/api/public/mcp` |
| 240 | + - Self-Hosted: `https://your-domain.com/api/public/mcp` |
| 241 | +- Transport: `streamableHttp` |
| 242 | +- Authentication: Basic Auth via authorization header |
| 243 | + - `Authorization: Basic {your-base64-token}` |
| 244 | + |
| 245 | +</Tab> |
| 246 | +</Tabs> |
| 247 | + |
| 248 | +</Steps> |
| 249 | + |
| 250 | +## Use Cases |
| 251 | + |
| 252 | +The MCP server enables powerful workflows for AI-assisted prompt management: |
| 253 | + |
| 254 | +- **Prompt Creation**: "Create a new chat prompt for customer support with system instructions and example messages" |
| 255 | +- **Version Management**: "Update the staging label to point to version 3 of the email-generation prompt" |
| 256 | +- **Prompt Discovery**: "List all prompts tagged with 'production' and show their latest versions" |
| 257 | +- **Iterative Development**: "Create a new version of the code-review prompt with improved instructions" |
| 258 | + |
| 259 | +## Feedback |
| 260 | + |
| 261 | +We'd love to hear about your experience with the Langfuse MCP server. Share your feedback, ideas, and use cases in our [GitHub Discussion](https://github.com/orgs/langfuse/discussions/10605). |
| 262 | + |
| 263 | +## Related Documentation |
| 264 | + |
| 265 | +- [Prompt Management with MCP](/docs/prompt-management/features/mcp-server) - Prompt-specific workflows and examples |
| 266 | +- [Prompt Management Overview](/docs/prompt-management/overview) - Learn about Langfuse prompt management |
| 267 | +- [Public API](/docs/api-and-data-platform/features/public-api) - REST API for programmatic access |
0 commit comments