Skip to main content
Glama

end_codegen_session

Terminates a code generation session in the MCP Playwright server and generates the corresponding test file using the specified session ID.

Instructions

End a code generation session and generate the test file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesID of the session to end

Implementation Reference

  • The complete tool definition including name, description, parameters schema, and the main handler function that ends the codegen session, generates the Playwright test file, and cleans up browser resources.
    export const endCodegenSession: Tool = {
      name: 'end_codegen_session',
      description: 'End the current code generation session and generate Playwright test',
      parameters: {
        type: 'object',
        properties: {
          sessionId: {
            type: 'string',
            description: 'ID of the session to end'
          }
        },
        required: ['sessionId']
      },
      handler: async ({ sessionId }: { sessionId: string }) => {
        try {
          const recorder = ActionRecorder.getInstance();
          const session = recorder.endSession(sessionId);
    
          if (!session) {
            throw new Error(`Session ${sessionId} not found`);
          }
    
          if (!session.options) {
            throw new Error(`Session ${sessionId} has no options configured`);
          }
    
          const generator = new PlaywrightGenerator(session.options);
          const result = await generator.generateTest(session);
    
          // Double check output directory exists
          const outputDir = path.dirname(result.filePath);
          await fs.mkdir(outputDir, { recursive: true });
          
          // Write test file
          try {
            await fs.writeFile(result.filePath, result.testCode, 'utf-8');
          } catch (writeError: any) {
            throw new Error(`Failed to write test file: ${writeError.message}`);
          }
    
          // Close Playwright browser and cleanup
          try {
            if (global.browser?.isConnected()) {
              await global.browser.close();
            }
          } catch (browserError: any) {
            console.warn('Failed to close browser:', browserError.message);
          } finally {
            global.browser = undefined;
            global.page = undefined;
          }
    
          const absolutePath = path.resolve(result.filePath);
    
          return {
            filePath: absolutePath,
            outputDirectory: outputDir,
            testCode: result.testCode,
            message: `Generated test file at: ${absolutePath}\nOutput directory: ${outputDir}`
          };
        } catch (error: any) {
          // Ensure browser cleanup even on error
          try {
            if (global.browser?.isConnected()) {
              await global.browser.close();
            }
          } catch {
            // Ignore cleanup errors
          } finally {
            global.browser = undefined;
            global.page = undefined;
          }
          
          throw new Error(`Failed to end codegen session: ${error.message}`);
        }
      }
    };
  • src/tools.ts:36-49 (registration)
    MCP tool registration definition providing the input schema for end_codegen_session as part of createToolDefinitions().
    {
      name: "end_codegen_session",
      description: "End a code generation session and generate the test file",
      inputSchema: {
        type: "object",
        properties: {
          sessionId: { 
            type: "string", 
            description: "ID of the session to end" 
          }
        },
        required: ["sessionId"]
      }
    },
  • Runtime dispatch/registration in handleToolCall switch statement that invokes the endCodegenSession.handler for the 'end_codegen_session' tool name.
      case 'start_codegen_session':
        return await handleCodegenResult(startCodegenSession.handler(args));
      case 'end_codegen_session':
        return await handleCodegenResult(endCodegenSession.handler(args));
      case 'get_codegen_session':
        return await handleCodegenResult(getCodegenSession.handler(args));
      case 'clear_codegen_session':
        return await handleCodegenResult(clearCodegenSession.handler(args));
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions ending a session and generating a test file, but fails to describe critical behaviors: whether this action is destructive (e.g., deletes session data), requires specific permissions, has side effects like file creation, or what happens if the session ID is invalid. This is inadequate for a tool that likely performs mutations.

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?

The description is a single, efficient sentence that front-loads the core action and outcome with zero wasted words. It is appropriately sized for a tool with one parameter and clear purpose, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the lack of annotations and output schema, and the tool's likely complexity (ending a session and generating files), the description is incomplete. It does not explain the result format, error conditions, or behavioral nuances, leaving significant gaps for the agent to operate effectively in a code generation context.

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 description coverage is 100%, with the single parameter 'sessionId' well-documented in the schema. The description does not add any semantic details beyond what the schema provides (e.g., format or source of the ID), so it meets the baseline score of 3 for high schema coverage without extra value.

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

Purpose4/5

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

The description clearly states the tool's purpose with a specific verb ('End') and resource ('a code generation session'), and it adds the outcome ('and generate the test file'). However, it does not explicitly distinguish this tool from its sibling 'clear_codegen_session', which might have overlapping functionality, leaving some ambiguity in differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, such as 'clear_codegen_session' or 'get_codegen_session'. It lacks context on prerequisites (e.g., needing an active session) or exclusions, leaving the agent to infer usage from the tool name alone.

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

Install Server

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/executeautomation/mcp-playwright'

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