import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface CatalogEntity {
id: string;
name: string;
type?: string;
description?: string;
}
const inputSchema = z.object({
spaceId: z.string().describe("The ID of the space to search"),
query: z.string().describe("Search query for catalog entities"),
});
export function registerSearchCatalog(server: McpServer, client: BirstClient): void {
server.tool(
"birst_search_catalog",
"Search for entities in the Birst catalog (tables, columns, measures, etc.).",
inputSchema.shape,
async (args) => {
const { spaceId, query } = inputSchema.parse(args);
const results = await client.rest<CatalogEntity[]>(
`/spaces/${spaceId}/catalog/entities/search`,
{
method: "POST",
body: {
query,
},
}
);
const simplified = results.map((entity) => ({
id: entity.id,
name: entity.name,
type: entity.type,
description: entity.description,
}));
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
query,
count: results.length,
entities: simplified,
},
null,
2
),
},
],
};
}
);
}