|
| 1 | +import { z } from '@midscene/core'; |
| 2 | +import { |
| 3 | + type BaseAgent, |
| 4 | + BaseMidsceneTools, |
| 5 | + type ToolDefinition, |
| 6 | +} from '@midscene/shared/mcp'; |
| 7 | + |
| 8 | +const DEPRECATION_MESSAGE = ` |
| 9 | +⚠️ DEPRECATION NOTICE ⚠️ |
| 10 | +
|
| 11 | +The @midscene/mcp package is deprecated and no longer maintained. |
| 12 | +
|
| 13 | +Please migrate to one of the platform-specific MCP packages: |
| 14 | + • @midscene/web-bridge-mcp - For web browser automation (Bridge mode) |
| 15 | + • @midscene/android-mcp - For Android device automation |
| 16 | + • @midscene/ios-mcp - For iOS device automation |
| 17 | +
|
| 18 | +These new packages provide better performance, stability, and platform-specific features. |
| 19 | +
|
| 20 | +Migration Guide: |
| 21 | +1. Uninstall @midscene/mcp |
| 22 | +2. Install the appropriate platform-specific package |
| 23 | +3. Update your MCP configuration to use the new package name |
| 24 | +
|
| 25 | +For more information, visit: https://midscenejs.com/mcp-migration |
| 26 | +`; |
| 27 | + |
| 28 | +/** |
| 29 | + * Mock tools definitions that will return deprecation notices |
| 30 | + */ |
| 31 | +export const tools = { |
| 32 | + // Common tools |
| 33 | + wait_for: { |
| 34 | + name: 'wait_for', |
| 35 | + description: |
| 36 | + 'DEPRECATED: Waits until a specified condition, described in natural language, becomes true on the page. Use platform-specific MCP packages instead.', |
| 37 | + }, |
| 38 | + assert: { |
| 39 | + name: 'assert', |
| 40 | + description: |
| 41 | + 'DEPRECATED: Asserts that a specified condition, described in natural language, is true on the page. Use platform-specific MCP packages instead.', |
| 42 | + }, |
| 43 | + take_screenshot: { |
| 44 | + name: 'take_screenshot', |
| 45 | + description: |
| 46 | + 'DEPRECATED: Captures a screenshot of the currently active page. Use platform-specific MCP packages instead.', |
| 47 | + }, |
| 48 | + |
| 49 | + // Web-specific tools |
| 50 | + web_connect: { |
| 51 | + name: 'web_connect', |
| 52 | + description: |
| 53 | + 'DEPRECATED: Connect to web page by opening new tab with URL. Use @midscene/web-bridge-mcp instead.', |
| 54 | + }, |
| 55 | + |
| 56 | + // Android-specific tools |
| 57 | + midscene_android_connect: { |
| 58 | + name: 'midscene_android_connect', |
| 59 | + description: |
| 60 | + 'DEPRECATED: Connect to an Android device via ADB for automation. Use @midscene/android-mcp instead.', |
| 61 | + }, |
| 62 | + midscene_android_list_devices: { |
| 63 | + name: 'midscene_android_list_devices', |
| 64 | + description: |
| 65 | + 'DEPRECATED: List all connected Android devices available for automation. Use @midscene/android-mcp instead.', |
| 66 | + }, |
| 67 | + |
| 68 | + // iOS-specific tools |
| 69 | + midscene_ios_connect: { |
| 70 | + name: 'midscene_ios_connect', |
| 71 | + description: |
| 72 | + 'DEPRECATED: Connect to an iOS device via WebDriverAgent for automation. Use @midscene/ios-mcp instead.', |
| 73 | + }, |
| 74 | + midscene_ios_list_devices: { |
| 75 | + name: 'midscene_ios_list_devices', |
| 76 | + description: |
| 77 | + 'DEPRECATED: List all connected iOS devices available for automation. Use @midscene/ios-mcp instead.', |
| 78 | + }, |
| 79 | + |
| 80 | + // AI methods from Agent class |
| 81 | + aiTap: { |
| 82 | + name: 'aiTap', |
| 83 | + description: |
| 84 | + 'DEPRECATED: AI-powered tap/click action on elements. Use platform-specific MCP packages instead.', |
| 85 | + }, |
| 86 | + aiRightClick: { |
| 87 | + name: 'aiRightClick', |
| 88 | + description: |
| 89 | + 'DEPRECATED: AI-powered right-click action on elements. Use platform-specific MCP packages instead.', |
| 90 | + }, |
| 91 | + aiDoubleClick: { |
| 92 | + name: 'aiDoubleClick', |
| 93 | + description: |
| 94 | + 'DEPRECATED: AI-powered double-click action on elements. Use platform-specific MCP packages instead.', |
| 95 | + }, |
| 96 | + aiHover: { |
| 97 | + name: 'aiHover', |
| 98 | + description: |
| 99 | + 'DEPRECATED: AI-powered hover action on elements. Use platform-specific MCP packages instead.', |
| 100 | + }, |
| 101 | + aiInput: { |
| 102 | + name: 'aiInput', |
| 103 | + description: |
| 104 | + 'DEPRECATED: AI-powered input text into form fields. Use platform-specific MCP packages instead.', |
| 105 | + }, |
| 106 | + aiKeyboardPress: { |
| 107 | + name: 'aiKeyboardPress', |
| 108 | + description: |
| 109 | + 'DEPRECATED: AI-powered keyboard press action. Use platform-specific MCP packages instead.', |
| 110 | + }, |
| 111 | + aiScroll: { |
| 112 | + name: 'aiScroll', |
| 113 | + description: |
| 114 | + 'DEPRECATED: AI-powered scroll action on page or elements. Use platform-specific MCP packages instead.', |
| 115 | + }, |
| 116 | + aiAct: { |
| 117 | + name: 'aiAct', |
| 118 | + description: |
| 119 | + 'DEPRECATED: AI-powered natural language action execution. Use platform-specific MCP packages instead.', |
| 120 | + }, |
| 121 | + aiAction: { |
| 122 | + name: 'aiAction', |
| 123 | + description: |
| 124 | + 'DEPRECATED: Alias for aiAct. Use platform-specific MCP packages instead.', |
| 125 | + }, |
| 126 | + aiQuery: { |
| 127 | + name: 'aiQuery', |
| 128 | + description: |
| 129 | + 'DEPRECATED: AI-powered data extraction from the page. Use platform-specific MCP packages instead.', |
| 130 | + }, |
| 131 | + aiBoolean: { |
| 132 | + name: 'aiBoolean', |
| 133 | + description: |
| 134 | + 'DEPRECATED: AI-powered boolean query from the page. Use platform-specific MCP packages instead.', |
| 135 | + }, |
| 136 | + aiNumber: { |
| 137 | + name: 'aiNumber', |
| 138 | + description: |
| 139 | + 'DEPRECATED: AI-powered number extraction from the page. Use platform-specific MCP packages instead.', |
| 140 | + }, |
| 141 | + aiString: { |
| 142 | + name: 'aiString', |
| 143 | + description: |
| 144 | + 'DEPRECATED: AI-powered string extraction from the page. Use platform-specific MCP packages instead.', |
| 145 | + }, |
| 146 | + aiAsk: { |
| 147 | + name: 'aiAsk', |
| 148 | + description: |
| 149 | + 'DEPRECATED: AI-powered question answering from the page. Use platform-specific MCP packages instead.', |
| 150 | + }, |
| 151 | + aiLocate: { |
| 152 | + name: 'aiLocate', |
| 153 | + description: |
| 154 | + 'DEPRECATED: AI-powered element location on the page. Use platform-specific MCP packages instead.', |
| 155 | + }, |
| 156 | + aiAssert: { |
| 157 | + name: 'aiAssert', |
| 158 | + description: |
| 159 | + 'DEPRECATED: AI-powered assertion on page state. Use platform-specific MCP packages instead.', |
| 160 | + }, |
| 161 | + aiWaitFor: { |
| 162 | + name: 'aiWaitFor', |
| 163 | + description: |
| 164 | + 'DEPRECATED: AI-powered wait for condition to be true. Use platform-specific MCP packages instead.', |
| 165 | + }, |
| 166 | + ai: { |
| 167 | + name: 'ai', |
| 168 | + description: |
| 169 | + 'DEPRECATED: Shorthand for aiAct. Use platform-specific MCP packages instead.', |
| 170 | + }, |
| 171 | +}; |
| 172 | + |
| 173 | +/** |
| 174 | + * Deprecation tools manager that registers mock tools |
| 175 | + * All tools return deprecation notices |
| 176 | + */ |
| 177 | +export class DeprecationMidsceneTools extends BaseMidsceneTools { |
| 178 | + protected createTemporaryDevice() { |
| 179 | + // Return a minimal mock device that satisfies the interface |
| 180 | + // This device is never actually used since all tools return deprecation messages |
| 181 | + return { |
| 182 | + async getActionSpace() { |
| 183 | + return []; |
| 184 | + }, |
| 185 | + } as any; |
| 186 | + } |
| 187 | + |
| 188 | + protected async ensureAgent(_initParam?: string): Promise<BaseAgent> { |
| 189 | + // Return a minimal mock agent |
| 190 | + // This agent is never actually used since all tools return deprecation messages |
| 191 | + return { |
| 192 | + async getActionSpace() { |
| 193 | + return []; |
| 194 | + }, |
| 195 | + } as BaseAgent; |
| 196 | + } |
| 197 | + |
| 198 | + protected preparePlatformTools(): ToolDefinition[] { |
| 199 | + // Convert tools object to ToolDefinition array |
| 200 | + return Object.values(tools).map((tool) => ({ |
| 201 | + name: tool.name, |
| 202 | + description: tool.description, |
| 203 | + schema: { |
| 204 | + _deprecated: z.boolean().optional().describe('This tool is deprecated'), |
| 205 | + }, |
| 206 | + handler: async () => ({ |
| 207 | + content: [ |
| 208 | + { |
| 209 | + type: 'text' as const, |
| 210 | + text: DEPRECATION_MESSAGE, |
| 211 | + }, |
| 212 | + ], |
| 213 | + }), |
| 214 | + autoDestroy: false, |
| 215 | + })); |
| 216 | + } |
| 217 | +} |
0 commit comments