Skip to content

feat: expose structured MCP command tools#593

Open
thymikee wants to merge 30 commits into
mainfrom
feat/semantic-mcp-tools
Open

feat: expose structured MCP command tools#593
thymikee wants to merge 30 commits into
mainfrom
feat/semantic-mcp-tools

Conversation

@thymikee
Copy link
Copy Markdown
Member

@thymikee thymikee commented May 26, 2026

Summary

Expose agent-device mcp as 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, while command-projection owns 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 CLI batch --steps now prefers the same shape. Existing CLI positionals/flags batch 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 former batch-command-contract module is now batch-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 stateDir is stripped before command validation, hybrid batch step shapes are rejected, and structured command input accepts target as a device-form alias only on commands that do not reserve target for a UI element. Latest cleanup removes the Record<string, any> command input escape hatch in favor of typed known command fields plus unknown for unrecognized fields.

Deletes the old command codec/request helpers, legacy CommandDefinition metadata, 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 as stateDir out 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: true tool-result handling guidance.

Current branch diff is +7,779 / -5,446 against origin/main after rebasing on latest main. 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 26, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://callstackincubator.github.io/agent-device/pr-preview/pr-593/

Built to branch gh-pages at 2026-05-27 19:55 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread src/commands/semantic-common.ts Outdated
Comment on lines +160 to +163
return compactRecord({
...commandOptions,
...commonToClientOptions(readCommonInput(record)),
}) as TOptions;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment thread src/mcp/server.ts Outdated

async function handleMcpBatch(messages: JsonRpcMessage[]): Promise<JsonRpcResponse[] | null> {
const responses = (
await Promise.all(messages.map(async (message) => await handleMcpMessage(message)))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

@thymikee thymikee changed the title feat: expose semantic MCP tools feat: expose structured MCP command tools May 27, 2026
@thymikee thymikee force-pushed the feat/semantic-mcp-tools branch from 72f65bb to 118999c Compare May 27, 2026 18:23
@thymikee thymikee force-pushed the feat/semantic-mcp-tools branch from ef20069 to 1f6136f Compare May 27, 2026 19:55
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