Skip to main content
Glama

close-browser

Closes a specific browser instance by its ID to manage resources during Vite development sessions.

Instructions

Closes a specific browser instance

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contextIdYesID of the browser to close

Implementation Reference

  • The main handler function for the 'close-browser' MCP tool. It takes a contextId, calls contextManager.closeContext(contextId), and returns a formatted success or error response.
    async ({ contextId }) => {
      try {
        const result = await contextManager.closeContext(contextId);
    
        if (result.success) {
          return {
            content: [
              {
                type: 'text',
                text: `Browser closed successfully: ${contextId}`
              }
            ]
          };
        } else {
          return {
            content: [
              {
                type: 'text',
                text: `Failed to close browser: ${result.error}`
              }
            ],
            isError: true
          };
        }
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        Logger.error(`Failed to close browser ${contextId}:`, error);
        return {
          content: [
            {
              type: 'text',
              text: `Failed to close browser: ${errorMessage}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod input schema for the close-browser tool, requiring a string contextId.
    {
      contextId: z.string().describe('ID of the browser to close')
    },
  • Registers the 'close-browser' tool using server.tool(), including description, schema, and inline handler.
    server.tool(
      'close-browser',
      'Closes a specific browser instance',
      {
        contextId: z.string().describe('ID of the browser to close')
      },
      async ({ contextId }) => {
        try {
          const result = await contextManager.closeContext(contextId);
    
          if (result.success) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Browser closed successfully: ${contextId}`
                }
              ]
            };
          } else {
            return {
              content: [
                {
                  type: 'text',
                  text: `Failed to close browser: ${result.error}`
                }
              ],
              isError: true
            };
          }
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          Logger.error(`Failed to close browser ${contextId}:`, error);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to close browser: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Core helper method in ContextManager that performs the actual browser context closure, map cleanup, shared browser management, and database deactivation.
    async closeContext(contextId: string): Promise<ContextOperationResult> {
      try {
        const contextInstance = this.contexts.get(contextId);
        if (!contextInstance) {
          return {
            success: false,
            error: `Context '${contextId}' not found`
          };
        }
    
        Logger.info(`Closing context: ${contextId}`);
    
        // Close context
        await contextInstance.context.close();
    
        // Remove from map
        this.contexts.delete(contextId);
        
        // Update shared browser context count
        if (this.sharedBrowser) {
          this.sharedBrowser.contextCount--;
          
          // Close shared browser if no contexts remain
          if (this.sharedBrowser.contextCount === 0) {
            Logger.info('Closing shared browser - no contexts remaining');
            await this.sharedBrowser.browser.close();
            this.sharedBrowser = null;
          }
        }
    
        // Update database to mark as inactive
        const db = getScreenshotDB();
        db.deactivateBrowser(contextId); // TODO: rename to deactivateContext
    
        Logger.info(`Context closed successfully: ${contextId}`);
    
        return {
          success: true,
          contextId
        };
    
      } catch (error) {
        Logger.error(`Failed to close context ${contextId}:`, error);
        return {
          success: false,
          error: error instanceof Error ? error.message : String(error)
        };
      }
    }
  • src/index.ts:82-82 (registration)
    Top-level call to registerBrowserManagerTools which sets up all browser manager tools including 'close-browser'.
    const contextManager = registerBrowserManagerTools(server);
Behavior2/5

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

With no annotations, the description carries full burden but only states the basic action. It doesn't disclose behavioral traits such as whether closing is destructive, if it requires specific permissions, what happens to open tabs, or error conditions. This is inadequate for a mutation tool with zero annotation coverage.

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 with zero waste, front-loading the core action. It's appropriately sized for a simple tool, making it easy 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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavior, side effects, or response format, leaving significant gaps in understanding how to use the tool effectively in 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%, so the schema already documents the single parameter 'contextId'. The description adds no additional meaning beyond implying it identifies the browser to close, meeting the baseline 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 action ('closes') and resource ('a specific browser instance'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'list-browsers' or 'start-browser' beyond the obvious action difference, missing explicit sibling distinction.

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?

No guidance is provided on when to use this tool versus alternatives or any prerequisites. The description implies usage for closing a browser but doesn't specify context like after operations or error handling, leaving the agent to infer usage scenarios.

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

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/ESnark/blowback'

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