feat(cron): per-task MCP server toggle in web UI#36
Conversation
Each scheduled task now has its own list of MCP servers that can be toggled on or off independently in the web UI editor dialog. Default is all off. When enabled servers are set, only those MCP tools are available to the task's runs. When null/empty (existing tasks), all MCP servers remain available for backward compatibility. - Add mcp_servers JSON column to cron_task table - Add mcpServers field to Cron Task/CreateInput/UpdateInput schemas - Pass enabled MCP servers to session metadata in the cron scheduler - Filter MCP tools in prompt.ts based on session metadata - Add MCP server toggle list with switches in cron editor dialog - Add i18n translations for new MCP servers section Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds per-cron-task MCP server allowlisting so cron runs can be constrained to a selected subset of MCP tools, with storage in the cron task DB row and UI switches in the cron task editor.
Changes:
- Persist
mcp_serversoncron_task(schema + migration) and plumb through cron create/update. - Attach task MCP allowlist to cron run session metadata and filter MCP tools during prompt tool resolution.
- Add UI for per-task MCP server selection and client/types/i18n wiring.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/codeplane/src/session/session.ts | Extends session creation interface to accept metadata. |
| packages/codeplane/src/session/prompt.ts | Filters MCP tools based on session.metadata.enabledMcpServers. |
| packages/codeplane/src/server/routes/cron.ts | Accepts mcpServers on cron task creation requests. |
| packages/codeplane/src/cron/scheduler.ts | Passes cron task MCP selection into session metadata for cron runs. |
| packages/codeplane/src/cron/cron.ts | Adds mcpServers to cron task schemas and stores/loads mcp_servers. |
| packages/codeplane/src/cron/cron.sql.ts | Adds mcp_servers JSON text column to the cron task table schema. |
| packages/codeplane/migration/20260601130626_add_mcp_servers_to_cron_tasks/snapshot.json | Updates migration snapshot to include the new column. |
| packages/codeplane/migration/20260601130626_add_mcp_servers_to_cron_tasks/migration.sql | Migration adding mcp_servers column. |
| packages/app/src/utils/cron-client.ts | Adds mcpServers to cron task/create/update types. |
| packages/app/src/pages/cron.tsx | Adds MCP server toggles to the cron editor and submits selection. |
| packages/app/src/i18n/en.ts | Adds translations for MCP server selection UI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const sanitizeMcp = (s: string) => s.replace(/[^a-zA-Z0-9_-]/g, "_") | ||
| const enabledMcpServers = input.session.metadata?.enabledMcpServers as string[] | undefined | ||
| const mcpTools = enabledMcpServers?.length | ||
| ? Object.fromEntries( | ||
| Object.entries(allMcpTools).filter(([key]) => | ||
| enabledMcpServers.some((name) => key.startsWith(sanitizeMcp(name) + "_")), | ||
| ), | ||
| ) | ||
| : allMcpTools |
| const sanitizeMcp = (s: string) => s.replace(/[^a-zA-Z0-9_-]/g, "_") | ||
| const enabledMcpServers = input.session.metadata?.enabledMcpServers as string[] | undefined | ||
| const mcpTools = enabledMcpServers?.length |
| metadata: task.mcpServers?.length | ||
| ? { enabledMcpServers: task.mcpServers } | ||
| : undefined, |
| last_run_status: null, | ||
| last_error: null, | ||
| next_run_at: nextRun, | ||
| mcp_servers: input.mcpServers ?? null, | ||
| time_created: now, |
| agent: store.agent.trim() || null, | ||
| model: store.model.trim() || null, | ||
| status: store.status, | ||
| mcpServers: store.mcpServers.length > 0 ? store.mcpServers : null, | ||
| } |
| agent: store.agent.trim() || undefined, | ||
| model: store.model.trim() || undefined, | ||
| status: store.status, | ||
| mcpServers: store.mcpServers.length > 0 ? store.mcpServers : undefined, | ||
| } |
Review: per-task MCP server toggleStatus: Superseded by PR #37 All CI checks are green and the implementation is sound. However, PR #37 contains identical changes to all 11 files in this PR plus the additional LLM prompt cache stability fix. These two PRs cannot be merged independently due to critical conflicts on the migration file, schema changes, prompt filtering, session metadata, and UI code. Closing this PR in favor of #37, which is the complete package. If you want to keep these separate, rebase #37 onto #36 and remove the duplicate MCP toggle files (keeping only llm.ts). |
|
Closing as superseded by PR #37, which contains all the MCP server toggle changes from this PR plus the additional LLM prompt cache stability fix. The two PRs cannot be merged independently due to critical conflicts on 11 shared files. If you prefer to keep them separate, rebase #37 onto this branch and remove the duplicate MCP toggle files (keeping only llm.ts changes). |
…ystem message layout Includes the complete MCP server toggle feature (superseding PR #36) plus the 2-part system message compaction for prompt cache stability.
Summary
Makes it possible in the web UI to turn individual MCP servers on or off per automated (cron) task. Each task gets its own set of MCP server switches in the editor dialog. By default, all MCP servers are off for new tasks. When enabled servers are set, only those MCP tools are available to the task's agent runs.
Changes
Backend
packages/codeplane/src/cron/cron.sql.ts— Addedmcp_serversJSON text column tocron_tasktablepackages/codeplane/src/cron/cron.ts— AddedmcpServers: string[]field toTask,CreateInput, andUpdateInputschemas; updatedtaskFromRow,create(), andupdate()to store/retrieve the fieldpackages/codeplane/src/cron/scheduler.ts— Passes task'smcpServersto session metadata asenabledMcpServerswhen creating a cron run sessionpackages/codeplane/src/session/prompt.ts— Filters MCP tools inresolveToolsbased on session metadataenabledMcpServers(null/missing = all servers available, preserving backward compatibility)packages/codeplane/src/session/session.ts— Addedmetadatato theSession.create()interface andCreateInputschemapackages/codeplane/src/server/routes/cron.ts— AddedmcpServersto the create input validation zod schemapackages/codeplane/migration/— GeneratedALTER TABLEmigration to add themcp_serverscolumnWeb UI
packages/app/src/pages/cron.tsx— Added MCP server toggle list withSwitchcomponents in the cron editor dialog, populated fromglobalSync.data.config.mcppackages/app/src/utils/cron-client.ts— AddedmcpServerstoCronTask,CronCreateInput, andCronUpdateInputtypespackages/app/src/i18n/en.ts— Addedcron.field.mcpServers,cron.field.mcpServers.empty, andcron.field.mcpServers.helptranslationsVerification
bun turbo typecheck— passes (codeplane has only pre-existingpty.node.tserror, app passes cleanly)bun lint— 0 errors