Get a single score by id
getScoreRetrieve a specific score from Langfuse by providing its unique ID. Access evaluation data for analysis.
Instructions
Fetch a single score by id.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| scoreId | Yes |
Implementation Reference
- src/tools.ts:120-128 (handler)The handler function for 'getScore' tool. It accepts a 'scoreId' parameter, URL-encodes it, and makes a GET request to /api/public/scores/{scoreId} via the LangfuseClient. The response is returned as formatted JSON text.
server.registerTool( "getScore", { title: "Get a single score by id", description: "Fetch a single score by id.", inputSchema: { scoreId: z.string().min(1) }, }, async ({ scoreId }) => asJson(await client.get(`/api/public/scores/${enc(scoreId)}`)), ); - src/tools.ts:125-126 (schema)The input schema for 'getScore' defines a single required string parameter 'scoreId' (min length 1), validated using Zod.
inputSchema: { scoreId: z.string().min(1) }, }, - src/tools.ts:120-128 (registration)The tool named 'getScore' is registered via server.registerTool() inside the registerTools() function. It appears in the scores section of tools.ts.
server.registerTool( "getScore", { title: "Get a single score by id", description: "Fetch a single score by id.", inputSchema: { scoreId: z.string().min(1) }, }, async ({ scoreId }) => asJson(await client.get(`/api/public/scores/${enc(scoreId)}`)), ); - src/client.ts:27-66 (helper)The LangfuseClient.get() method is the underlying HTTP helper that the 'getScore' handler calls. It constructs the URL with query params, sets Basic auth, performs the fetch, and parses the JSON response.
async get(path: string, params: QueryParams = {}): Promise<unknown> { const url = new URL(`${this.baseUrl}${path}`); for (const [key, value] of Object.entries(params)) { if (value === undefined || value === null || value === "") continue; if (Array.isArray(value)) { for (const item of value) url.searchParams.append(key, String(item)); } else { url.searchParams.set(key, String(value)); } } const response = await fetch(url, { headers: { Authorization: this.authHeader, Accept: "application/json", }, }); const text = await response.text(); if (!response.ok) { throw new LangfuseError( `Langfuse API ${response.status} ${response.statusText}: ${text.slice(0, 500)}`, response.status, text, ); } try { return JSON.parse(text) as unknown; } catch { throw new LangfuseError( `Langfuse API returned non-JSON response from ${url.pathname}: ${text.slice(0, 200)}`, response.status, text, ); } } }