豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit b98266b

Browse files
committed
address comments
1 parent d33cf42 commit b98266b

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/tools/ToolDefinition.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ export type Context = Readonly<{
198198
triggerExtensionAction(id: string): Promise<void>;
199199
listExtensions(): InstalledExtension[];
200200
getExtension(id: string): InstalledExtension | undefined;
201-
setInPageTools(toolGroup?: ToolGroup<InPageToolDefinition>): void;
202201
getInPageTools(): ToolGroup<InPageToolDefinition> | undefined;
203202
getSelectedMcpPage(): McpPage;
204203
getExtensionServiceWorkers(): ExtensionServiceWorker[];

src/tools/inPage.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,27 @@ export const executeInPageTool = definePageTool({
6666
schema: {
6767
toolName: zod.string().describe('The name of the tool to execute'),
6868
params: zod
69-
.record(zod.string(), zod.unknown())
69+
.string()
7070
.optional()
71-
.describe('The parameters to pass to the tool'),
71+
.describe('The JSON-stringified parameters to pass to the tool'),
7272
},
7373
handler: async (request, response, context) => {
7474
const page = context.getSelectedMcpPage();
7575
const toolName = request.params.toolName;
76-
const params = request.params.params ?? {};
76+
let params: Record<string, unknown> = {};
77+
if (request.params.params) {
78+
try {
79+
const parsed = JSON.parse(request.params.params);
80+
if (typeof parsed === 'object' && parsed !== null) {
81+
params = parsed;
82+
} else {
83+
throw new Error('Parsed params is not an object');
84+
}
85+
} catch (e) {
86+
const errorMessage = e instanceof Error ? e.message : String(e);
87+
throw new Error(`Failed to parse params as JSON: ${errorMessage}`);
88+
}
89+
}
7790

7891
const toolGroup = context.getInPageTools();
7992
const tool = toolGroup?.tools.find(t => t.name === toolName);

src/tools/input.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ async function fillFormElement(
217217
}
218218
}
219219

220+
// here
220221
export const fill = definePageTool({
221222
name: 'fill',
222223
description: `Type text into a input, text area or select an option from a <select> element.`,

tests/tools/inPage.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ describe('inPage', () => {
194194
{
195195
params: {
196196
toolName: 'test-tool',
197-
params: {arg: 'value'},
197+
params: JSON.stringify({arg: 'value'}),
198198
},
199199
page: context.getSelectedMcpPage(),
200200
},
@@ -233,7 +233,7 @@ describe('inPage', () => {
233233
{
234234
params: {
235235
toolName: 'missing-tool',
236-
params: {},
236+
params: JSON.stringify({}),
237237
},
238238
page: context.getSelectedMcpPage(),
239239
},
@@ -282,7 +282,7 @@ describe('inPage', () => {
282282
{
283283
params: {
284284
toolName: 'test-tool',
285-
params: {}, // Missing required 'arg'
285+
params: JSON.stringify({}), // Missing required 'arg'
286286
},
287287
page: context.getSelectedMcpPage(),
288288
},
@@ -326,7 +326,7 @@ describe('inPage', () => {
326326
{
327327
params: {
328328
toolName: 'test-tool',
329-
params: {},
329+
params: JSON.stringify({}),
330330
},
331331
page: context.getSelectedMcpPage(),
332332
},

0 commit comments

Comments
 (0)