Skip to content

Commit e8b070e

Browse files
committed
fix(shared): hide deprecated mcp behavior flag
1 parent 1388e9c commit e8b070e

7 files changed

Lines changed: 44 additions & 10 deletions

File tree

‎apps/site/docs/en/mcp.mdx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ Common flags:
207207
- `--wait-after-action <ms>` maps to `waitAfterAction`: wait time after each action execution. The default is `300`.
208208
- `--replanning-cycle-limit <n>` maps to `replanningCycleLimit`: maximum number of `aiAct` replanning cycles.
209209
- `--ai-act-context <text>` maps to `aiActContext`: extra background knowledge for `aiAct`.
210-
- `--ai-action-context <text>` maps to `aiActionContext`: deprecated alias for `aiActContext`.
211210
- `--screenshot-shrink-factor <n>` maps to `screenshotShrinkFactor`: shrink screenshots before sending them to the AI model.
212211

213-
In MCP calls, keep the API camelCase name and put it under the platform namespace: `android.waitAfterAction`, `harmony.waitAfterAction`, `ios.waitAfterAction`, `computer.waitAfterAction`, or `web.waitAfterAction`. The same pattern applies to `replanningCycleLimit`, `aiActContext`, `aiActionContext`, and `screenshotShrinkFactor`.
212+
In MCP calls, keep the API camelCase name and put it under the platform namespace: `android.waitAfterAction`, `harmony.waitAfterAction`, `ios.waitAfterAction`, `computer.waitAfterAction`, or `web.waitAfterAction`. The same pattern applies to `replanningCycleLimit`, `aiActContext`, and `screenshotShrinkFactor`.
214213

215214
These parameters are part of the Agent init args for that tool call. If a later call changes them, or omits them after setting them, Midscene rebuilds the Agent so the next call uses the new effective configuration. For Web tools, `web.url` opens or navigates to the URL each time it is supplied; omit it to keep using the current page.
216215

‎apps/site/docs/zh/mcp.mdx‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,9 @@ midscene-ios assert --prompt "成功提示可见" --screenshot-shrink-factor 2
207207
- `--wait-after-action <ms>` 对应 `waitAfterAction`:每次动作执行后的等待时间,默认值为 `300`。
208208
- `--replanning-cycle-limit <n>` 对应 `replanningCycleLimit`:`aiAct` 的最大重规划次数。
209209
- `--ai-act-context <text>` 对应 `aiActContext`:传给 `aiAct` 的额外背景信息。
210-
- `--ai-action-context <text>` 对应 `aiActionContext`:`aiActContext` 的旧参数名,不建议继续使用。
211210
- `--screenshot-shrink-factor <n>` 对应 `screenshotShrinkFactor`:发送给 AI 模型前的截图压缩倍率。
212211

213-
在 MCP 调用中,保留 API 里的 camelCase 参数名,并放在平台 namespace 下:`android.waitAfterAction`、`harmony.waitAfterAction`、`ios.waitAfterAction`、`computer.waitAfterAction` 或 `web.waitAfterAction`。`replanningCycleLimit`、`aiActContext`、`aiActionContext` 和 `screenshotShrinkFactor` 也使用同样的规则。
212+
在 MCP 调用中,保留 API 里的 camelCase 参数名,并放在平台 namespace 下:`android.waitAfterAction`、`harmony.waitAfterAction`、`ios.waitAfterAction`、`computer.waitAfterAction` 或 `web.waitAfterAction`。`replanningCycleLimit`、`aiActContext` 和 `screenshotShrinkFactor` 也使用同样的规则。
214213

215214
这些参数属于当前工具调用的 Agent init args。后续调用如果改变这些参数,或在设置后省略它们,Midscene 会重建 Agent,让下一次调用使用新的有效配置。对于 Web 工具,只要传入 `web.url`,每次都会打开或导航到该 URL;省略它则继续使用当前页面。
216215

‎packages/android/tests/unit-test/cli.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ describe('Android CLI integration', () => {
215215
expect(output.join('\n')).toContain('Default: 300ms');
216216
expect(output.join('\n')).toContain('--replanning-cycle-limit');
217217
expect(output.join('\n')).toContain('--ai-act-context');
218+
expect(output.join('\n')).not.toContain('--ai-action-context');
219+
expect(output.join('\n')).not.toContain('--aiActionContext');
218220
expect(output.join('\n')).toContain('--screenshot-shrink-factor');
219221
expect(output.join('\n')).toContain(
220222
'high values may reduce recognition quality, especially on mobile',

‎packages/android/tests/unit-test/mcp-tools.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ describe('AndroidMidsceneTools', () => {
161161

162162
expect(takeScreenshotTool?.schema).toHaveProperty('android.deviceId');
163163
expect(actTool?.schema).toHaveProperty('android.deviceId');
164+
expect(takeScreenshotTool?.schema).toHaveProperty('android.aiActContext');
165+
expect(takeScreenshotTool?.schema).not.toHaveProperty(
166+
'android.aiActionContext',
167+
);
164168
});
165169

166170
it('prefers namespaced deviceId over top-level bare deviceId', async () => {

‎packages/shared/src/mcp/agent-behavior-init-args.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,18 @@ export interface AgentBehaviorInitArgs {
88
screenshotShrinkFactor?: number;
99
}
1010

11+
type ExposedAgentBehaviorInitArgKey = Exclude<
12+
keyof AgentBehaviorInitArgs,
13+
'aiActionContext'
14+
>;
15+
1116
export const agentBehaviorInitArgShape = {
1217
aiActContext: z
1318
.string()
1419
.optional()
1520
.describe(
1621
'Background knowledge passed to aiAct. Default: no extra context.',
1722
),
18-
aiActionContext: z
19-
.string()
20-
.optional()
21-
.describe('Deprecated alias for aiActContext. Default: no extra context.'),
2223
replanningCycleLimit: z
2324
.number()
2425
.int()
@@ -41,7 +42,7 @@ export const agentBehaviorInitArgShape = {
4142
.describe(
4243
'Screenshot shrink factor before sending images to AI. Default: 1; high values may reduce recognition quality, especially on mobile.',
4344
),
44-
} satisfies Record<keyof AgentBehaviorInitArgs, z.ZodTypeAny>;
45+
} satisfies Record<ExposedAgentBehaviorInitArgKey, z.ZodTypeAny>;
4546

4647
export function extractAgentBehaviorInitArgs(
4748
extracted: Partial<AgentBehaviorInitArgs> | undefined,

‎packages/shared/src/mcp/tool-generator.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
129129
function makePromptOptional(
130130
shape: Record<string, z.ZodTypeAny>,
131131
wrapInOptional: boolean,
132+
description?: string | null,
132133
): z.ZodTypeAny {
133134
const newShape = { ...shape };
134135
newShape.prompt = shape.prompt.optional();
@@ -137,6 +138,9 @@ function makePromptOptional(
137138
if (wrapInOptional) {
138139
newSchema = newSchema.optional();
139140
}
141+
if (description) {
142+
newSchema = newSchema.describe(description);
143+
}
140144
return newSchema;
141145
}
142146

@@ -151,7 +155,10 @@ function transformSchemaField(
151155
const shape = getZodObjectShape(innerValue);
152156

153157
if (shape && isMidsceneLocatorField(innerValue)) {
154-
return [key, makePromptOptional(shape, isOptional)];
158+
return [
159+
key,
160+
makePromptOptional(shape, isOptional, getZodDescription(value)),
161+
];
155162
}
156163
return [key, value];
157164
}

‎packages/shared/tests/unit-test/tool-generator.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,28 @@ describe('generateToolsFromActionSpace', () => {
108108
});
109109
});
110110

111+
it('preserves locate field descriptions after making locate.prompt optional', () => {
112+
const [tool] = generateToolsFromActionSpace(
113+
[
114+
{
115+
name: 'Tap',
116+
description: 'Tap the element',
117+
paramSchema: z.object({
118+
locate: locateSchema.describe('The element to be tapped'),
119+
}),
120+
},
121+
],
122+
async () => ({
123+
getActionSpace: vi.fn().mockResolvedValue([]),
124+
page: {
125+
screenshotBase64: vi.fn().mockResolvedValue(screenshotBase64),
126+
},
127+
}),
128+
);
129+
130+
expect(tool.schema.locate.description).toBe('The element to be tapped');
131+
});
132+
111133
it('falls back to aiAction when direct action execution is unavailable', async () => {
112134
const aiAction = vi.fn().mockResolvedValue(undefined);
113135
const [tool] = generateToolsFromActionSpace(actionSpace, async () => ({

0 commit comments

Comments
 (0)