stop_agent
Stop a loaded agent by disconnecting from relays. The active agent remains running.
Instructions
Stop a loaded agent. Disconnects from relays. Cannot stop the active agent.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes |
Implementation Reference
- packages/mcp/src/tools/agent.ts:341-365 (handler)The handler function for the 'stop_agent' tool. It prevents stopping the active agent, checks if the agent is loaded, disconnects from Nostr relays via agent.client.close(), scrubs secret key bytes from memory, and removes the agent from the registry.
defineTool({ name: 'stop_agent', description: 'Stop a loaded agent. Disconnects from relays. Cannot stop the active agent.', schema: StopAgentSchema, async handler(ctx, input) { if (input.name === ctx.activeAgentName) { return errorResult('Cannot stop the active agent. Switch to another agent first.'); } const agent = ctx.registry.get(input.name); if (!agent) { return errorResult(`Agent "${input.name}" is not loaded.`); } agent.client.close(); // best-effort scrub of secret key bytes before dropping the agent. if (agent.solanaKeypair) { agent.solanaKeypair.secretKey.fill(0); } agent.identity.scrub(); ctx.registry.delete(input.name); return textResult(`Agent "${input.name}" stopped and removed.`); }, }), - Zod schema for stop_agent input validation - expects a single required field 'name' (string).
const StopAgentSchema = z.object({ name: z.string(), }); - packages/mcp/src/server.ts:32-40 (registration)agentTools (which includes stop_agent) is aggregated into allTools and registered with the MCP server via ListToolsRequestSchema/CallToolRequestSchema handlers.
const allTools: ToolDefinition[] = [ ...discoveryTools, ...customerTools, ...walletTools, ...dashboardTools, ...agentTools, ...feedbackContactsTools, ...policiesTools, ]; - packages/mcp/src/tools/agent.ts:124-124 (registration)stop_agent is exported as part of the agentTools array from agent.ts, alongside create_agent, switch_agent, and list_agents.
export const agentTools: ToolDefinition[] = [ - The defineTool helper function that constructs a ToolDefinition with type-checked handler against the schema.
export function defineTool<S extends z.ZodTypeAny>(def: { name: string; description: string; schema: S; handler: (ctx: AgentContext, input: z.infer<S>) => Promise<ToolResult>; }): ToolDefinition { return def as unknown as ToolDefinition; }