Get observation by id
getObservationRetrieve a specific observation from Langfuse by its ID.
Instructions
Fetch a single observation by id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| observationId | Yes |
Implementation Reference
- src/tools.ts:66-75 (registration)Registration of the 'getObservation' tool on the MCP server via registerTool(). Defines title, description, input schema, and handler.
server.registerTool( "getObservation", { title: "Get observation by id", description: "Fetch a single observation by id.", inputSchema: { observationId: z.string().min(1) }, }, async ({ observationId }) => asJson(await client.get(`/api/public/observations/${enc(observationId)}`)), ); - src/tools.ts:68-72 (schema)Input schema for getObservation: requires a single 'observationId' string (min length 1) validated with Zod.
{ title: "Get observation by id", description: "Fetch a single observation by id.", inputSchema: { observationId: z.string().min(1) }, }, - src/tools.ts:73-75 (handler)Handler function for getObservation: destructures observationId, makes a GET request to the Langfuse API at /api/public/observations/{observationId}, and returns the JSON result.
async ({ observationId }) => asJson(await client.get(`/api/public/observations/${enc(observationId)}`)), ); - src/tools.ts:6-8 (helper)Helper function 'asJson' used by the handler to wrap the API response in MCP text content format.
const asJson = (data: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }); - src/tools.ts:10-10 (helper)URI encoding helper 'enc' used to safely encode the observationId in the URL path.
const enc = encodeURIComponent;