feat(browser,mcp): resolve environment and credentials from DB in exec
- POST /exec now accepts environmentId (UUID) and credentials (alias → UUID) instead of raw payloads; resolves entities via EnvironmentService and CredentialService before passing data to browserService.exec - exec_code MCP tool updated with same schema: environmentId + credentials map - CredentialModule imported into BrowserModule and McpModule - docs(scenario): rewrite script runtime section for single context argument - docs(mcp): update exec_code description to reflect new parameter shapes - style: reorder imports across server source (formatter)
This commit is contained in:
+1
-1
@@ -28,7 +28,7 @@ The server currently registers the following tools.
|
||||
| Tool | Description |
|
||||
|---|---|
|
||||
| `open_url` | Open URL with optional `sessionName`, return page/title/content |
|
||||
| `exec_code` | Execute Playwright JS with `page` and `context` in scope |
|
||||
| `exec_code` | Execute Playwright JS — script receives a single `context` argument (see `scenario.md`). Optional `environmentId` (UUID) resolves environment from DB for `context.getEnv()`. Optional `credentials` (`{ alias: credentialUUID }`) resolves credentials from DB for `context.getCredential(alias)`. |
|
||||
|
||||
## Scenarios
|
||||
|
||||
|
||||
+19
-15
@@ -17,24 +17,28 @@ Current scheduler behavior is exec-centric:
|
||||
|
||||
## Script runtime
|
||||
|
||||
`execCode` and `validateCode` execute as async JavaScript with:
|
||||
`execCode` and `validateCode` execute as async JavaScript with a single `context` argument:
|
||||
|
||||
- `page`: Playwright `Page`
|
||||
- `context`: Playwright `BrowserContext`
|
||||
- `helpers`: utility object
|
||||
```js
|
||||
async (context) => {
|
||||
// your code here
|
||||
}
|
||||
```
|
||||
|
||||
Available in scope:
|
||||
|
||||
- `context.page`: Playwright `Page`
|
||||
- `context.browser`: Playwright `BrowserContext`
|
||||
- `context.env`: shallow copy of environment key/value map
|
||||
- `context.getEnv(key)`: required environment value lookup (throws if missing)
|
||||
- `context.getCredential(alias)`: credential payload assigned to the scenario alias
|
||||
- `context.getStepOutput(order)`: prior step output by absolute order (`1`, `2`, ...) or relative (`-1` = previous step)
|
||||
- `context.dumpDom(selector?)`: simplified DOM snapshot
|
||||
- `context.log(...args)`, `context.warn(...args)`, `context.error(...args)`: structured step logs
|
||||
- `context.runSnippet(name, ...args)`: execute stored snippet code with the same context
|
||||
- `console`: proxied to run logs (`log`, `warn`, `error`, etc.)
|
||||
|
||||
`validateCode` additionally receives `result`, which is the value returned by `execCode`.
|
||||
|
||||
## Available helpers
|
||||
|
||||
- `helpers.dumpDom(selector?)`: simplified DOM snapshot
|
||||
- `helpers.log(...args)`, `helpers.warn(...args)`, `helpers.error(...args)`: structured step logs
|
||||
- `helpers.getStepOutput(order)`: prior step output by absolute order (`0`, `1`, ...) or relative (`-1` previous step)
|
||||
- `helpers.getCredential(alias)`: credential payload assigned to the scenario alias
|
||||
- `helpers.env`: shallow copy of environment URL map
|
||||
- `helpers.getEnv(key)`: required environment value lookup (throws if missing)
|
||||
- `helpers.runSnippet(name, ...args)`: execute stored snippet code in the same page/context/helpers scope
|
||||
`validateCode` additionally receives `result` in scope, which is the value returned by `execCode`.
|
||||
|
||||
## Validation contract
|
||||
|
||||
|
||||
Reference in New Issue
Block a user