Skip to content

MCP: type_text takes a ref, presses it, then types (MCP-113) - #407

Open
marcoslor wants to merge 1 commit into
mainfrom
feat/mcp-113-type-text-ref
Open

marcoslor wants to merge 1 commit into
mainfrom
feat/mcp-113-type-text-ref

Conversation

@marcoslor

Copy link
Copy Markdown
Owner

Fixes #389

Implements MCP-113 on the Mac only: type_text now takes an optional ref. With it, one call presses the element first (ui.press with the caller's expect), types nothing when that press is refused (stale_ref, off_screen, covered), then on press.ok sends the single ui.type and settles and observes once. did carries ref beside characters, clear, submit, entry and via (never the text), and on.snapshot is the tree the ref came from. No wire or Android change.

What changed

  • MCPActMachine: new Path.pressThenType; Queued -> Pressing -> Typing -> Sent -> Settling -> Observing -> Done, with the existing Draining, deadline, windowClosed, linkLost and clientGone rows unchanged. A refused press goes straight to Done with its closed code and sends no sendType.
  • MCPCall.typeText / MCPArguments: optional ref, validated by the same key() rule as tap (^e[0-9]+$, ≤ 2147483647).
  • MCPTools+Input: the press keeps the window's turn; sendType reuses the press snapshot for on.snapshot; MCPActDid.type gained the optional ref.
  • Schemas: type_text's input schema declares ref; its output did declares ref with additionalProperties: false.
  • Docs: MCP-113 row and the act-machine table row in docs/specs/mcp.md; type_text's tool-table description (word-for-word with MCPCore.swift) and the did shape in docs/design/mcp.md.
  • Tests (all tagged [MCP-113]): happy path, every press refusal, deadline/client-gone/window-closed while pressing and typing, schema and description parity, plus a ref e2e case in suite_type.py.

Checks

$ scripts/check-rules.sh --base $(git merge-base HEAD main)
check-rules: PASS (base fd321e20828562dbd4ffefa6e48d398d8dc6cd06, 12 files checked)

$ scripts/check-ratchets.sh --base $(git merge-base HEAD main)
check-ratchets: PASS (base fd321e20828562dbd4ffefa6e48d398d8dc6cd06)

$ scripts/check-format.sh --base $(git merge-base HEAD main)
check-format: PASS (base fd321e20828562dbd4ffefa6e48d398d8dc6cd06, 8 Swift files, 0 Kotlin files)
$ cd macos && swift build
Build complete! (399,33 secs)

$ swift test --filter ContiguaCoreTests
Test Suite 'ContiguaCoreTests.xctest' passed
        Executed 433 tests, with 0 failures (0 unexpected) in 30.766 (30.797) seconds

$ swift test --filter MCP
Test Suite 'MCPActMachineTests' passed
Test Suite 'MCPCoreTests' passed
Test Suite 'MCPToolHostTests' passed
Test Suite 'WindowActQueueTests' passed
Test Suite 'Selected tests' passed
        Executed 271 tests, with 0 failures (0 unexpected) in 64.885 (64.913) seconds
Test Suite 'Selected tests' passed
        Executed 26 tests, with 0 failures (0 unexpected) in 0.692 (0.699) seconds

Every new case passes:

testTypeByRefPressesThenTypes_MCP113 passed
testTypeByRefPressRefusalTypesNothing_MCP113 passed
testTypeByRefDeadlineWhilePressingDrains_MCP113 passed
testTypeByRefClientGoneWhilePressingDrains_MCP113 passed
testTypeByRefWindowClosedWhilePressingFailsNoWindow_MCP113 passed
testTypeByRefDeadlineWhileTypingDrains_MCP113 passed
testTypeTextRefIsAKey_MCP113 passed
testTypeTextEnvelopeDeclaresRef_MCP113 passed
testTypeTextWithRefPressesThenTypes_MCP113 passed
testTypeTextWithRefPressRefusalTypesNothing_MCP113 passed
testTypeByRefPressesThenTypes_MCP113 passed (WindowActQueueTests)
testTypeByRefPressRefusalSendsNoType_MCP113 passed (WindowActQueueTests)

Full-suite note for this headless session: swift test reaches one unrelated AppKit/Vision test that cannot run here — LiveTextInteractionTests.testTheOverlayTakesAHitTestOnTextAndKeepsTextSelection fails with VisionKit never finished (state analyzing) (541 s), and SecondaryClickTests hangs creating an NSEvent; with those two skipped, everything else (all MCP and core tests) is green:

$ swift test --skip SecondaryClickTests
Test Case '-[ContiguaTests.LiveTextInteractionTests testTheOverlayTakesAHitTestOnTextAndKeepsTextSelection]' failed (541.932 seconds).
... VisionKit never finished (state analyzing)
Test Suite 'ContiguaCoreTests.xctest' passed
        Executed 433 tests, with 0 failures (0 unexpected) in 56.315 (56.358) seconds
Note: Some test targets reported failures:
  - ContiguaTests (XCTest)
$ python3 -m unittest discover -s tools/mcp-eval -p 'test_*.py'
Ran 34 tests in 10.076s

OK

The e2e suite_type.py case is added but not run here (needs the built app and fake-phone harness); it exercises a ref press followed by one ui.type, and a stale ref that types nothing.

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.

MCP: allow optional ref on type_text to focus and type in one call (MCP-113)

1 participant