Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

getForms

Extract all form elements from a webpage to analyze structure, collect data, or automate interactions during browser automation tasks.

Instructions

Get all forms from the current page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function getForms() in PlaywrightController class that uses page.evaluate to extract all forms, their action/method, and input fields from the current page.
    async getForms(): Promise<Array<{action?: string, method?: string, fields: Array<{name?: string, type?: string, value?: string}>}>> {
      try {
        if (!this.isInitialized()) {
          throw new Error('Browser not initialized');
        }
        this.log('Getting page forms');
        const forms = await this.state.page?.evaluate(() => {
          const formElements = Array.from(document.querySelectorAll('form'));
          return formElements.map(form => ({
            action: form.getAttribute('action') || undefined,
            method: form.getAttribute('method') || undefined,
            fields: Array.from(form.querySelectorAll('input, select, textarea')).map(field => ({
              name: field.getAttribute('name') || undefined,
              type: field.getAttribute('type') || field.tagName.toLowerCase(),
              value: (field as HTMLInputElement).value || undefined
            }))
          }));
        });
        this.log('Forms retrieved:', forms?.length);
        return forms || [];
      } catch (error: any) {
        console.error('Get forms error:', error);
        throw new BrowserError('Failed to get forms', 'Check if the page is loaded');
      }
    }
  • The Tool schema definition for 'getForms', specifying no input parameters.
    const GET_FORMS_TOOL: Tool = {
      name: "getForms",
      description: "Get all forms from the current page",
      inputSchema: {
        type: "object",
        properties: {},
        required: []
      }
    };
  • src/server.ts:531-531 (registration)
    Registration of the getForms tool in the tools dictionary passed to MCP server capabilities.
    getForms: GET_FORMS_TOOL,
  • src/server.ts:740-745 (registration)
    Dispatch handler in callTool request handler that invokes the getForms method and returns the JSON stringified result.
    case 'getForms': {
      const forms = await playwrightController.getForms();
      return {
        content: [{ type: "text", text: JSON.stringify(forms, null, 2) }]
      };
    }

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/jomon003/PlayMCP'

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