Skip to main content
Glama

stop_intensive_chat

Close an active intensive chat session to free system resources and mark the session as complete after gathering all needed information.

Instructions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesID of the intensive chat session to stop

Implementation Reference

  • The MCP server tool handler for 'stop_intensive_chat'. Validates session ID, calls the stop function, manages active sessions map, handles errors, and formats the tool response.
    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 }] }; } },
  • Core helper function that stops the intensive chat session: signals close 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; }
  • Tool definition including schema (stopSchema), capability, and description for 'stop_intensive_chat' used in registration.
    const stopToolDefinition: ToolDefinition = { capability: stopCapability, description: stopDescription, schema: stopSchema, };
  • src/index.ts:305-348 (registration)
    Conditional registration of the 'stop_intensive_chat' tool on the MCP server using schema and handler from imports.
    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 }] }; } }, ); }

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