Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/api/src/protected-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { createMcpHandler, McpServer, ResourceTemplate, ProtocolError, ProtocolE
import { createMcpHonoApp } from "@modelcontextprotocol/hono";
import { z } from "zod";
import { ApiService, ServiceError } from "./api-service";
import { triggerConditionsTestSchema, triggerIdSchema, triggerInputSchema, fireTriggerInputSchema } from "./trigger-schemas";
import { triggerConditionsTestSchema, triggerIdSchema, mcpTriggerInputSchema, fireTriggerInputSchema, type TriggerInput } from "./trigger-schemas";
import type { Env, OAuthProps } from "./types";
import { executeAuth, validBrowserOrigin } from "./auth-api";
import { matchApiOperation } from "./api-contract";
Expand Down Expand Up @@ -213,8 +213,8 @@ function createMcpServer(service: ApiService, subscriptions = true): McpServer {
tool("list_event_occurrences", "Read durable Event occurrences in reverse order.", z.object({eventId:z.uuid(),...eventOccurrenceQuery.shape}), ({eventId,limit,cursor}:any) => service.listEventOccurrences(eventId,limit,cursor));
tool("list_triggers", "List triggers and their parent Events", z.object({}), () => service.listTriggers());
tool("get_trigger", "Get a Trigger, its parent Event, and input configuration", triggerIdSchema, ({ triggerId }: any) => service.getTrigger(triggerId));
tool("create_trigger", "Create an input Trigger attached to an Event. Credentials are never accepted or returned.", triggerInputSchema, (input: any) => service.createTrigger(input));
tool("update_trigger", "Replace a Trigger's input configuration and Event parent.", triggerInputSchema.extend({ triggerId: z.string().min(1) }), ({ triggerId, ...input }: any) => service.updateTrigger(triggerId, input));
tool("create_trigger", "Create an input Trigger attached to an Event. Credentials are never accepted or returned.", mcpTriggerInputSchema, (input: TriggerInput) => service.createTrigger(input));
tool("update_trigger", "Replace a Trigger's input configuration and Event parent.", mcpTriggerInputSchema.extend({ triggerId: z.string().min(1) }), ({ triggerId, ...input }: TriggerInput & { triggerId: string }) => service.updateTrigger(triggerId, input));
tool("delete_trigger", "Delete an input Trigger", triggerIdSchema, ({ triggerId }: any) => service.deleteTrigger(triggerId));
tool("enable_trigger", "Enable a trigger", triggerIdSchema, ({ triggerId }: any) => service.setTriggerEnabled(triggerId, true));
tool("disable_trigger", "Disable a trigger", triggerIdSchema, ({ triggerId }: any) => service.setTriggerEnabled(triggerId, false));
Expand Down
9 changes: 8 additions & 1 deletion packages/api/src/trigger-schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ export const triggerSourceSchema = z.discriminatedUnion("kind", [
z.object({ id: z.string().min(1).optional(), slug: z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/).optional(), kind: z.literal("schedule"), template: sourceTemplate, enabled: z.boolean().default(true), config: z.object({ cron: z.string().trim().min(1), timezone: z.string().trim().min(1) }).strict() }).strict(),
z.object({ id: z.string().min(1).optional(), slug: z.string().regex(/^[a-z][a-z0-9_-]{0,63}$/).optional(), kind: z.literal("webhook"), template: sourceTemplate, enabled: z.boolean().default(true), config: webhookSourceConfigSchema }).strict(),
]);
export const triggerInputSchema = z.object({ name: resourceName, eventId: z.guid(), sources: z.array(triggerSourceSchema).min(1).max(50).default([{ kind: "manual", slug: "source-1", enabled: true, config: {} }]) }).strict();
const triggerSources = z.array(triggerSourceSchema).min(1).max(50);
export const triggerInputSchema = z.object({ name: resourceName, eventId: z.guid(), sources: triggerSources.default([{ kind: "manual", slug: "source-1", enabled: true, config: {} }]) }).strict();

// Require explicit MCP input so a stale tool catalog cannot discard the
// source configuration and fall back to creating or restoring a manual source.
export const mcpTriggerInputSchema = triggerInputSchema.extend({
sources: triggerSources.describe("Input sources for the Trigger."),
});
export const triggerIdSchema = z.object({ triggerId: z.string().min(1) });
export const fireTriggerInputSchema = z.object({ data: z.record(z.string(), z.unknown()).default({}), idempotencyKey: z.string().trim().min(1).max(200).optional() }).strict();
export const triggerConditionsTestSchema = z.object({ conditions: conditionsSchema.optional(), webhook: preparedWebhookSchema }).strict();
Expand Down
33 changes: 33 additions & 0 deletions packages/api/test/mcp-events.postgres.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,39 @@ describe.skipIf(!process.env.AUTH_TEST_DATABASE_URL)("MCP event webhook lifecycl
"SELECT occurrence_id,status,attempts,http_status FROM app.mcp_event_deliveries ORDER BY updated_at,occurrence_id",
)).rows;

it("requires canonical MCP sources and persists the configured Linear webhook", async () => {
const catalog = (await request("tools/list")).message.result.tools;
for (const toolName of ["create_trigger", "update_trigger"]) {
const schema = catalog.find((item: { name: string }) => item.name === toolName).inputSchema;
expect(schema.properties).toMatchObject({ sources: { type: "array" } });
expect(schema.properties).not.toHaveProperty("events");
expect(schema.required).toContain("sources");
}
const config = {
provider: "linear", projectId: "fixture-project",
matchRules: [{ type: "status", targetId: "fixture-todo" }],
};
const webhook = { kind: "webhook", enabled: true, config };
const input = { name: "fixture-linear", eventId: source.definitionId };
expect((await tool("create_trigger", input)).isError).toBe(true);
expect((await tool("create_trigger", { ...input, events: [webhook] })).isError).toBe(true);
const create = await tool("create_trigger", { ...input, sources: [webhook] });
expect(create.isError, JSON.stringify(create)).not.toBe(true);
const triggerId = create.structuredContent.id;
const get = () => tool("get_trigger", { triggerId });
const original = (await get()).structuredContent.sources;
expect(original).toMatchObject([{ kind: "manual" }, webhook]);
const update = { ...input, triggerId };
const manual = { kind: "manual", id: original[0].id, config: {} };
const newWebhook = { ...webhook, id: original[1].id, config: { ...config, matchRules: [{ type: "status", targetId: "fixture-review" }] } };
expect((await tool("update_trigger", { ...update, sources: [manual, newWebhook] })).isError).not.toBe(true);
const updated = (await get()).structuredContent.sources;
expect(updated).toMatchObject([manual, newWebhook]);
expect((await tool("update_trigger", update)).isError).toBe(true);
expect((await tool("update_trigger", { ...update, events: [webhook] })).isError).toBe(true);
expect((await get()).structuredContent.sources).toEqual(updated);
});

it("discovers, subscribes, commits, dispatches and reads a deduplicated occurrence", async () => {
expect((await request("server/discover")).message.result.capabilities).toMatchObject({ events: {}, resources: { subscribe: true } });
expect((await request("events/list")).message.result.events).toEqual([{
Expand Down
5 changes: 3 additions & 2 deletions packages/docs/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,9 @@ input, or manual fire request. Duplicate deliveries are deduplicated. Reuse the
same `idempotencyKey` after an uncertain manual fire. Webhook activity tools
show safe processing outcomes without exposing secrets or raw payloads.

`create_trigger` and `update_trigger` accept a parent `eventId` and a
`sources` array of input configurations. Read a Trigger before replacing its
`create_trigger` and `update_trigger` require a parent `eventId` and an
explicit `sources` array of input configurations. For a manual-only Trigger,
send `sources: [{ "kind": "manual" }]`. Read a Trigger before replacing its
configuration.

## Integration APIs
Expand Down
5 changes: 3 additions & 2 deletions packages/docs/mcp/tools.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ input, or manual fire request. Duplicate deliveries are deduplicated. Reuse the
same `idempotencyKey` after an uncertain manual fire. Webhook activity tools
show safe processing outcomes without exposing secrets or raw payloads.

`create_trigger` and `update_trigger` accept a parent `eventId` and a
`sources` array of input configurations. Read a Trigger before replacing its
`create_trigger` and `update_trigger` require a parent `eventId` and an
explicit `sources` array of input configurations. For a manual-only Trigger,
send `sources: [{ "kind": "manual" }]`. Read a Trigger before replacing its
configuration.

## Integration APIs
Expand Down
Loading