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