From 76cce49b74fbe659db3db9f0290f5dbba3dd2d6e Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Tue, 24 Nov 2026 08:20:59 -0700 Subject: [PATCH 1/2] Accept legacy MCP trigger source input --- packages/api/src/protected-api.ts | 6 ++-- packages/api/src/trigger-schemas.ts | 16 +++++++++- packages/api/test/mcp-events.postgres.test.ts | 31 +++++++++++++++++++ packages/docs/llms-full.txt | 3 +- packages/docs/mcp/tools.mdx | 3 +- 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/packages/api/src/protected-api.ts b/packages/api/src/protected-api.ts index e8601dd2..353bac73 100644 --- a/packages/api/src/protected-api.ts +++ b/packages/api/src/protected-api.ts @@ -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, normalizeMcpTriggerInput, fireTriggerInputSchema } from "./trigger-schemas"; import type { Env, OAuthProps } from "./types"; import { executeAuth, validBrowserOrigin } from "./auth-api"; import { matchApiOperation } from "./api-contract"; @@ -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: Parameters[0]) => service.createTrigger(normalizeMcpTriggerInput(input))); + tool("update_trigger", "Replace a Trigger's input configuration and Event parent.", mcpTriggerInputSchema.safeExtend({ triggerId: z.string().min(1) }), ({ triggerId, ...input }: Parameters[0] & { triggerId: string }) => service.updateTrigger(triggerId, normalizeMcpTriggerInput(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)); diff --git a/packages/api/src/trigger-schemas.ts b/packages/api/src/trigger-schemas.ts index 8123ab72..94bc2e1e 100644 --- a/packages/api/src/trigger-schemas.ts +++ b/packages/api/src/trigger-schemas.ts @@ -19,7 +19,21 @@ 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(); + +// A previously discovered MCP tool catalog can still send the old "events" +// input. Validate both spellings identically, but keep REST's contract unchanged. +export const mcpTriggerInputSchema = triggerInputSchema.extend({ + sources: triggerSources.optional().describe("Input sources for the Trigger."), + events: triggerSources.optional().describe("Deprecated MCP alias for sources; do not supply both."), +}).refine(({ sources, events }) => sources === undefined || events === undefined, { + path: ["events"], message: "Specify either sources or events, not both.", +}); + +export function normalizeMcpTriggerInput({ events, sources, ...input }: z.infer): TriggerInput { + return triggerInputSchema.parse({ ...input, sources: sources ?? events }); +} 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(); diff --git a/packages/api/test/mcp-events.postgres.test.ts b/packages/api/test/mcp-events.postgres.test.ts index 2cb5710b..1df9965c 100644 --- a/packages/api/test/mcp-events.postgres.test.ts +++ b/packages/api/test/mcp-events.postgres.test.ts @@ -119,6 +119,37 @@ 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("persists a Linear webhook from legacy MCP input alongside the built-in manual source", async () => { + const catalog = (await request("tools/list")).message.result.tools; + for (const toolName of ["create_trigger", "update_trigger"]) { + expect(catalog.find((item: { name: string }) => item.name === toolName).inputSchema.properties) + .toMatchObject({ sources: { type: "array" }, events: { type: "array" } }); + } + 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 }; + const create = await tool("create_trigger", { ...input, events: [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 oldWebhook = { ...webhook, id: original[1].id }; + const newWebhook = { ...oldWebhook, config: { ...config, matchRules: [{ type: "status", targetId: "fixture-review" }] } }; + expect((await tool("update_trigger", { ...update, sources: [manual, newWebhook] })).isError).not.toBe(true); + expect((await get()).structuredContent.sources).toMatchObject([manual, newWebhook]); + expect((await tool("update_trigger", { ...update, events: [manual, oldWebhook] })).isError).not.toBe(true); + const restored = (await get()).structuredContent.sources; + expect(restored).toMatchObject([manual, oldWebhook]); + expect((await tool("update_trigger", { ...update, sources: [manual, newWebhook], events: [manual, oldWebhook] })).isError).toBe(true); + expect((await get()).structuredContent.sources).toEqual(restored); + }); + 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([{ diff --git a/packages/docs/llms-full.txt b/packages/docs/llms-full.txt index ba030116..6ed314e4 100644 --- a/packages/docs/llms-full.txt +++ b/packages/docs/llms-full.txt @@ -315,7 +315,8 @@ 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 +`sources` array of input configurations. Older MCP clients may send `events` +instead; send only one of the two fields. Read a Trigger before replacing its configuration. ## Integration APIs diff --git a/packages/docs/mcp/tools.mdx b/packages/docs/mcp/tools.mdx index a2313e70..f25ce2eb 100644 --- a/packages/docs/mcp/tools.mdx +++ b/packages/docs/mcp/tools.mdx @@ -88,7 +88,8 @@ 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 +`sources` array of input configurations. Older MCP clients may send `events` +instead; send only one of the two fields. Read a Trigger before replacing its configuration. ## Integration APIs From a1dcba4be5bded0b3af36ae81a16f275ee092c50 Mon Sep 17 00:00:00 2001 From: Brendan Asselstine Date: Tue, 24 Nov 2026 08:25:17 -0700 Subject: [PATCH 2/2] Require canonical sources in MCP trigger writes --- packages/api/src/protected-api.ts | 6 ++--- packages/api/src/trigger-schemas.ts | 13 +++------- packages/api/test/mcp-events.postgres.test.ts | 26 ++++++++++--------- packages/docs/llms-full.txt | 6 ++--- packages/docs/mcp/tools.mdx | 6 ++--- 5 files changed, 26 insertions(+), 31 deletions(-) diff --git a/packages/api/src/protected-api.ts b/packages/api/src/protected-api.ts index 353bac73..4397ae28 100644 --- a/packages/api/src/protected-api.ts +++ b/packages/api/src/protected-api.ts @@ -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, mcpTriggerInputSchema, normalizeMcpTriggerInput, 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"; @@ -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.", mcpTriggerInputSchema, (input: Parameters[0]) => service.createTrigger(normalizeMcpTriggerInput(input))); - tool("update_trigger", "Replace a Trigger's input configuration and Event parent.", mcpTriggerInputSchema.safeExtend({ triggerId: z.string().min(1) }), ({ triggerId, ...input }: Parameters[0] & { triggerId: string }) => service.updateTrigger(triggerId, normalizeMcpTriggerInput(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)); diff --git a/packages/api/src/trigger-schemas.ts b/packages/api/src/trigger-schemas.ts index 94bc2e1e..1a101a40 100644 --- a/packages/api/src/trigger-schemas.ts +++ b/packages/api/src/trigger-schemas.ts @@ -22,18 +22,11 @@ export const triggerSourceSchema = z.discriminatedUnion("kind", [ 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(); -// A previously discovered MCP tool catalog can still send the old "events" -// input. Validate both spellings identically, but keep REST's contract unchanged. +// 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.optional().describe("Input sources for the Trigger."), - events: triggerSources.optional().describe("Deprecated MCP alias for sources; do not supply both."), -}).refine(({ sources, events }) => sources === undefined || events === undefined, { - path: ["events"], message: "Specify either sources or events, not both.", + sources: triggerSources.describe("Input sources for the Trigger."), }); - -export function normalizeMcpTriggerInput({ events, sources, ...input }: z.infer): TriggerInput { - return triggerInputSchema.parse({ ...input, sources: sources ?? events }); -} 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(); diff --git a/packages/api/test/mcp-events.postgres.test.ts b/packages/api/test/mcp-events.postgres.test.ts index 1df9965c..2dd50d82 100644 --- a/packages/api/test/mcp-events.postgres.test.ts +++ b/packages/api/test/mcp-events.postgres.test.ts @@ -119,11 +119,13 @@ 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("persists a Linear webhook from legacy MCP input alongside the built-in manual source", async () => { + 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"]) { - expect(catalog.find((item: { name: string }) => item.name === toolName).inputSchema.properties) - .toMatchObject({ sources: { type: "array" }, events: { type: "array" } }); + 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", @@ -131,7 +133,9 @@ describe.skipIf(!process.env.AUTH_TEST_DATABASE_URL)("MCP event webhook lifecycl }; const webhook = { kind: "webhook", enabled: true, config }; const input = { name: "fixture-linear", eventId: source.definitionId }; - const create = await tool("create_trigger", { ...input, events: [webhook] }); + 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 }); @@ -139,15 +143,13 @@ describe.skipIf(!process.env.AUTH_TEST_DATABASE_URL)("MCP event webhook lifecycl expect(original).toMatchObject([{ kind: "manual" }, webhook]); const update = { ...input, triggerId }; const manual = { kind: "manual", id: original[0].id, config: {} }; - const oldWebhook = { ...webhook, id: original[1].id }; - const newWebhook = { ...oldWebhook, config: { ...config, matchRules: [{ type: "status", targetId: "fixture-review" }] } }; + 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); - expect((await get()).structuredContent.sources).toMatchObject([manual, newWebhook]); - expect((await tool("update_trigger", { ...update, events: [manual, oldWebhook] })).isError).not.toBe(true); - const restored = (await get()).structuredContent.sources; - expect(restored).toMatchObject([manual, oldWebhook]); - expect((await tool("update_trigger", { ...update, sources: [manual, newWebhook], events: [manual, oldWebhook] })).isError).toBe(true); - expect((await get()).structuredContent.sources).toEqual(restored); + 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 () => { diff --git a/packages/docs/llms-full.txt b/packages/docs/llms-full.txt index 6ed314e4..247ad3d1 100644 --- a/packages/docs/llms-full.txt +++ b/packages/docs/llms-full.txt @@ -314,9 +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. Older MCP clients may send `events` -instead; send only one of the two fields. 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 diff --git a/packages/docs/mcp/tools.mdx b/packages/docs/mcp/tools.mdx index f25ce2eb..6b132d71 100644 --- a/packages/docs/mcp/tools.mdx +++ b/packages/docs/mcp/tools.mdx @@ -87,9 +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. Older MCP clients may send `events` -instead; send only one of the two fields. 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