Skip to main content
Glama
mikeysrecipes

interactive-mcp

stop_intensive_chat

Closes an active intensive chat session to free system resources and complete the conversation flow after gathering information.

Instructions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesID 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, schedules 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:298-341 (registration)
    MCP server tool registration for 'stop_intensive_chat', including schema, description, and thin wrapper handler calling stopIntensiveChatSession.
    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 (Zod), capability, and detailed description for 'stop_intensive_chat' used in registration.
    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,
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A4.5/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Given no annotations, the description carries full burden and discloses key behaviors: closes console window, frees system resources, marks session complete. It omits potential side effects like idempotency or error handling, but the core behavioral traits are well covered for a termination action.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Highly structured with clear sections (description, importantNotes, whenToUseThisTool, etc.). Every sentence adds value, and the core purpose is front-loaded. No unnecessary verbosity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with one required parameter and no output schema, the description is fully complete. It covers what it does, when to use, how to use (with example), and what to expect. No gaps remain for an agent to select and invoke correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% for the single parameter 'sessionId', with the schema providing a description. The description repeats the same parameter info without adding new semantic meaning, so baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states 'Stop and close an active intensive chat session' with a specific verb and resource. It clearly distinguishes from siblings like 'start_intensive_chat' and 'ask_intensive_chat' by noting it must be called after all questions have been asked.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides explicit when-to-use conditions: after completing 'ask_intensive_chat', when the multi-step process is complete, and as the final action. Also includes a strong directive that it 'must be called' and 'should always be called', leaving no ambiguity about its role in the workflow.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.