Skip to content

feat: add actions option to mql, core, and mcp - #9

Open
Kikobeats wants to merge 1 commit into
masterfrom
feat/actions-sdk
Open

feat: add actions option to mql, core, and mcp#9
Kikobeats wants to merge 1 commit into
masterfrom
feat/actions-sdk

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Aug 9, 2026

Copy link
Copy Markdown
Member

Summary

  • Add Action / ActionLocator types and actions?: Action[] on @microlink/mql MicrolinkApiOptions, with flatten snapshot + tsd coverage
  • Mirror actions on microlink.io core Options (screenshot/pdf inherit)
  • Add Zod actions discriminated union to @microlink/mcp browserSchema and prefer actions in screenshot/pdf/html/function tool descriptions

No wire-format serializer changes — flattie already emits actions.N.* and the API reconstitutes via nestie.

Test plan

  • ava test/get-api-url.mjs (includes actions flatten snapshot)
  • tsd in mql and core
  • node --test packages/mcp/test/schemas.test.js (53 passing)

Made with Cursor

Summary by CodeRabbit

  • New Features

    • Added support for ordered browser actions, including injecting scripts, clicking, waiting, scrolling, filling forms, evaluating code, capturing screenshots, and generating PDFs.
    • Actions support semantic locators and CSS selectors for more targeted interactions.
    • Added typed configuration support for defining action sequences.
  • Enhancements

    • Existing interaction and capture options remain supported alongside the new actions API.
    • Action sequences are serialized for API requests using structured parameters.
    • Updated tool guidance with examples and recommendations for using ordered actions.

Type and validate the upcoming browser actions API surface so clients
can pass ordered interaction steps with semantic locators before the
engine ships.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds ordered browser action types, MCP validation, tool documentation, and MQL coverage for action requests and dotted-key URL serialization.

Changes

Browser actions

Layer / File(s) Summary
Action contracts and validation
packages/core/src/index.d.ts, packages/core/test/index.test-d.ts, packages/mcp/src/schemas.js
Core declarations define locators and action variants. MCP validates non-empty action arrays and variant-specific fields. Type tests cover screenshot and PDF actions.
Tool action guidance
packages/mcp/src/tools/function.js, packages/mcp/src/tools/html.js, packages/mcp/src/tools/pdf.js, packages/mcp/src/tools/screenshot.js
Tool descriptions recommend ordered actions and document supported legacy options.
MQL serialization coverage
packages/mql/test/index.test-d.ts, packages/mql/test/get-api-url.mjs, packages/mql/test/snapshots/get-api-url.mjs.md, packages/mcp/test/schemas.test.js
Tests cover action request types, URL flattening, valid action combinations, and rejection of unsupported action types.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant browserSchema
  participant MQLURLBuilder
  participant API

  Client->>browserSchema: Submit actions array
  browserSchema->>browserSchema: Validate action variants
  browserSchema-->>MQLURLBuilder: Parsed actions
  MQLURLBuilder->>MQLURLBuilder: Flatten actions into dotted keys
  MQLURLBuilder->>API: Send indexed action parameters
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding the actions option across MQL, core, and MCP.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/actions-sdk

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/mcp/src/schemas.js`:
- Around line 253-258: The click and fill schemas currently allow missing or
conflicting locator strategies. Add refinements to both action schemas requiring
exactly one strategy, counting role with optional name as a single strategy and
rejecting name without role; preserve the existing locator field definitions and
strictness.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3a4ccc85-5d42-46f0-8153-8ae39f7dce07

📥 Commits

Reviewing files that changed from the base of the PR and between f51f9ed and 9aba95a.

⛔ Files ignored due to path filters (2)
  • packages/mql/dist/index.d.ts is excluded by !**/dist/**
  • packages/mql/test/snapshots/get-api-url.mjs.snap is excluded by !**/*.snap
📒 Files selected for processing (11)
  • packages/core/src/index.d.ts
  • packages/core/test/index.test-d.ts
  • packages/mcp/src/schemas.js
  • packages/mcp/src/tools/function.js
  • packages/mcp/src/tools/html.js
  • packages/mcp/src/tools/pdf.js
  • packages/mcp/src/tools/screenshot.js
  • packages/mcp/test/schemas.test.js
  • packages/mql/test/get-api-url.mjs
  • packages/mql/test/index.test-d.ts
  • packages/mql/test/snapshots/get-api-url.mjs.md

Comment on lines +253 to +258
z
.object({
type: z.literal('click'),
...locatorFields
})
.strict(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '5,29p' packages/core/src/index.d.ts
sed -n '231,306p' packages/mcp/src/schemas.js

Repository: microlinkhq/microlink

Length of output: 2957


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- locate package files ---'
fd -a '^(package\.json|index\.d\.ts|schemas\.js)$' packages/mcp packages/core | sed 's#^\./##'

printf '%s\n' '--- package metadata for packages/mcp ---'
cat packages/mcp/package.json | sed -n '1,120p'

printf '%s\n' '--- relevant schema sections ---'
sed -n '1,80p' packages/mcp/src/schemas.js
sed -n '215,306p' packages/mcp/src/schemas.js

printf '%s\n' '--- inspect references to locator validation / ActionLocator ---'
rg -n "locatorFields|ActionLocator|mutual|exclusiv|role\?|name" packages -S

Repository: microlinkhq/microlink

Length of output: 42263


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- lockfile zod version references ---'
if [ -f package-lock.json ]; then
  node -e 'const lock=require("./package-lock.json"); for (const [k,v] of Object.entries(lock.packages||{}).filter(([k,v]) => k && v.version)?.entries) if (k.includes("zod")) console.log(`${k}: ${v.version}`)'
fi

printf '%s\n' '--- deterministic schema behavior probe using repo package files ---'
python3 - <<'PY'
from pathlib import Path
import re

schema = Path('packages/mcp/src/schemas.js').read_text()
locator_fields = dict(re.search(r'const locatorFields = \{(?P<body>.*?)\n\}\n(? =const actionSchema)', schema, re.S).group('body'))
click = re.search(r'z\s*\.\s*object\(\{\s*type:\s* z\.literal\('click'\'),(?P<body>.*?)\}\.strict\(\),', schema, re.S)
fill = re.search(r'z\s*\.\s*object\(\{\s*type:\s*z\.literal\('fill'\'),(?P<body>.*?)\}\.strict\(\),', schema, re.S)
core_type = Path('packages/core/src/index.d.ts').read_text()
print('locator_fields_are_optional:', all('optional()' in value for value in locator_fields.values()))
print('click_accepts_no_strategy:', click is not None and '{ type: z.literal("click") }' in click.group(0))
print('fill_accepts_no_strategy:', fill is not None and '{ type: z.literal("fill") }' in fill.group(0))
print('click_accepts_conflicting_selector_text_example:', bool(click and re.search(r'click.*selector.*text', click.group(0), re.S)))
print('fill_accepts_conflicting_selector_text_example:', bool(fill and re.search(r'fill.*selector.*text', fill.group(0), re.S)))
print('core_click_requires_actionlocator:' ,bool(re.search(r'\(\{\s*type:\s*\'click\'\s*\}\s*&\s*ActionLocator\)', core_type)))
print('core_fill_requires_actionlocator:', bool(re.search(r'\(\{\s*type:\s*\'fill\'\s*,\s*value:\s*string\s*\}\s*&\s*ActionLocator\)', core_type)))
PY

Repository: microlinkhq/microlink

Length of output: 514


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
import re

schema = Path('packages/mcp/src/schemas.js').read_text()
locator_body = re.search(r"const locatorFields = \{(?P<body>.*?)\n\}\n", schema, re.S).group('body')
locator_fields = {}
for m in re.finditer(r'(\w+):\s*z\.str.*?\.optional?\(\)', locator_body):
    locator_fields[m.group(1)] = m.group(0).rstrip(',')

click = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('click'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S, flags=re.S)
fill = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('fill'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S)
core = Path('packages/core/src/index.d.ts').read_text()

print('all_locator_fields_optional:', all('optional()' in v for v in locator_fields.values()))
print('click_accepts_no_locator_strategy:', bool(click) and '{ type: z.literal('click') }' in click.group(0))
print('fill_accepts_no_locator_strategy:', bool(fill) and '{ type: z.literal('fill') }' in fill.group(0))
print('click_accepts_conflicting_selector_and_text:', bool(click) and 'selector' in click.group(0) and 'text' in click.group(0))
print('fill_accepts_conflicting_selector_and_text:', bool(fill) and 'selector' in fill.group(0) and 'text' in fill.group(0))
print('core_click_requires_actionlocator:', bool(re.search(r"\(\{\s*type:\s*'click'\s*\}\s*&\s*ActionLocator\)", core)))
print('core_fill_requires_actionlocator:', bool(re.search(r"\(\{\s*type:\s*'fill',\s*value:\s*string\s*\}\s*&\s*ActionLocator\)", core)))
PY

Repository: microlinkhq/microlink

Length of output: 413


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - <<'PY'
from pathlib import Path
import re

schema = Path('packages/mcp/src/schemas.js').read_text()
locator_body = re.search(r"const locatorFields = \{(?P<body>.*?)\n\}\n", schema, re.S).group('body')
locator_fields = {}
for m in re.finditer(rr"(\w+):\s*z\(.*?\)\.optional\(\)", locator_body):
    locator_fields[m.group(1)] = m.group(0).rstrip(',')

click = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('click'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S)
fill = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('fill'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S)
core = Path('packages/core/src/index.d.ts').read_text().splitlines()

print('all_locator_fields_optional:', all('optional()' in v for v in locator_fields.values()))
print('locator_fields', locator_fields)
print('click_accepts_no_locator_strategy:', bool(click) and "'click'" in click.group(0) and '{ type:' not in click.group(1).strip())
print('fill_accepts_no_locator_strategy:', bool(fill))
print('click_accepts_conflicting_selector_and_text:', bool(click) and 'selector' in click.group(0) and 'text' in click.group(0))
print('fill_accepts_conflicting_selector_and_text:', bool(fill) and 'selector' in fill.group(0) and 'text' in fill.group(0))
for i,l in enumerate(core):
    if "type: 'click'" in l or "type: 'fill'" in l or "ActionLocator =" in l:
        print(f'core[{i}]: {l}')
PY

Repository: microlinkhq/microlink

Length of output: 318


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 - "$@" <<'PY'
from pathlib import Path
import re

schema = Path('packages/mcp/src/schemas.js').read_text()
locator_body = re.search(r"const locatorFields = \{(?P<body>.*?)\n\}\n", schema, re.S).group('body')
locator_fields = {}
for m in re.finditer(r"(\w+):\s*z\..*?\)\.optional\(\)", locator_body, re.S):
    locator_fields[m.group(1)] = m.group(0).rstrip(',')

click = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('click'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S)
fill = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('fill'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S)
core = Path('packages/core/src/index.d.ts').read_text().splitlines()

print('all_locator_fields_optional:', all('optional()' in v for v in locator_fields.values()))
print('locator_fields', locator_fields)
print('click_accepts_no_locator_strategy:', bool(click) and '{ type: z.literal('click') }' in click.group(0))
print('fill_accepts_no_locator_strategy:', bool(fill) and 'value: z.string()' in fill.group(0))
print('click_accepts_conflicting_selector_and_text:', bool(click) and 'selector' in click.group(0) and 'text' in click.group(0))
print('fill_accepts_conflicting_selector_and_text:', bool(fill) and 'selector' in fill.group(0) and 'text' in fill.group(0))
for i,l in enumerate(core):
    if "type: 'click'" in l or "type: 'fill'" in l or "ActionLocator =" in l:
        print(f'core[{i}]: {l}')
PY

Repository: microlinkhq/microlink

Length of output: 413


🏁 Script executed:

#!/bin/bash
set -euo pipefail

python3 <<'PY'
from pathlib import Path
import re

schema = Path('packages/mcp/src/schemas.js').read_text()
locator_body = re.search(r"const locatorFields = \{(?P<body>.*?)\n\}\n", schema, re.S).group('body')
locator_fields = {}
for m in re.finditer(r"(\w+):\s*z\..*?\)\.optional\(\)", locator_body, re.S):
    locator_fields[m.group(1)] = m.group(0).rstrip(',')

click = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('click'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S)
fill = re.search(r"z\s*\.\s*object\(\{\s*type:\s*z\.literal\('fill'\'),(?P<body>.*?)\}\.strict\(\)", schema, re.S)
core = Path('packages/core/src/index.d.ts').read_text().splitlines()
action_locator = '\n'.join(core[core.index(next(l for l in core if 'ActionLocator =' in l)): next((i for i,l in enumerate(core) if 'export type Action' in l), len(core))])

print('all_locator_fields_optional=', all('optional()' in v for v in locator_fields.values()))
print('locator_fields=', sorted(locator_fields))
print('click_accepts_no_locator_strategy=', '{ type: z.literal('click') }' in click.group(0) if click else False)
print('click_accepts_conflicting_selector_and_text=', bool(click) and 'selector' in click.group(0) and 'text' in click.group(0))
print('fill_accepts_conflicting_selector_and_text=', bool(fill) and 'selector' in fill.group(0) and 'text' in fill.group(0))
print('core_action_locator_clause=', action_locator[:600].replace('\n',' '))
PY

Repository: microlinkhq/microlink

Length of output: 401


🌐 Web query:

Microlink API ActionLocator click fill schema selector role name text label placeholder testId alt action options

💡 Result:

The term ActionLocator does not exist as a standard parameter or feature in the Microlink API. Microlink uses a declarative, query-string-based API to handle browser automation and data extraction, rather than a locator-based system like those found in testing frameworks such as Playwright [1][2][3]. For browser interactions in Microlink, you instead use specific interaction parameters [2]: * Click: You perform clicks by passing a CSS selector to the click parameter (e.g., click='.my-button') [2]. * Fill/Input: Microlink does not have a dedicated fill parameter for declarative browser interaction. If you need to fill forms or perform complex interactions that go beyond simple clicks or scrolls, you should use the function parameter to run custom JavaScript code with full Puppeteer access [2][4]. * Data Extraction: You define the schema for data you want to extract using the data parameter [5]. This object uses selectors (e.g., selector, selectorAll) and attributes (attr) to target specific elements on a page [5][6]. The attributes you listed (role, name, text, label, placeholder, testId, alt) are standard DOM accessibility or testing attributes commonly used as CSS selectors (e.g., [role='button'], [placeholder='email']) [2]. You can use these as values for the selector fields within your Microlink data rules or click parameters by utilizing standard CSS attribute selector syntax [5][2]. If you are seeing references to ActionLocator, it is likely related to Playwright's internal trace tools or custom implementations in other frameworks rather than the Microlink API itself [7][8][9].

Citations:


🌐 Web query:

packages/mql/src ActionLocator mql index.js "ActionLocator" "click" "fill"

💡 Result:

The terms "ActionLocator", "mql", "index.js", "click", and "fill" appear in several distinct technical contexts, as there is no single standardized library or framework that exclusively combines all these specific components. 1. Playwright and Testing Frameworks: In many automation and testing projects (such as robotframework-browser), "ActionLocator" is a conceptual or class name used to find UI elements [1]. Developers often use Playwright’s.click and.fill methods to interact with these located elements [1][2]. 2. MQL (MetaQuotes Language) Compile Actions: There is a GitHub repository named MQL-Compile-Action which contains an index.js file [3][4]. This project is used to compile MQL files (used in algorithmic trading platforms) and manages this process via build scripts [3]. 3. ObjectStack / UI Frameworks: Some frameworks, like ObjectStack, utilize an ActionLocation concept to define where UI actions (such as buttons or menu items) surface in an application [5][6]. 4. C# Web Frameworks: In custom or educational C# web framework implementations, an ActionLocator component is frequently used within middleware to resolve incoming requests to specific controller actions [7]. 5. Specialized Systems: The term "ActionLocator" also appears in specialized software, such as the UR robot operating system (in the context of command processing) [8] or game development frameworks (like Planeshift) for defining interactive locations [9]. If you are working with a specific codebase or trying to resolve a particular error, you are likely looking at one of these implementations rather than a unified industry-standard package.

Citations:


🌐 Web query:

@microlink/mql ActionLocator click fill selector role name text zod validation

💡 Result:

The @microlink/mql library interacts with the Microlink API to perform web scraping and browser automation [1][2]. Based on official documentation, the concepts of "ActionLocator," "role," "name," and "text" as specific, native parameters for clicking or filling elements are not part of the standard @microlink/mql API [3][4][5]. Instead, Microlink uses the following mechanisms: 1. Interaction (Clicking/Filling): The click parameter is used for interaction before data extraction [6]. It accepts a CSS selector as a string (or an array of strings) to target the elements to be clicked [6][3]. Example: const { data } = await mql('https://example.com', { click: '.button-selector' }) 2. Data Extraction (Selectors): Data extraction is defined via the data parameter, which uses CSS selectors [4][7]. - selector: Specifies the target element (CSS selector) [8][5]. - attr: Specifies the attribute to extract, such as 'text', 'href', 'src', or 'html' [8][9][5]. - type: Used for validation and normalization of the extracted value (e.g., 'string', 'number', 'url', 'image') [10][9][5]. 3. Validation: Microlink does not natively integrate Zod for validation within the request configuration [10][5]. Instead, it uses a built-in type property in the data extraction rule to ensure the extracted value matches a specific format (e.g., 'number', 'date') [10][9]. If the value does not match the expected type, it is considered invalid and may be discarded [10][11]. Note: Some third-party agentic frameworks or automation wrappers (like the example found in the Catcher repository) may implement higher-level abstractions using terms like "role", "name", and "text" to construct Playwright locators internally, but these are not native features of the @microlink/mql library itself [12].

Citations:


Require one locator strategy for click and fill.

The locatorFields object makes every locator field optional, so these action schemas accept targetless actions and compatible conflicting strategies such as selector plus text. This diverges from ActionLocator, which allows only one strategy. Add a refinement for both schemas that requires exactly one strategy; treat role plus optional name as one strategy, and reject name when role is absent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/mcp/src/schemas.js` around lines 253 - 258, The click and fill
schemas currently allow missing or conflicting locator strategies. Add
refinements to both action schemas requiring exactly one strategy, counting role
with optional name as a single strategy and rejecting name without role;
preserve the existing locator field definitions and strictness.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant