web/src/features/mcp/README.md
Model Context Protocol (MCP) server for Langfuse, enabling AI assistants to interact with your Langfuse prompts programmatically.
Get API Keys
http://localhost:3000/project/{project-id}/settingspk-lf-... and sk-lf-...)Encode Credentials
echo -n "pk-lf-xxx:sk-lf-xxx" | base64
Output:
// Example. Real token will be much longer
cGstbGYteHh4OnNrLWxmLXh4eA==
Add to Claude Code
claude mcp add --transport http langfuse http://localhost:3000/api/public/mcp \
--header "Authorization: Basic {your-base64-token}"
Verify
In Claude Code: List all prompts in the project
The MCP server provides 6 tools for prompt management:
getPrompt - Fetch a specific prompt by name with optional label or version (fully resolved with dependencies)getPromptUnresolved - Fetch a specific prompt WITHOUT resolving dependencies (useful for prompt composition analysis)listPrompts - List all prompts in the project with filtering (name/label/tag/updatedAt range) and paginationcreateTextPrompt - Create a new text prompt versioncreateChatPrompt - Create a new chat prompt version (OpenAI-style messages)updatePromptLabels - Add/move labels across prompt versionsImplementation: See /web/src/features/mcp/features/prompts/tools/ for detailed schemas, parameters, and examples for each tool.
getPrompt vs getPromptUnresolvedLangfuse supports prompt composition where prompts can reference other prompts via dependency tags like @@@langfusePrompt:name=xxx|label=yyy@@@. The MCP server provides two tools for fetching prompts with different resolution behaviors:
getPrompt (Fully Resolved)Input: "You are helpful. @@@langfusePrompt:name=base-rules|label=production@@@"
Output: "You are helpful. Always be kind and respectful."
getPromptUnresolved (Raw)@@@langfusePrompt:...@@@ tags preservedInput: "You are helpful. @@@langfusePrompt:name=base-rules|label=production@@@"
Output: "You are helpful. @@@langfusePrompt:name=base-rules|label=production@@@"
Use Cases for getPromptUnresolved:
The Langfuse MCP server uses a stateless per-request architecture:
This design:
1. Client sends request with Authorization header
↓
2. API endpoint validates BasicAuth (PUBLIC_KEY:SECRET_KEY)
↓
3. Verify API key has project-level scope
↓
4. Build ServerContext from API key metadata
↓
5. Create fresh MCP server with context in closure
↓
6. Handle request (context auto-injected to handlers)
↓
7. Discard server instance
ServerContext:
{
projectId: "proj-123", // Auto-injected from API key
orgId: "org-456", // Auto-injected from API key
apiKeyId: "key-789", // For audit logging
accessLevel: "project", // Required for MCP
publicKey: "pk-lf-..." // For reference
}
Tools include hints for clients about their behavior:
readOnly: true: Safe operations that don't modify data (getPrompt, listPrompts)destructive: true: Operations that create/modify data (createTextPrompt, createChatPrompt, updatePromptLabels)Clients like Claude Code can use these annotations to:
All write operations (createTextPrompt, createChatPrompt, updatePromptLabels) automatically create audit log entries with before/after snapshots.
All clients require BasicAuth authentication using your Langfuse API keys.
Encode your Langfuse API keys (Public Key:Secret Key) to base64:
echo -n "pk-lf-your-public-key:sk-lf-your-secret-key" | base64
This outputs your BasicAuth token (e.g., cGstbGYt...).
Langfuse Cloud:
https://cloud.langfuse.comhttps://us.langfuse.comhttps://hipaa.langfuse.comSelf-Hosted:
https://your-domain.comLocal Development:
http://localhost:3000Register the Langfuse MCP server:
# Langfuse Cloud (EU)
claude mcp add --transport http langfuse https://cloud.langfuse.com/api/public/mcp \
--header "Authorization: Basic {your-base64-token}"
# Langfuse Cloud (US)
claude mcp add --transport http langfuse https://us.langfuse.com/api/public/mcp \
--header "Authorization: Basic {your-base64-token}"
# Self-Hosted (HTTPS required)
claude mcp add --transport http langfuse https://your-domain.com/api/public/mcp \
--header "Authorization: Basic {your-base64-token}"
# Local Development
claude mcp add --transport http langfuse http://localhost:3000/api/public/mcp \
--header "Authorization: Basic {your-base64-token}"
Add to your Cursor MCP settings:
{
"mcp": {
"servers": {
"langfuse": {
"url": "https://cloud.langfuse.com/api/public/mcp",
"headers": {
"Authorization": "Basic {your-base64-token}"
}
}
}
}
}
Replace https://cloud.langfuse.com with your Langfuse URL (see Choose Your Langfuse URL).