Skip to content

Commit 8dd0dc5

Browse files
committed
add agent mcp tools
1 parent d8615f6 commit 8dd0dc5

File tree

6 files changed

+459
-2
lines changed

6 files changed

+459
-2
lines changed

apps/webapp/app/routes/realtime.v1.streams.$runId.$streamId.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export const loader = createLoaderApiRoute(
8080
allowJWT: true,
8181
corsStrategy: "all",
8282
findResource: async (params, auth) => {
83-
return $replica.taskRun.findFirst({
83+
const run = await $replica.taskRun.findFirst({
8484
where: {
8585
friendlyId: params.runId,
8686
runtimeEnvironmentId: auth.environment.id,
@@ -93,6 +93,7 @@ export const loader = createLoaderApiRoute(
9393
},
9494
},
9595
});
96+
return run;
9697
},
9798
authorization: {
9899
action: "read",

packages/cli-v3/src/mcp/config.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,28 @@ export const toolsMetadata = {
213213
description:
214214
"Reactivate a previous dashboard-sourced version as the active override. Use get_prompt_versions to find dashboard versions that can be reactivated.",
215215
},
216+
list_agents: {
217+
name: "list_agents",
218+
title: "List Agents",
219+
description:
220+
"List all chat agents in the current worker. Agents are tasks created with chat.agent() or chat.customAgent(). Use start_agent_chat with an agent's slug to start a conversation.",
221+
},
222+
start_agent_chat: {
223+
name: "start_agent_chat",
224+
title: "Start Agent Chat",
225+
description:
226+
"Start a conversation with a chat agent. Returns a chatId you can use with send_agent_message. Optionally preloads the agent so it initializes before the first message.",
227+
},
228+
send_agent_message: {
229+
name: "send_agent_message",
230+
title: "Send Agent Message",
231+
description:
232+
"Send a message to an active agent chat and get the full response text back. Use the chatId from start_agent_chat. The agent remembers full context from previous messages in the same chat.",
233+
},
234+
close_agent_chat: {
235+
name: "close_agent_chat",
236+
title: "Close Agent Chat",
237+
description:
238+
"Close an agent chat conversation. The agent exits its loop gracefully. Without this, the agent will close on its own when its idle timeout expires.",
239+
},
216240
};

packages/cli-v3/src/mcp/tools.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import {
2929
removePromptOverrideTool,
3030
reactivatePromptOverrideTool,
3131
} from "./tools/prompts.js";
32+
import { listAgentsTool } from "./tools/agents.js";
33+
import {
34+
startAgentChatTool,
35+
sendAgentMessageTool,
36+
closeAgentChatTool,
37+
} from "./tools/agentChat.js";
3238
import { respondWithError } from "./utils.js";
3339

3440
/** Tool names that perform write/mutating operations. */
@@ -43,6 +49,9 @@ const WRITE_TOOLS = new Set([
4349
updatePromptOverrideTool.name,
4450
removePromptOverrideTool.name,
4551
reactivatePromptOverrideTool.name,
52+
startAgentChatTool.name,
53+
sendAgentMessageTool.name,
54+
closeAgentChatTool.name,
4655
]);
4756

4857
export function registerTools(context: McpContext) {
@@ -80,6 +89,10 @@ export function registerTools(context: McpContext) {
8089
updatePromptOverrideTool,
8190
removePromptOverrideTool,
8291
reactivatePromptOverrideTool,
92+
listAgentsTool,
93+
startAgentChatTool,
94+
sendAgentMessageTool,
95+
closeAgentChatTool,
8396
];
8497

8598
for (const tool of tools) {

0 commit comments

Comments
 (0)