Skip to main content
Glama
eva-wanxin-git

Windows Automation MCP Server

browser_get_text

Extract text from web elements using CSS selectors to automate data collection or verification in browser automation workflows.

Instructions

获取元素文本

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS 选择器
sessionIdNo会话 ID(可选)

Implementation Reference

  • The core handler function for the 'browser_get_text' tool. It retrieves the Puppeteer page for the session, waits for the selector, and extracts the text content of the element.
    async getText(selector, sessionId = 'default') {
      try {
        const page = this.pages.get(sessionId);
        if (!page) {
          return { success: false, error: '浏览器未启动' };
        }
    
        await page.waitForSelector(selector, { timeout: 5000 });
        const text = await page.$eval(selector, el => el.textContent);
    
        return { success: true, selector, text };
      } catch (error) {
        return { success: false, error: error.message };
      }
    }
  • The tool schema definition including name, description, and inputSchema for validation of parameters (selector required, sessionId optional).
    {
      name: 'browser_get_text',
      description: '获取元素文本',
      inputSchema: {
        type: 'object',
        properties: {
          selector: { type: 'string', description: 'CSS 选择器' },
          sessionId: { type: 'string', description: '会话 ID(可选)' },
        },
        required: ['selector'],
      },
    },
  • Registers 'browser_get_text' in the list of tools this class can handle via the canHandle method.
    canHandle(toolName) {
      const tools = ['browser_launch', 'browser_navigate', 'browser_click', 
                     'browser_type', 'browser_screenshot', 'browser_get_text', 'browser_close'];
      return tools.includes(toolName);
    }
  • Registers the handler dispatch for 'browser_get_text' in the executeTool switch statement, calling the getText method.
    async executeTool(name, args) {
      if (!this.puppeteerAvailable) {
        return { 
          success: false, 
          error: 'puppeteer 未安装。请运行: npm install puppeteer' 
        };
      }
    
      switch (name) {
        case 'browser_launch':
          return await this.launchBrowser(args.headless, args.sessionId);
        case 'browser_navigate':
          return await this.navigate(args.url, args.sessionId);
        case 'browser_click':
          return await this.click(args.selector, args.sessionId);
        case 'browser_type':
          return await this.type(args.selector, args.text, args.sessionId);
        case 'browser_screenshot':
          return await this.screenshot(args.path, args.fullPage, args.sessionId);
        case 'browser_get_text':
          return await this.getText(args.selector, args.sessionId);
        case 'browser_close':
          return await this.closeBrowser(args.sessionId);
        default:
          throw new Error(`未知工具: ${name}`);
      }
    }
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 action without behavioral details. It doesn't disclose error handling (e.g., if selector fails), performance (e.g., timeouts), side effects, or return format. For a tool interacting with a browser, this leaves critical behavior unspecified.

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

Conciseness4/5

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

The description is a single phrase '获取元素文本', which is concise and front-loaded. However, it's overly terse—it could benefit from slightly more detail without losing efficiency, as it under-specifies the tool's scope.

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 no annotations, no output schema, and a tool that interacts with a browser (complex environment), the description is incomplete. It doesn't cover return values, error cases, or dependencies on other tools like 'browser_launch', making it inadequate for safe and effective use by an AI agent.

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 parameters are documented in the schema. The description adds no meaning beyond the schema's 'CSS 选择器' (CSS selector) and '会话 ID(可选)' (session ID optional). It doesn't explain selector syntax examples or session context, resulting in baseline adequacy.

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

Purpose3/5

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

The description '获取元素文本' (Get element text) states a clear verb ('获取' - get) and resource ('元素文本' - element text), but it's vague about what type of element (browser DOM element) and doesn't distinguish from sibling tools like 'get_clipboard' or 'read_file' that also retrieve text. It's functional but lacks specificity.

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 on when to use this tool vs. alternatives is provided. It doesn't mention prerequisites (e.g., requires an active browser session), context (e.g., use after navigation), or differentiate from similar tools like 'browser_screenshot' for visual capture. The description alone offers no usage context.

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/eva-wanxin-git/windows-automation-mcp'

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