import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface Dashboard {
id: string;
name: string;
layout?: string;
}
const inputSchema = z.object({
spaceId: z.string().describe("The ID of the space"),
collectionId: z.string().describe("The ID of the collection containing dashboards"),
});
export function registerListDashboards(server: McpServer, client: BirstClient): void {
server.tool(
"birst_list_dashboards",
"List dashboards in a specific collection. Use birst_list_collections first to find collection IDs.",
inputSchema.shape,
async (args) => {
const { spaceId, collectionId } = inputSchema.parse(args);
const dashboards = await client.rest<Dashboard[]>(
`/spaces/${spaceId}/collections/${collectionId}/dashboards`
);
const simplified = dashboards.map((dashboard) => ({
id: dashboard.id,
name: dashboard.name,
layout: dashboard.layout,
}));
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
spaceId,
collectionId,
count: dashboards.length,
dashboards: simplified,
},
null,
2
),
},
],
};
}
);
}