list_datasets
Retrieve datasets from Langfuse projects with pagination to manage and analyze data efficiently.
Instructions
List all datasets in the project with pagination support.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page | No | Page number for pagination (starts at 1) | |
| limit | No | Maximum number of datasets to return (default: 50) |
Input Schema (JSON Schema)
{
"properties": {
"limit": {
"description": "Maximum number of datasets to return (default: 50)",
"type": "number"
},
"page": {
"description": "Page number for pagination (starts at 1)",
"type": "number"
}
},
"type": "object"
}
Implementation Reference
- src/tools/list-datasets.ts:11-27 (handler)The main handler function for the list_datasets tool. It invokes the Langfuse client to list datasets and returns the JSON-formatted result or error.export async function listDatasets( client: LangfuseAnalyticsClient, args: ListDatasetsArgs = {} ) { try { const data = await client.listDatasets(args); return { content: [{ type: 'text' as const, text: JSON.stringify(data, null, 2) }], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text' as const, text: `Error: ${errorMessage}` }], isError: true, }; } }
- src/tools/list-datasets.ts:4-7 (schema)Zod schema defining the input parameters for the list_datasets tool: page and limit.export const listDatasetsSchema = z.object({ page: z.number().min(1).optional().describe('Page number for pagination (starts at 1)'), limit: z.number().min(1).max(100).optional().describe('Maximum number of datasets to return (default: 50)'), });
- src/index.ts:645-661 (registration)Registers the list_datasets tool in the MCP server's tool list, providing name, description, and input schema.{ name: 'list_datasets', description: 'List all datasets in the project with pagination support.', inputSchema: { type: 'object', properties: { page: { type: 'number', description: 'Page number for pagination (starts at 1)', }, limit: { type: 'number', description: 'Maximum number of datasets to return (default: 50)', }, }, }, },
- src/index.ts:1098-1101 (registration)Switch case in the call tool handler that parses arguments using the schema and invokes the listDatasets handler.case 'list_datasets': { const args = listDatasetsSchema.parse(request.params.arguments); return await listDatasets(this.client, args); }
- src/langfuse-client.ts:411-435 (helper)LangfuseAnalyticsClient method that performs the actual API request to list datasets from the Langfuse server.async listDatasets(params: { page?: number; limit?: number; } = {}): Promise<any> { const queryParams = new URLSearchParams(); if (params.page) queryParams.append('page', params.page.toString()); if (params.limit) queryParams.append('limit', params.limit.toString()); const authHeader = 'Basic ' + Buffer.from( `${this.config.publicKey}:${this.config.secretKey}` ).toString('base64'); const response = await fetch(`${this.config.baseUrl}/api/public/v2/datasets?${queryParams}`, { headers: { 'Authorization': authHeader, }, }); if (!response.ok) { await this.handleApiError(response, 'List Datasets'); } return await response.json(); }