Skip to main content
Glama

stop_intensive_chat

End and close an active intensive chat session to free system resources. Use after completing all interactions with 'ask_intensive_chat' to cleanly terminate the session.

Instructions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesID of the intensive chat session to stop

Implementation Reference

  • Core implementation of the stop logic for intensive chat sessions: signals closure via file, terminates the child process, marks session inactive, and schedules directory cleanup.
    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:305-348 (registration)
    MCP server tool registration for 'stop_intensive_chat', including description, schema, and thin handler wrapper that validates the session ID and invokes 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 }] }; } }, ); }
  • Defines the tool capability (JSON schema for MCP), Zod input schema, detailed description, and tool definition object for 'stop_intensive_chat' used in registration.
    // === Stop Intensive Chat Definition === 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, };

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ttommyth/interactive-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server