midscene icon indicating copy to clipboard operation
midscene copied to clipboard

feat(mcp): simplify MCP tool architecture and unify platform tools

Open quanru opened this issue 4 weeks ago โ€ข 1 comments

Summary

This PR refactors the MCP packages to use a simplified, consistent tool architecture across all platforms (Web, Android, iOS).

Key Changes

๐Ÿ—๏ธ Shared Infrastructure (@midscene/shared/mcp)

  • Created BaseMCPServer and BaseMidsceneTools base classes for code reuse
  • Implemented dynamic tool generation from agent.getActionSpace()
  • Simplified common tools to only take_screenshot and wait_for (removed assert)
  • Added unified tool generation pattern in tool-generator.ts

๐Ÿ“ฆ Platform-Specific Packages

  • @midscene/web-mcp (Renamed from @midscene/mcp): Web automation via Puppeteer & Bridge mode
  • @midscene/android-mcp (New): Android-specific MCP server with android_connect tool
  • @midscene/ios-mcp (New): iOS-specific MCP server with ios_connect tool

๐ŸŽฏ Simplified Tool Architecture

Each platform now provides exactly 3 types of tools:

  1. ActionSpace tools (dynamic): Generated from agent.getActionSpace()
    • Platform-specific interaction capabilities (Tap, Input, Scroll, etc.)
  2. Common tools (2 tools):
    • take_screenshot: Capture current page/screen
    • wait_for: Wait until condition becomes true
  3. Platform connection (1 tool):
    • web_connect: Connect to web page (Puppeteer) or browser (Bridge mode)
    • android_connect: Connect to Android device (optional deviceId and uri)
    • ios_connect: Connect to iOS device (optional uri)

๐Ÿ”ง Recent Improvements

Bridge Mode Enhancement (d56be2d7):

  • Improved bridge mode device initialization in base-tools.ts
  • Enhanced wait_for error handling with try-catch blocks
  • Better connection lifecycle management

Build & Type Fixes (0d4a3734):

  • Fixed invalid planType parameter in tool-generator.ts
  • Added missing isError field to wait_for tool response
  • Removed unused @midscene/android dependency from web-mcp
  • Added externals configuration to android-mcp and ios-mcp rslib configs
  • Unified version handling using __VERSION__ constant across all MCP packages

๐Ÿงช Testing & Quality

  • All MCP package tests passing (web-mcp: 22/22, android-mcp, ios-mcp)
  • Build and lint checks passing
  • Fixed test organization (moved from @midscene/mcp to @midscene/web-mcp)

Migration Notes

Tools have been consolidated:

  • ~~open_new~~ โ†’ web_connect
  • ~~android_list_devices~~ โ†’ Removed (use android_connect without deviceId)
  • ~~android_launch~~ โ†’ Merged into android_connect (use uri parameter)
  • ~~ios_check_environment~~ โ†’ Removed (just use ios_connect)
  • ~~assert~~ โ†’ Removed from common tools

Package rename:

  • @midscene/mcp โ†’ @midscene/web-mcp

Related Issues

Part of MCP architecture refactoring to support multiple platforms with consistent patterns. Addresses GitHub Copilot review comments for improved code quality and type safety.

๐Ÿค– Generated with Claude Code

quanru avatar Nov 25 '25 12:11 quanru

Deploy Preview for midscene ready!

Name Link
Latest commit cb1fe3377f0b54edfdc5787c152acd59a7d5bc84
Latest deploy log https://app.netlify.com/projects/midscene/deploys/6937863d3ab57b0008476428
Deploy Preview https://deploy-preview-1507--midscene.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

netlify[bot] avatar Nov 25 '25 12:11 netlify[bot]