import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface CloudConnection {
name: string;
guid?: string;
connectorType?: string;
dateCreated?: string;
dateModified?: string;
shared?: boolean;
}
const inputSchema = z.object({
spaceId: z.string().describe("The ID of the space to list connections from"),
});
export function registerListConnections(server: McpServer, client: BirstClient): void {
server.tool(
"birst_list_connections",
"List data connections in a Birst space. Returns both space-level and shared connections.",
inputSchema.shape,
async (args) => {
const { spaceId } = inputSchema.parse(args);
const connections = await client.rest<CloudConnection[]>(
`/spaces/${spaceId}/connections`
);
const simplified = connections.map((conn) => ({
name: conn.name,
id: conn.guid,
type: conn.connectorType,
shared: conn.shared,
created: conn.dateCreated,
modified: conn.dateModified,
}));
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
spaceId,
count: connections.length,
connections: simplified,
},
null,
2
),
},
],
};
}
);
}