import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import type { BirstClient } from "../../client/birstClient.js";
import { z } from "zod";
interface WorkflowRunResponse {
runId?: string;
status?: string;
message?: string;
}
const inputSchema = z.object({
workflowId: z.string().describe("The ID of the workflow to run"),
parameters: z.record(z.string()).optional().describe(
"Optional workflow parameters as key-value pairs"
),
});
export function registerRunWorkflow(server: McpServer, client: BirstClient): void {
server.tool(
"birst_run_workflow",
"Trigger a workflow to run immediately. Returns the run ID for status monitoring.",
inputSchema.shape,
async (args) => {
const { workflowId, parameters } = inputSchema.parse(args);
const response = await client.rest<WorkflowRunResponse>(
`/workflows/${workflowId}/_runNow`,
{
method: "POST",
body: parameters ? { parameters } : {},
}
);
return {
content: [
{
type: "text" as const,
text: JSON.stringify(
{
success: true,
workflowId,
runId: response.runId,
status: response.status,
message: response.message || "Workflow triggered successfully",
},
null,
2
),
},
],
};
}
);
}