langfuse-mcp-java

langfuse-mcp-java

Query Langfuse traces, schema and datasets, scores and metrics, debug exceptions, analyze sessions, and manage prompts. Full observability toolkit for LLM applications.

Category
访问服务器

README

Langfuse MCP Server — Java / Spring AI

Spring Boot Spring AI Java Lombok

A production-hardened, read-only MCP server that connects any MCP-compatible AI agent to your Langfuse observability data.
Query traces, debug errors, inspect sessions, analyze prompts, and explore datasets — all through natural language.

Transport: HTTP/SSE on port 8080, compatible with Cursor and Claude Desktop out of the box.


Why this server?

Capability This server Official Langfuse MCP
Traces & Observations ✅ ❌
Sessions & Users ✅ ❌
Exception tracking ✅ ❌
Prompt management ✅ ✅
Dataset management ✅ ❌
Scores & metrics ✅ ❌
Schema introspection ✅ ❌
Java / Spring AI ✅ ❌ (Python)
Read-only by design ✅ N/A

Tools (24 total)

Category Count Tools
Traces 6 fetch_traces, fetch_trace, find_exceptions, find_exceptions_in_file, get_exception_details, get_error_count
Observations 2 fetch_observations, fetch_observation
Sessions 3 fetch_sessions, get_session_details, get_user_sessions
Prompts 2 list_prompts, get_prompt
Datasets 4 list_datasets, get_dataset, list_dataset_items, get_dataset_item
Scores 4 get_scores, get_score, get_score_configs, get_score_config
Users 1 get_user_traces
Comments 1 get_comments
Schema 1 get_data_schema

Quick start

# 1. Build
mvn clean package

# 2. Set credentials
export LANGFUSE_PUBLIC_KEY=pk-lf-...
export LANGFUSE_SECRET_KEY=sk-lf-...
export LANGFUSE_HOST=https://cloud.langfuse.com

# 3. Run (SSE transport — port 8080)
java -jar target/langfuse-mcp-1.0.0.jar

# 4. Verify
curl http://localhost:8080/actuator/health

# 5. Inspect all tools
npx @modelcontextprotocol/inspector http://localhost:8080/sse

Get credentials from Langfuse Cloud → Settings → API Keys.
Self-hosted Langfuse? Set LANGFUSE_HOST to your instance URL.


Architecture

MCP Client (Cursor / Claude Desktop / other)
    │   HTTP/SSE transport (/sse + /mcp/message)
    ▼
Tool class  (@McpTool — thin delegation layer, validates required params)
    ▼
Service interface + impl  (business logic, error mapping, server-side filtering)
    ▼
LangfuseApiClient  (GET-only HTTP gateway, typed exceptions)
    ▼
Langfuse Public REST API

The architecture is strictly layered:

  • client/ — Langfuse integration boundary (HTTP, Basic-Auth, error handling)
  • service/ — domain logic (filtering, mapping, pagination)
  • tools/ — MCP-facing surface (descriptions, param validation, delegation)
  • Spring Boot — runtime and transport wrapper only

Read-only by design: LangfuseApiClient exposes only GET methods. No POST, PATCH, or DELETE operations exist anywhere in the codebase. The langfuse.read-only=true flag is enforced at the properties level.

Every tool returns a consistent ApiResponse<T> envelope:

{ "success": true,  "data": { ... }, "timestamp": "2025-01-15T10:30:00Z" }
{ "success": false, "errorCode": "TRACE_NOT_FOUND", "errorMessage": "...", "timestamp": "..." }

Configuration

Property Env var Required Default Description
langfuse.public-key LANGFUSE_PUBLIC_KEY ✅ — Langfuse project public key
langfuse.secret-key LANGFUSE_SECRET_KEY ✅ — Langfuse project secret key
langfuse.host LANGFUSE_HOST ✅ — Langfuse base URL
langfuse.timeout LANGFUSE_TIMEOUT ❌ 30s HTTP request timeout (Spring Duration format, e.g. 30s, 1m)
langfuse.read-only — ❌ true Safety flag — always true, no writes are possible

Client config

Cursor (.cursor/mcp.json)

{
  "mcpServers": {
    "langfuse": {
      "url": "http://localhost:8080/sse"
    }
  }
}

Claude Desktop (claude_desktop_config.json)

{
  "mcpServers": {
    "langfuse": {
      "url": "http://localhost:8080/sse"
    }
  }
}

On macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

VS Code / GitHub Copilot

URL mode (if your client supports it):

{
  "github.copilot.chat.mcp.servers": {
    "langfuse": {
      "url": "http://localhost:8080/sse"
    }
  }
}

Command mode (stdio-only clients):

{
  "github.copilot.chat.mcp.servers": {
    "langfuse": {
      "command": "java",
      "args": ["-jar", "/path/to/langfuse-mcp-1.0.0.jar"],
      "env": {
        "LANGFUSE_PUBLIC_KEY": "pk-lf-...",
        "LANGFUSE_SECRET_KEY": "sk-lf-...",
        "LANGFUSE_HOST": "https://cloud.langfuse.com"
      }
    }
  }
}

Docker

# Build image
docker build -t langfuse-mcp:latest .

# Run
docker run --rm -p 8080:8080 \
  -e LANGFUSE_PUBLIC_KEY=pk-lf-... \
  -e LANGFUSE_SECRET_KEY=sk-lf-... \
  -e LANGFUSE_HOST=https://cloud.langfuse.com \
  langfuse-mcp:latest

If Langfuse runs in Docker on the same host, use host.docker.internal:

-e LANGFUSE_HOST=http://host.docker.internal:3000

Running tests

mvn test

Test coverage includes:

  • LangfusePropertiesBindingTest — config binding from application-test.yml and constructor-level validation
  • RawJsonResponseSerializationTest — Jackson serialization round-trips for RawJsonBackedResponse

Package structure

com.langfuse.mcp
├── LangfuseMcpApplication.java          @SpringBootApplication @ConfigurationPropertiesScan
├── config/
│   ├── LangfuseProperties.java          @ConfigurationProperties — publicKey, secretKey, host, timeout, readOnly
│   ├── LangfuseClientConfig.java        RestClient bean with Basic-Auth and JdkClientHttpRequestFactory
│   └── JacksonConfig.java               Primary ObjectMapper (JSR310, ignore unknowns)
├── client/
│   └── LangfuseApiClient.java           GET-only HTTP gateway; typed exceptions; UriComponentsBuilder queries
├── exception/
│   ├── LangfuseApiException.java        Wraps HTTP errors — statusCode + endpoint on all error paths
│   └── ResourceNotFoundException.java   Thrown on HTTP 404
├── dto/
│   ├── common/    ApiResponse · PagedResponse · PaginationMeta
│   ├── request/   *FilterRequest · PromptGetRequest (9 filter classes + 1 get class)
│   └── response/  *Response (14 classes — JsonNode for open-schema fields)
├── service/       Interfaces (9): Trace · Observation · Session · Prompt · Dataset · Score · User · Comment · Schema
│   └── impl/      *ServiceImpl (9) — business logic, server-side filtering, error mapping
├── tools/         @McpTool classes (9) — param validation, delegation, agent-friendly descriptions
│   ├── TraceTools.java        (6 tools)
│   ├── ObservationTools.java  (2 tools)
│   ├── SessionTools.java      (3 tools)
│   ├── PromptTools.java       (2 tools)
│   ├── DatasetTools.java      (4 tools)
│   ├── ScoreTools.java        (4 tools)
│   ├── UserTools.java         (1 tool)
│   ├── CommentTools.java      (1 tool)
│   └── SchemaTools.java       (1 tool)
└── util/
    └── JsonPageMapper.java    Centralised JSON → PagedResponse mapper (no duplication)

Troubleshooting

TRACE_FETCH_ERROR: HTTP/1.1 header parser received no bytes

Connectivity issue — not a code bug. Check:

  1. LANGFUSE_HOST points to a running Langfuse instance
  2. The host is reachable from the JVM process
  3. For Docker: use host.docker.internal instead of localhost
  4. The HTTP/HTTPS scheme matches your server (http:// vs https://)
  5. Confirm the API is up: curl $LANGFUSE_HOST/api/public/health

INVALID_INPUT: <param> is required

A required parameter was not provided by the agent. All required = true parameters are enforced at the tool layer before any HTTP call is made.

Connection timeouts

Increase the timeout via the env var:

export LANGFUSE_TIMEOUT=60s

Copilot / Claude can't see the server

  1. Confirm the server is running: curl http://localhost:8080/actuator/health
  2. Confirm the MCP SSE endpoint is alive: curl http://localhost:8080/sse
  3. Check that the URL in the client config points to http://localhost:8080/sse

License

License: MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选