stop_intensive_chat
End and clean up an active intensive chat session on MCP server 'interactive-mcp'. Call this tool to close the console window, free system resources, and mark the session as complete once all necessary information has been gathered via 'ask_intensive_chat'.
Instructions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sessionId | Yes | ID of the intensive chat session to stop |
Implementation Reference
- Core handler function that stops the intensive chat session: writes close signal, kills process, marks inactive, cleans up directory and removes from active sessions.export async function stopIntensiveChatSession( sessionId: string, ): Promise<boolean> { const session = activeSessions[sessionId]; if (!session || !session.isActive) { return false; // Session doesn't exist or is already inactive } // Write close signal file const closeFilePath = path.join(session.outputDir, 'close-session.txt'); await fs.writeFile(closeFilePath, '', 'utf8'); // Give the process some time to exit gracefully await new Promise((resolve) => setTimeout(resolve, 500)); try { // Force kill the process if it's still running if (!session.process.killed) { // Kill process group on Unix-like systems, standard kill on Windows try { if (os.platform() !== 'win32') { process.kill(-session.process.pid!, 'SIGTERM'); } else { process.kill(session.process.pid!, 'SIGTERM'); } } catch { // console.error("Error killing process:", killError); // Fallback or ignore if process already exited or group kill failed } } } catch { // Process might have already exited } // Mark session as inactive session.isActive = false; // Clean up session directory after a delay setTimeout(() => { // Use void to mark intentionally unhandled promise void (async () => { try { await fs.rm(session.outputDir, { recursive: true, force: true }); } catch { // Ignore errors during cleanup } // Remove from active sessions delete activeSessions[sessionId]; })(); }, 2000); return true; }
- src/index.ts:298-341 (registration)MCP server tool registration for 'stop_intensive_chat', including schema, description, and wrapper handler that calls the core stopIntensiveChatSession function.if (isToolEnabled('stop_intensive_chat')) { // Use properties from the imported intensiveChatTools object server.tool( 'stop_intensive_chat', // Description is a string here typeof intensiveChatTools.stop.description === 'function' ? intensiveChatTools.stop.description(globalTimeoutSeconds) // Should not happen, but safe : intensiveChatTools.stop.description, intensiveChatTools.stop.schema, // Use schema property async (args) => { // Use inferred args type const { sessionId } = args; // Check if session exists if (!activeChatSessions.has(sessionId)) { return { content: [ { type: 'text', text: 'Error: Invalid or expired session ID.' }, ], }; } try { // Stop the session const success = await stopIntensiveChatSession(sessionId); // Remove session from map if successful if (success) { activeChatSessions.delete(sessionId); } const message = success ? 'Session stopped successfully.' : 'Session not found or already stopped.'; return { content: [{ type: 'text', text: message }] }; } catch (error: unknown) { let errorMessage = 'Failed to stop intensive chat session.'; if (error instanceof Error) { errorMessage = `Failed to stop intensive chat session: ${error.message}`; } else if (typeof error === 'string') { errorMessage = `Failed to stop intensive chat session: ${error}`; } return { content: [{ type: 'text', text: errorMessage }] }; } }, ); }
- Tool schema definition including input parameters (sessionId), Zod schema, capability, and detailed description for the stop_intensive_chat tool.const stopCapability: ToolCapabilityInfo = { description: 'Stop and close an active intensive chat session.', parameters: { type: 'object', properties: { sessionId: { type: 'string', description: 'ID of the intensive chat session to stop', }, }, required: ['sessionId'], }, }; const stopDescription: ToolRegistrationDescription = `<description> Stop and close an active intensive chat session. **Must be called** after all questions have been asked using 'ask_intensive_chat'. </description> <importantNotes> - (!important!) Closes the console window for the intensive chat. - (!important!) Frees up system resources. - (!important!) **Should always be called** as the final step when finished with an intensive chat session, typically at the end of the response message where 'start_intensive_chat' was called. </importantNotes> <whenToUseThisTool> - When you've completed gathering all needed information via 'ask_intensive_chat'. - When the multi-step process requiring intensive chat is complete. - When you're ready to move on to processing the collected information. - When the user indicates they want to end the session (if applicable). - As the final action related to the intensive chat flow within a single response message. </whenToUseThisTool> <features> - Gracefully closes the console window - Cleans up system resources - Marks the session as complete </features> <bestPractices> - Always stop sessions when you're done to free resources - Provide a summary of the information collected before stopping </bestPractices> <parameters> - sessionId: ID of the intensive chat session to stop </parameters> <examples> - { "sessionId": "abcd1234" } </examples>`; const stopSchema: ZodRawShape = { sessionId: z.string().describe('ID of the intensive chat session to stop'), }; const stopToolDefinition: ToolDefinition = { capability: stopCapability, description: stopDescription, schema: stopSchema, };