Get session with its traces
getSessionRetrieve a Langfuse session and its associated traces by providing the session id.
Instructions
Fetch a session by id, including its traces.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes |
Implementation Reference
- src/tools.ts:92-100 (registration)Registration of the 'getSession' tool via server.registerTool. It accepts a 'sessionId' string (min length 1) and calls Langfuse public API GET /api/public/sessions/{sessionId}.
server.registerTool( "getSession", { title: "Get session with its traces", description: "Fetch a session by id, including its traces.", inputSchema: { sessionId: z.string().min(1) }, }, async ({ sessionId }) => asJson(await client.get(`/api/public/sessions/${enc(sessionId)}`)), ); - src/tools.ts:99-99 (handler)Handler function for 'getSession': an anonymous async function that destructures 'sessionId' from args, URL-encodes it via the 'enc' helper, and performs a GET request to the Langfuse public sessions endpoint.
async ({ sessionId }) => asJson(await client.get(`/api/public/sessions/${enc(sessionId)}`)), - src/tools.ts:97-97 (schema)Input schema for 'getSession': a single required 'sessionId' field validated as a non-empty string via Zod's z.string().min(1).
inputSchema: { sessionId: z.string().min(1) }, - src/tools.ts:6-8 (helper)Helper 'asJson' that wraps data into an MCP text content response with pretty-printed JSON.
const asJson = (data: unknown) => ({ content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }], }); - src/tools.ts:10-10 (helper)Helper alias 'enc' referencing encodeURIComponent, used to safely encode the sessionId in the URL path.
const enc = encodeURIComponent;