import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface BaseSource {
id?: string;
name: string;
type?: string;
connectionId?: string;
}
const inputSchema = z.object({
spaceId: z.string().describe("The ID of the space to list sources from"),
type: z.enum(["RAW", "SCRIPTED", "LIVE_ACCESS", "INHERITED"]).optional().describe(
"Filter sources by type (RAW, SCRIPTED, LIVE_ACCESS, INHERITED)"
),
});
export function registerListSources(server: McpServer, client: BirstClient): void {
server.tool(
"birst_list_sources",
"List data sources (tables) in a Birst space. Can filter by source type.",
inputSchema.shape,
async (args) => {
const { spaceId, type } = inputSchema.parse(args);
const sources = await client.rest<BaseSource[]>(`/spaces/${spaceId}/sources`, {
queryParams: type ? { type } : undefined,
});
const simplified = sources.map((source) => ({
id: source.id,
name: source.name,
type: source.type,
connectionId: source.connectionId,
}));
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
spaceId,
filter: type || "all",
count: sources.length,
sources: simplified,
},
null,
2
),
},
],
};
}
);
}