Skip to content

Add Selenium Grid tools and saved Grids - #3

Open
AutomatedTester wants to merge 2 commits into
trunkfrom
claude/project-thread-eh519q
Open

AutomatedTester wants to merge 2 commits into
trunkfrom
claude/project-thread-eh519q

Conversation

@AutomatedTester

Copy link
Copy Markdown
Member

Requested by David · project thread

🔗 Related Issues

Phase 1 of the Grid operations MCP plan.

💥 What does this PR do?

Agents that run browsers on a Selenium Grid couldn't see what the Grid was doing, and had to be given the Grid URL on every start. This PR fixes both.

Five selenium_grid_* tools, in the default list:

Tool What it does
selenium_grid_use Saves a Grid the person names (URL, or a saved name) as the default, after checking it answers
selenium_grid_status Readiness, nodes, free slots per browser; with node, one node in detail
selenium_grid_sessions Running sessions, longest first, filterable, each with its Grid UI link
selenium_grid_queue Waiting requests, with a hint at why each waits (e.g. "no node offers safari")
selenium_grid_bug_report A summary for an issue, without URLs, hostnames or ids
  • Read-only tools: they only read the Grid, over /status, GraphQL and the session queue. Ending sessions, draining or removing nodes and clearing the queue are left to the person. Tools never guess which node, session or request is meant, and the server instructions say so too.
  • Saved Grids: they live in a config file. The server uses the first of --config, SELENIUM_MCP_CONFIG, ./.selenium-mcp.json and ~/.config/selenium-mcp/config.json, and saves back to the same file. Browsers start on the saved default Grid. --grid now takes a saved name as well as a URL, and still wins for that run.
  • No saved credentials: a Grid is assumed to sit behind its own network or auth. A URL with a user name or password in it is refused for saving. A URL with credentials given to --grid still works, but only for that run.
  • Session name: browsers started on a Grid get se:name: selenium-mcp, so they show up named in the Grid UI.

🔧 Implementation Notes

  • Node details are folded into selenium_grid_status (node argument) rather than being a sixth tool. This keeps the default list at the 25-tool cap that tools_test.js enforces. The tool list is about 2,820 of the 4,000-token budget.
  • The Grid refuses JSON bodies unless the content type says charset=utf-8; GridApi sends that.
  • --caps (open in another branch) is untouched. These tools are in the default list by design, since the server may run locally or remotely.

💡 Additional Considerations

  • Possible follow-ups on the Grid side: an endpoint that explains why a request doesn't match any node, and session idle time in /status and GraphQL. The queue hint compares browser names only, and says so.
  • Credentials for saved Grids and project-file permissions are deferred until users ask for them.

🔄 Types of changes

  • New feature (non-breaking change which adds functionality)

🧪 Testing

  • npm run lint passes.
  • Unit tests: test/unit/grid_test.js covers config file lookup order, saving, validation and errors, the formatters, and GridApi errors. The formatter tests run against /status, GraphQL and queue answers recorded from a real 4.52 hub with two nodes, four sessions and two queued requests. All 70 unit tests outside snapshot_test.js pass locally.
  • Grid e2e: test/e2e/grid_test.js starts a real hub and two nodes from SELENIUM_MCP_TEST_SERVER_JAR, and is skipped without it. It saves the Grid, reads status and node details, and starts the browser on the Grid. That browser start exercises BiDi through Grid. It also lists the selenium-mcp session, the empty queue and the bug report. 5/5 pass locally against Grid 4.52.0.
  • CI: the workflow now sets up Java 17, downloads the 4.52.0 server jar and runs the Grid e2e with --selenium-manager true on the nodes.
  • Not run locally: the existing browser e2e and snapshot_test.js need the nightly selenium-webdriver, which needs a GitHub Packages token this environment doesn't have. Locally I used selenium-webdriver@4.52.0 from npm, so they fail here for that reason only; CI runs them with the nightly. I updated the e2e tool count from 20 to 25.

🤖 AI assistance

  • AI assisted
    • Tool: Claude Code
    • What was generated: the code, tests, fixtures and docs in this PR, from a plan David reviewed and shaped (one server, read-only Grid tools, destructive tasks left to the person, saved Grids, no saved credentials).
    • Review: a human review by David is still needed before merge.

Generated by Claude Code

Agents that run browsers on a Selenium Grid had no way to see what
the Grid was doing, and had to be told the Grid URL on every start.

Add five selenium_grid_* tools to the default list: use, status,
sessions, queue and bug_report. They only read the Grid, over
/status, GraphQL and the session queue. Ending sessions, draining or
removing nodes and clearing the queue are left to the person, and no
tool guesses which node, session or request is meant.

selenium_grid_use saves a Grid the person names to a config file
(--config, SELENIUM_MCP_CONFIG, ./.selenium-mcp.json, then the user's
config) as the default, so they are not asked again. Browsers then
start on it. --grid now takes a saved Grid's name as well as a URL.
No credentials are saved; a Grid is assumed to sit behind its own
network or auth.

Browsers started on a Grid are named selenium-mcp, so people can tell
them apart in the Grid UI. CI runs the Grid tools against a real hub
with two nodes.
@AutomatedTester AutomatedTester self-assigned this Nov 17, 2026
Brings in the --caps tool groups. The Grid tools stay in the default
list; the optional groups are listed after them in the README.
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