Skip to content

Commit ea51e14

Browse files
kathiekiwiTrigger.dev RepoOps
authored andcommitted
feat(mcp): batch trigger tool for the MCP server
Mono-RevId: b5cf5037ebaed0dcbc902e4499610be64d2d497e
1 parent 6d21bd7 commit ea51e14

13 files changed

Lines changed: 1396 additions & 14 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
area: webapp
3+
type: feature
4+
---
5+
6+
The MCP server can now trigger a batch of up to 20 runs in one call, after you approve every item.

‎apps/webapp/app/mcp/gate/types.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ export type McpConfirmSpec<A = unknown> = {
2323
/**
2424
* The ability is undefined for `user: true` tools; a check that relies on it must deny then.
2525
* Return `{ action, subject, id? }` to name the missing permission; `id` narrows the token-scope check only.
26+
* Return `{ refuse }` to deny with that text.
2627
*/
2728
precheck?: (
2829
args: A,
2930
ability: RbacAbility | undefined,
3031
subject: McpSubject | null
31-
) => McpPrecheckDenial | void | Promise<McpPrecheckDenial | void>;
32+
) =>
33+
| McpPrecheckDenial
34+
| McpPreviewRefusal
35+
| void
36+
| Promise<McpPrecheckDenial | McpPreviewRefusal | void>;
3237
preview: (
3338
args: A,
3439
subject: McpSubject | null,
@@ -44,6 +49,8 @@ export type McpToolAuth =
4449
| {
4550
action: string;
4651
subject: string;
52+
/** The token scope that grants the action, when it is not `action:subject` itself. */
53+
scope?: string;
4754
confirm?: boolean | McpConfirmSpec;
4855
/** A project-wide subject passes when the right holds in any environment type; the tool checks each. */
4956
anyEnvType?: true;

‎apps/webapp/app/mcp/gate/withMcpToolAuth.server.ts‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { UrlElicitationRequiredError } from "@modelcontextprotocol/server";
22
import { RuntimeEnvironmentType } from "@trigger.dev/database";
33
import type { RbacResource } from "@trigger.dev/plugins";
4-
import { buildJwtAbility, CAPLESS_USER_ACTOR_SCOPES, type RbacAbility } from "@trigger.dev/rbac";
4+
import {
5+
buildJwtAbility,
6+
CAPLESS_USER_ACTOR_SCOPES,
7+
type RbacAbility,
8+
withActionAliases,
9+
} from "@trigger.dev/rbac";
510
import { logger } from "~/services/logger.server";
611
import { resolveAndRecheckUserActorClaims } from "~/services/personalAccessToken.server";
712
import { MCP_SCOPES, mcpResource } from "~/services/oauth/metadata.server";
@@ -89,8 +94,8 @@ const errorText = (text: string): McpToolResult => ({
8994
isError: true,
9095
});
9196

92-
const requiredScopes = (auth: { action: string; subject: string }) => [
93-
`${auth.action}:${auth.subject}`,
97+
const requiredScopes = (auth: { action: string; subject: string; scope?: string }) => [
98+
auth.scope ?? `${auth.action}:${auth.subject}`,
9499
];
95100

96101
export function missingScopes(
@@ -101,9 +106,10 @@ export function missingScopes(
101106
if ("public" in auth || identity.kind !== "uat") return [];
102107
const cap = identity.cap ?? CAPLESS_USER_ACTOR_SCOPES;
103108
const scope = requiredScopes(auth)[0];
109+
const ability = withActionAliases(buildJwtAbility(cap));
104110
const allowed = resource
105-
? buildJwtAbility(cap).can(auth.action, resource)
106-
: buildJwtAbility(cap).can(auth.action, { type: auth.subject }) ||
111+
? ability.can(auth.action, resource)
112+
: ability.can(auth.action, { type: auth.subject }) ||
107113
cap.some((s) => s.startsWith(`${scope}:`));
108114
return allowed ? [] : [scope];
109115
}
@@ -307,6 +313,10 @@ export function withMcpToolAuth<TArgs>(
307313
typeof approval === "object"
308314
? await approval.precheck?.(args, authorization.ability, subject)
309315
: undefined;
316+
if (precheck && typeof precheck === "object" && "refuse" in precheck) {
317+
outcome = "forbidden";
318+
return errorText(precheck.refuse);
319+
}
310320
if (precheck !== undefined) {
311321
const named = precheck === "forbidden" ? null : namedPermission(precheck);
312322
if (!named && precheck !== "forbidden") {

‎apps/webapp/app/mcp/registry.server.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import { webhooksReadTools } from "./tools/webhooksRead.server";
5454
import { agentChatTools } from "./tools/agentChat.server";
5555
import { alertsManageTools } from "./tools/alertsManage.server";
5656
import { alertsWriteTools } from "./tools/alertsWrite.server";
57+
import { batchTriggerTools } from "./tools/batchTrigger.server";
5758
import { bulkActionsWriteTools } from "./tools/bulkActionsWrite.server";
5859
import { dashboardsWriteTools } from "./tools/dashboardsWrite.server";
5960
import { errorsWriteTools } from "./tools/errorsWrite.server";
@@ -154,6 +155,7 @@ export const mcpTools: McpToolDefinition[] = assertUniqueToolNames([
154155
...bulkActionsWriteTools,
155156
...sessionsWriteTools,
156157
...tasksWriteTools,
158+
...batchTriggerTools,
157159
...schedulesWriteTools,
158160
...webhooksWriteTools,
159161
...webhooksEndpointWriteTools,

0 commit comments

Comments
 (0)