import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface SpaceReport {
id: string;
name: string;
type?: string;
tags?: string[];
directoryPath?: string;
}
const inputSchema = z.object({
spaceId: z.string().describe("The ID of the space to list reports from"),
resultsPerPage: z.number().optional().default(100).describe(
"Number of results per page (default: 100)"
),
currentPage: z.number().optional().default(0).describe(
"Page number, starting from 0 (default: 0)"
),
});
export function registerListReports(server: McpServer, client: BirstClient): void {
server.tool(
"birst_list_reports",
"List reports in a Birst space. Supports pagination for large result sets.",
inputSchema.shape,
async (args) => {
const { spaceId, resultsPerPage, currentPage } = inputSchema.parse(args);
const reports = await client.rest<SpaceReport[]>(`/spaces/${spaceId}/reports`, {
queryParams: {
resultsPerPage,
currentPage,
},
});
const simplified = reports.map((report) => ({
id: report.id,
name: report.name,
type: report.type,
path: report.directoryPath,
tags: report.tags,
}));
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
count: reports.length,
page: currentPage,
perPage: resultsPerPage,
reports: simplified,
},
null,
2
),
},
],
};
}
);
}