import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface SpaceUser {
userId: string;
username?: string;
email?: string;
firstName?: string;
lastName?: string;
}
const inputSchema = z.object({
spaceId: z.string().describe("The ID of the space to list users from"),
});
export function registerListSpaceUsers(server: McpServer, client: BirstClient): void {
server.tool(
"birst_list_space_users",
"List users who have access to a specific Birst space.",
inputSchema.shape,
async (args) => {
const { spaceId } = inputSchema.parse(args);
const users = await client.rest<SpaceUser[]>(`/spaces/${spaceId}/users`);
const simplified = users.map((user) => ({
id: user.userId,
username: user.username,
email: user.email,
name: user.firstName && user.lastName
? `${user.firstName} ${user.lastName}`
: user.firstName || user.lastName,
}));
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
spaceId,
count: users.length,
users: simplified,
},
null,
2
),
},
],
};
}
);
}