Skip to main content
Glama
FuzzyCZX

MCP Communication Server

by FuzzyCZX

打开网页

open_web_page

Opens a specified URL in a new browser window via the MCP Communication Server, waits for WebSocket data from the page, and handles timeout settings for real-time interaction.

Instructions

在IDE中打开一个新的网页窗口显示指定的URL,并自动等待接收页面发送的WebSocket数据

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timeoutMsNo等待数据的超时时间(毫秒),默认10秒
urlYes
waitForDataNo是否等待页面发送数据,默认为true

Implementation Reference

  • The handler function opens the specified URL in the default system browser using platform-specific commands (cmd/start on Windows, open on macOS, xdg-open on Linux). It then optionally waits for data from the page via an HTTP API call to localhost:3003/api/wait-for-data, returning the received data or an error message.
    async ({ url, waitForData = true, timeoutMs = 10000 }: { 
      url: string; 
      waitForData?: boolean | undefined; 
      timeoutMs?: number | undefined; 
    }) => {
      try {
        let command: string;
        
        // 根据操作系统选择合适的命令
        if (process.platform === 'win32') {
          // Windows: 使用cmd /c start来确保正确打开浏览器
          command = `cmd /c start "" "${url}"`;
        } else if (process.platform === 'darwin') {
          command = `open "${url}"`;
        } else {
          command = `xdg-open "${url}"`;
        }
        
        await execAsync(command);
        
        if (!waitForData) {
          return {
            content: [{ 
              type: "text", 
              text: `成功打开网页: ${url}` 
            }]
          };
        }
        
        // 给页面一些时间来加载和建立WebSocket连接
        console.error("⏳ 等待页面加载并建立WebSocket连接...");
        await new Promise(resolve => setTimeout(resolve, 2000));
        
        // 等待页面发送数据
        try {
          console.error(`🔍 等待页面 ${url} 发送数据,超时时间: ${timeoutMs}ms`);
          const receivedData = await waitForPageDataViaAPI(timeoutMs);
          
          return {
            content: [{ 
              type: "text", 
              text: `成功打开网页并接收到数据: ${url}\n\n接收到的数据:\n${JSON.stringify(receivedData, null, 2)}` 
            }]
          };
        } catch (dataError) {
          // 如果等待数据超时,仍然返回成功打开页面的消息
          return {
            content: [{ 
              type: "text", 
              text: `成功打开网页: ${url}\n\n等待数据时出现问题: ${dataError instanceof Error ? dataError.message : '未知错误'}` 
            }]
          };
        }
        
      } catch (error) {
        return {
          content: [{ 
            type: "text", 
            text: `打开网页失败: ${error instanceof Error ? error.message : '未知错误'}` 
          }]
        };
      }
    }
  • Zod input schema defining parameters: url (required string URL), waitForData (optional boolean, default true), timeoutMs (optional number, default 10000). Part of the tool metadata.
    inputSchema: { 
      url: z.string().url("请提供有效的URL地址"),
      waitForData: z.boolean().optional().describe("是否等待页面发送数据,默认为true"),
      timeoutMs: z.number().optional().describe("等待数据的超时时间(毫秒),默认10秒")
    }
  • src/index.ts:60-133 (registration)
    Registers the 'open_web_page' tool on the MCP server with title, description, input schema, and handler function.
    server.registerTool("open_web_page",
      {
        title: "打开网页",
        description: "在IDE中打开一个新的网页窗口显示指定的URL,并自动等待接收页面发送的WebSocket数据",
        inputSchema: { 
          url: z.string().url("请提供有效的URL地址"),
          waitForData: z.boolean().optional().describe("是否等待页面发送数据,默认为true"),
          timeoutMs: z.number().optional().describe("等待数据的超时时间(毫秒),默认10秒")
        }
      },
      async ({ url, waitForData = true, timeoutMs = 10000 }: { 
        url: string; 
        waitForData?: boolean | undefined; 
        timeoutMs?: number | undefined; 
      }) => {
        try {
          let command: string;
          
          // 根据操作系统选择合适的命令
          if (process.platform === 'win32') {
            // Windows: 使用cmd /c start来确保正确打开浏览器
            command = `cmd /c start "" "${url}"`;
          } else if (process.platform === 'darwin') {
            command = `open "${url}"`;
          } else {
            command = `xdg-open "${url}"`;
          }
          
          await execAsync(command);
          
          if (!waitForData) {
            return {
              content: [{ 
                type: "text", 
                text: `成功打开网页: ${url}` 
              }]
            };
          }
          
          // 给页面一些时间来加载和建立WebSocket连接
          console.error("⏳ 等待页面加载并建立WebSocket连接...");
          await new Promise(resolve => setTimeout(resolve, 2000));
          
          // 等待页面发送数据
          try {
            console.error(`🔍 等待页面 ${url} 发送数据,超时时间: ${timeoutMs}ms`);
            const receivedData = await waitForPageDataViaAPI(timeoutMs);
            
            return {
              content: [{ 
                type: "text", 
                text: `成功打开网页并接收到数据: ${url}\n\n接收到的数据:\n${JSON.stringify(receivedData, null, 2)}` 
              }]
            };
          } catch (dataError) {
            // 如果等待数据超时,仍然返回成功打开页面的消息
            return {
              content: [{ 
                type: "text", 
                text: `成功打开网页: ${url}\n\n等待数据时出现问题: ${dataError instanceof Error ? dataError.message : '未知错误'}` 
              }]
            };
          }
          
        } catch (error) {
          return {
            content: [{ 
              type: "text", 
              text: `打开网页失败: ${error instanceof Error ? error.message : '未知错误'}` 
            }]
          };
        }
      }
    );
  • Helper function used by the handler to poll the web server at localhost:3003/api/wait-for-data for page-submitted data, with configurable timeout.
    async function waitForPageDataViaAPI(timeoutMs: number = 10000): Promise<any> {
      try {
        const response = await fetch('http://localhost:3003/api/wait-for-data', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({ timeoutMs })
        });
        
        console.error(`HTTP响应状态: ${response.status} ${response.statusText}`);
        
        if (!response.ok) {
          const errorText = await response.text();
          throw new Error(`HTTP请求失败 (${response.status}): ${errorText}`);
        }
        
        const result = await response.json();
        console.error('解析的结果:', result);
        
        if (result.success) {
          return result.data;
        } else {
          throw new Error(result.message || '等待数据失败');
        }
      } catch (error) {
        throw new Error(`HTTP API调用失败: ${error instanceof Error ? error.message : '未知错误'}`);
      }
    }
Behavior3/5

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

With no annotations provided, the description carries full burden and partially succeeds. It discloses that the tool opens a web page in an IDE and waits for WebSocket data, which are key behavioral traits. However, it doesn't mention potential side effects, error conditions, or what happens after timeout/WebSocket receipt.

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 functionality (opening web pages) and adds the WebSocket waiting behavior. Every word earns its place with no redundancy or unnecessary elaboration.

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

Completeness3/5

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

For a tool with 3 parameters, no annotations, and no output schema, the description provides adequate basic functionality explanation but lacks details about return values, error handling, or IDE-specific constraints. It's minimally viable but has clear gaps in behavioral context.

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

Parameters4/5

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

With 67% schema description coverage (2 of 3 parameters documented in schema), the description adds meaningful context by explaining that the tool '自动等待接收页面发送的WebSocket数据' which clarifies the purpose of the waitForData parameter. This compensates well for the partial schema coverage.

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 clearly states the specific action ('在IDE中打开一个新的网页窗口显示指定的URL') and distinguishes it from the sibling tool 'add' by specifying it opens web pages in an IDE environment. It goes beyond the title by adding the WebSocket data waiting functionality.

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 about when to use this tool versus alternatives. The description doesn't mention any prerequisites, constraints, or comparison with other tools that might open web pages or handle WebSocket data differently.

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/FuzzyCZX/MCP'

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