Skip to content

fix: add preset support to MCP tools (#24694)#24889

Merged
johnstcn merged 1 commit into
release/2.33from
cj/r233/mcp-presets
May 1, 2026
Merged

fix: add preset support to MCP tools (#24694)#24889
johnstcn merged 1 commit into
release/2.33from
cj/r233/mcp-presets

Conversation

@johnstcn

@johnstcn johnstcn commented May 1, 2026

Copy link
Copy Markdown
Member

The chat tools (read_template, create_workspace) did not surface or respect template version presets. Presets were invisible to the LLM and preset parameter defaults were never applied at workspace creation. The toolsdk MCP surface had the same gap (ref #24695, now subsumed here).

What this changes

  • read_template returns presets with id, name, default, description, icon, parameters, and desired_prebuild_instances (when set), so the LLM can pick the right preset and prefer prebuilt-backed ones.
  • create_workspace accepts a preset_id. The wsbuilder applies preset parameter defaults and may claim a prebuilt workspace.
  • start_workspace does not accept a preset. Presets are a creation-time choice; subsequent starts use the workspace's existing version and parameters. Users who need a specific preset or version on an existing chat can create the workspace out-of-band (CLI / UI / API) with the desired configuration and attach the chat to it.
  • toolsdk gains GetTemplate (with presets including desired_prebuild_instances), preset support on CreateWorkspace, and preset + rich_parameters support on CreateWorkspaceBuild. The template_version_preset_id description warns about preset/version affinity.

🤖 Generated with Coder Agents and reviewed by a human.

(cherry picked from commit 04cc983)

The chat tools (`read_template`, `create_workspace`) did not surface or
respect template version presets. Presets were invisible to the LLM and
preset parameter defaults were never applied at workspace creation. The
`toolsdk` MCP surface had the same gap (ref #24695, now subsumed here).

## What this changes

- **`read_template`** returns presets with `id`, `name`, `default`,
`description`, `icon`, `parameters`, and `desired_prebuild_instances`
(when set), so the LLM can pick the right preset and prefer
prebuilt-backed ones.
- **`create_workspace`** accepts a `preset_id`. The wsbuilder applies
preset parameter defaults and may claim a prebuilt workspace.
- **`start_workspace`** does *not* accept a preset. Presets are a
creation-time choice; subsequent starts use the workspace's existing
version and parameters. Users who need a specific preset or version on
an existing chat can create the workspace out-of-band (CLI / UI / API)
with the desired configuration and attach the chat to it.
- **`toolsdk`** gains `GetTemplate` (with presets including
`desired_prebuild_instances`), preset support on `CreateWorkspace`, and
preset + `rich_parameters` support on `CreateWorkspaceBuild`. The
`template_version_preset_id` description warns about preset/version
affinity.

> 🤖 Generated with [Coder Agents](https://coder.com/agents) and reviewed by a human.

Co-authored-by: Max schwenk <maschwenk@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
(cherry picked from commit 04cc983)
@johnstcn johnstcn self-assigned this May 1, 2026
Copilot AI review requested due to automatic review settings May 1, 2026 14:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds end-to-end support for template version presets across chat tools and the codersdk/toolsdk MCP surface so agents can discover presets and apply them during workspace creation/builds.

Changes:

  • Exposes presets (including parameters and desired_prebuild_instances) via read_template (chattool) and new coder_get_template (toolsdk).
  • Adds preset selection to workspace creation/build surfaces (preset_id on chat create_workspace; template_version_preset_id on toolsdk create_workspace / create_workspace_build).
  • Expands integration tests to cover preset propagation, rich parameters, validation cases, and “require active version” start behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
codersdk/toolsdk/toolsdk.go Adds coder_get_template, adds preset + rich parameter handling to create workspace/build tool args and handlers.
codersdk/toolsdk/toolsdk_test.go Extends tool integration tests to cover preset propagation, rich parameters, and new GetTemplate tool behavior.
coderd/x/chatd/chattool/readtemplate.go Includes presets (and preset params + desired prebuild instances) in read_template responses when present.
coderd/x/chatd/chattool/readtemplate_test.go New tests asserting read_template preset shape, params, and omit-when-empty behavior.
coderd/x/chatd/chattool/createworkspace.go Adds preset_id argument and forwards it as TemplateVersionPresetID to workspace creation requests.
coderd/x/chatd/chattool/createworkspace_test.go Adds unit tests ensuring preset_id validation and request propagation in chattool create_workspace.
coderd/x/chatd/chattool/startworkspace.go No functional change (formatting only).
coderd/export_test.go Exposes chatStartWorkspace to external-package tests via ChatStartWorkspace alias.
coderd/exp_chats_test.go Adds end-to-end test covering RequireActiveVersion auto-update on chat start path and ensuring no preset is applied.
coderd/exp_chats.go Documents the exported test alias rationale for chatStartWorkspace.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +861 to +865
transition := codersdk.WorkspaceTransition(args.Transition)
// Presets and rich_parameters are scoped to a starting build;
// they have no meaning on stop or delete transitions. Surface
// both violations at once via errors.Join so agents fix them
// in a single round-trip instead of one tool call per error.

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateWorkspaceBuild treats any non-"start" transition as stop/delete for the purpose of validating template_version_preset_id and rich_parameters. If args.transition is invalid (runtime doesn’t enforce the schema enum), the user will get misleading errors about preset/params rather than an actionable "transition must be one of start/stop/delete" message. Consider validating args.Transition first (e.g., switch on the parsed transition and return a clear error on default) before applying the non-start field restrictions.

Copilot uses AI. Check for mistakes.
Comment on lines +180 to +183
// Surface the prebuild count when set so the LLM can prefer
// presets backed by prebuilt workspaces. Match the toolsdk
// `desired_prebuild_instances` key for cross-surface consistency.
if p.DesiredInstances.Valid && p.DesiredInstances.Int32 > 0 {

Copilot AI May 1, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_template only includes desired_prebuild_instances when DesiredInstances > 0. The REST preset surface (coderd/presets.go -> codersdk.Preset.DesiredPrebuildInstances) includes the field whenever DesiredInstances is set, even if it’s 0. Filtering out 0 here makes the chattool response inconsistent with coder_get_template/codersdk and prevents callers from distinguishing "unset" vs "explicitly 0". Consider including desired_prebuild_instances whenever DesiredInstances.Valid is true and letting the LLM interpret 0 as "no prebuilds".

Suggested change
// Surface the prebuild count when set so the LLM can prefer
// presets backed by prebuilt workspaces. Match the toolsdk
// `desired_prebuild_instances` key for cross-surface consistency.
if p.DesiredInstances.Valid && p.DesiredInstances.Int32 > 0 {
// Surface the prebuild count whenever it is explicitly set so
// the response matches the toolsdk
// `desired_prebuild_instances` key, including explicit 0 to
// preserve the distinction between "unset" and "no prebuilds".
if p.DesiredInstances.Valid {

Copilot uses AI. Check for mistakes.
@matifali matifali requested review from f0ssel and jcjiang May 1, 2026 14:27
@johnstcn johnstcn merged commit eabb68d into release/2.33 May 1, 2026
70 of 75 checks passed
@johnstcn johnstcn deleted the cj/r233/mcp-presets branch May 1, 2026 15:26
@github-actions github-actions Bot locked and limited conversation to collaborators May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants