import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface SpaceGroup {
id: string;
name: string;
}
const inputSchema = z.object({
spaceId: z.string().describe("The ID of the space to list groups from"),
});
export function registerListSpaceGroups(server: McpServer, client: BirstClient): void {
server.tool(
"birst_list_space_groups",
"List groups within a Birst space. Space groups control user permissions within the space.",
inputSchema.shape,
async (args) => {
const { spaceId } = inputSchema.parse(args);
const groups = await client.rest<SpaceGroup[]>(
`/spaces/${spaceId}/spacegroups`
);
const simplified = groups.map((group) => ({
id: group.id,
name: group.name,
}));
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
spaceId,
count: groups.length,
spaceGroups: simplified,
},
null,
2
),
},
],
};
}
);
}