feat: expose structured MCP command tools#593
Conversation
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb650cfeba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return compactRecord({ | ||
| ...commandOptions, | ||
| ...commonToClientOptions(readCommonInput(record)), | ||
| }) as TOptions; |
There was a problem hiding this comment.
Preserve element target when deviceTarget is present
readClientOptions currently spreads commonToClientOptions after command-specific fields, and commonToClientOptions maps deviceTarget onto target. For commands that also use a semantic element target object (notably get/longpress), providing deviceTarget overwrites that object with a string, so downstream target conversion throws (Expected target to be an object). This is a behavioral regression for requests that select both a device form and an element target.
Useful? React with 👍 / 👎.
|
|
||
| async function handleMcpBatch(messages: JsonRpcMessage[]): Promise<JsonRpcResponse[] | null> { | ||
| const responses = ( | ||
| await Promise.all(messages.map(async (message) => await handleMcpMessage(message))) |
There was a problem hiding this comment.
Process JSON-RPC batch messages in order
Using Promise.all here executes all batch entries concurrently, which makes dependent mutating requests race each other (for example, open and then click in one JSON-RPC batch can run out of order and fail with no active session). The previous implementation handled batch entries serially, and this parallelization changes MCP into a concurrent execution path for stateful session commands.
Useful? React with 👍 / 👎.
72f65bb to
118999c
Compare
ef20069 to
1f6136f
Compare
Summary
Expose
agent-device mcpas a first-class structured tool server instead of discovery-only metadata. CLI, MCP, and the Node client now share command contracts; CLI grammar only reads positional/flag input, whilecommand-projectionowns typed input to daemon request projection for the Node client and batch execution.Batch is structured at every public interface: MCP and
client.batch.run()use{ command, input, runtime? }steps, and CLIbatch --stepsnow prefers the same shape. Existing CLIpositionals/flagsbatch files still run through a CLI-only compatibility normalizer with a deprecation warning; that legacy shape is documented for removal in the next major version. Daemon-shaped{ positionals, flags }steps are kept inside the projection/daemon executor. The formerbatch-command-contractmodule is nowbatch-command.Review hardening: MCP JSON-RPC batches and separate stdio request payloads now execute serially, fallback MCP infrastructure errors preserve the request id when available, MCP
stateDiris stripped before command validation, hybrid batch step shapes are rejected, and structured command input acceptstargetas a device-form alias only on commands that do not reservetargetfor a UI element. Latest cleanup removes theRecord<string, any>command input escape hatch in favor of typed known command fields plusunknownfor unrecognized fields.Deletes the old command codec/request helpers, legacy
CommandDefinitionmetadata, MCP catalog placeholder, and thin dedicated CLI wrapper modules that only delegated into shared execution. CLI help/schema code is split into focused modules, command schemas derive from the command surface, capability decisions stay in capabilities, and MCP tools are generated from command contracts. Follow-up cleanup tightens CLI reader/override registries against the command surface so misspelled command keys fail at typecheck, keeps MCP-only config such asstateDirout of shared command contracts, and keeps MCP executor implementation types module-local.Updates agent setup docs with copy-paste Cursor and Claude paths for CLI-only and MCP workflows, plus MCP
isError: truetool-result handling guidance.Current branch diff is
+7,779 / -5,446againstorigin/mainafter rebasing on latestmain. Touched-file count: 104. Scope is the CLI/MCP/Node interface layer; daemon architecture and platform handlers are preserved.Validation
Ran
pnpm format,pnpm check:quick,pnpm check:fallow --base origin/main, and focused Vitest coverage for the command-interface surface:pnpm exec vitest run src/__tests__/cli-grammar.test.ts src/__tests__/cli-batch.test.ts src/__tests__/client.test.ts src/mcp/__tests__/command-tools.test.ts src/mcp/__tests__/router.test.ts src/utils/__tests__/args.test.ts.Earlier validation for this branch also covered batch/remote materialization/MCP/client/help scenarios and the previously failing provider scenario:
pnpm exec vitest run test/integration/provider-scenarios/android-lifecycle.test.ts --project provider-integration.