-
Notifications
You must be signed in to change notification settings - Fork 932
feat(mcp-v2): add agent spawn tools #4076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; | ||
| import { z } from "zod"; | ||
| import { createMcpCaller } from "../../caller"; | ||
| import { defineTool } from "../../define-tool"; | ||
| import { hostServiceMutation } from "../../host-service-client"; | ||
|
|
||
| export function register(server: McpServer): void { | ||
| defineTool(server, { | ||
| name: "agents_run", | ||
| description: | ||
| "Launch an agent inside an existing workspace. Resolves the host that owns the workspace, then runs the named agent preset (or HostAgentConfig instance) with the given prompt in a fresh terminal session. Use this to start a second agent in a workspace that already exists; for create-and-spawn in a single call, pass `agents` to workspaces_create instead.", | ||
| inputSchema: { | ||
| workspaceId: z | ||
| .string() | ||
| .uuid() | ||
| .describe("Workspace UUID to run the agent in."), | ||
| agent: z | ||
| .string() | ||
| .min(1) | ||
| .describe( | ||
| "Agent preset id (e.g. `claude`, `codex`) or HostAgentConfig instance UUID.", | ||
| ), | ||
| prompt: z.string().min(1).describe("Prompt sent to the agent."), | ||
| attachmentIds: z | ||
| .array(z.string().uuid()) | ||
| .optional() | ||
| .describe( | ||
| "Host-scoped attachment UUIDs. The host resolves these to absolute paths and appends them to the prompt.", | ||
| ), | ||
| }, | ||
| handler: async (input, ctx) => { | ||
| const caller = createMcpCaller(ctx); | ||
| const workspace = await caller.v2Workspace.getFromHost({ | ||
| organizationId: ctx.organizationId, | ||
| id: input.workspaceId, | ||
| }); | ||
| if (!workspace) { | ||
| throw new Error(`Workspace not found: ${input.workspaceId}`); | ||
| } | ||
|
|
||
| return hostServiceMutation< | ||
| { | ||
| workspaceId: string; | ||
| agent: string; | ||
| prompt: string; | ||
| attachmentIds?: string[]; | ||
| }, | ||
| { sessionId: string; label: string } | ||
| >( | ||
| { | ||
| relayUrl: ctx.relayUrl, | ||
| organizationId: ctx.organizationId, | ||
| hostId: workspace.hostId, | ||
| jwt: ctx.bearerToken, | ||
| }, | ||
| "agents.run", | ||
| { | ||
| workspaceId: input.workspaceId, | ||
| agent: input.agent, | ||
| prompt: input.prompt, | ||
| attachmentIds: input.attachmentIds, | ||
| }, | ||
| ); | ||
| }, | ||
| }); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
agents.runhost RPC can return{ ok: false; error: string }on business-logic failures (e.g. unknown agent preset), as evidenced by the discriminated unionworkspaces_createnow uses for the same per-agent results. Typing the return here as only{ sessionId: string; label: string }means a{ ok: false, error: "..." }payload from the host passes through silently: the MCP client receives a wrong shape withsessionId/labelasundefinedand never sees the error message.The response generic should mirror the union, and the
ok: falsebranch should surface the error:Prompt To Fix With AI