mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-12-06 10:33:33 +01:00
fix: mcp extension results
This commit is contained in:
1 parent
a4512c5c48
commit
fb38e2d6ff
3 files changed
+100
-11
No files matched your search
@@ -37,6 +37,11 @@ export async function mcpClient(base, token, profileId) {
|
||||
const body = await call(name, args);
|
||||
assert.equal(body.error, undefined, JSON.stringify(body));
|
||||
assert.notEqual(body.result.isError, true, JSON.stringify(body.result));
|
||||
// MCP clients refuse a result that is not an object with a content list.
|
||||
assert.ok(
|
||||
!Array.isArray(body.result) && Array.isArray(body.result.content),
|
||||
`${name} answered without content: ${JSON.stringify(body.result)}`,
|
||||
);
|
||||
return body.result.content[0];
|
||||
};
|
||||
const toolJson = async (name, args) =>
|
||||
|
||||
@@ -1021,6 +1021,79 @@ test("MCP update_profile stores launch arguments and refuses arguments it does n
|
||||
);
|
||||
});
|
||||
|
||||
test("MCP extension tools answer with content", async () => {
|
||||
await withApp(
|
||||
"integrations-mcp-extensions",
|
||||
async (app) => {
|
||||
await seedTerms(app);
|
||||
const settings = await app.invoke("get_app_settings");
|
||||
const saved = await app.invoke("save_app_settings", {
|
||||
settings: {
|
||||
...settings,
|
||||
api_enabled: true,
|
||||
api_port: 0,
|
||||
api_token: null,
|
||||
onboarding_completed: true,
|
||||
},
|
||||
});
|
||||
const port = await app.invoke("start_api_server", { port: 0 });
|
||||
const profile = await app.invoke("create_browser_profile_new", {
|
||||
name: "MCP Extensions",
|
||||
browserStr: "wayfern",
|
||||
version: TEST_BROWSER_VERSION,
|
||||
releaseType: "stable",
|
||||
proxyId: null,
|
||||
vpnId: null,
|
||||
wayfernConfig: { fingerprint: "{}" },
|
||||
groupId: null,
|
||||
ephemeral: false,
|
||||
dnsBlocklist: null,
|
||||
launchHook: null,
|
||||
});
|
||||
const { tool, toolJson } = await mcpClient(
|
||||
`http://127.0.0.1:${port}`,
|
||||
saved.api_token,
|
||||
profile.id,
|
||||
);
|
||||
|
||||
assert.deepEqual(await toolJson("list_extensions"), []);
|
||||
const group = await toolJson("create_extension_group", { name: "Shop" });
|
||||
assert.equal(group.name, "Shop");
|
||||
assert.deepEqual(
|
||||
(await toolJson("list_extension_groups")).map((g) => g.id),
|
||||
[group.id],
|
||||
);
|
||||
const renamed = await toolJson("update_extension_group", {
|
||||
group_id: group.id,
|
||||
name: "Shop EU",
|
||||
});
|
||||
assert.equal(renamed.name, "Shop EU");
|
||||
assert.match(
|
||||
(
|
||||
await tool("assign_extension_group_to_profile", {
|
||||
extension_group_id: group.id,
|
||||
})
|
||||
).text,
|
||||
/assigned/,
|
||||
);
|
||||
assert.match(
|
||||
(
|
||||
await tool("assign_extension_group_to_profile", {
|
||||
extension_group_id: "",
|
||||
})
|
||||
).text,
|
||||
/removed/,
|
||||
);
|
||||
assert.match(
|
||||
(await tool("delete_extension_group", { group_id: group.id })).text,
|
||||
/deleted/,
|
||||
);
|
||||
assert.deepEqual(await toolJson("list_extension_groups"), []);
|
||||
},
|
||||
{ extraEnv: { WAYFERN_TEST_TOKEN: "e2e-local-extension-tools" } },
|
||||
);
|
||||
});
|
||||
|
||||
test("an agent's feedback goes anonymously and its reply says no answer will come", async () => {
|
||||
const capture = await feedbackCaptureServer();
|
||||
try {
|
||||
|
||||
+22
-11
@@ -10719,7 +10719,7 @@ impl McpServer {
|
||||
message: format!("Failed to list extensions: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(extensions).unwrap())
|
||||
Self::json_content(&extensions)
|
||||
}
|
||||
|
||||
async fn handle_list_extension_groups(&self) -> Result<serde_json::Value, McpError> {
|
||||
@@ -10736,7 +10736,7 @@ impl McpServer {
|
||||
message: format!("Failed to list extension groups: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(groups).unwrap())
|
||||
Self::json_content(&groups)
|
||||
}
|
||||
|
||||
async fn handle_add_extension(
|
||||
@@ -10780,7 +10780,7 @@ impl McpServer {
|
||||
message: format!("Failed to add extension: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(extension).unwrap())
|
||||
Self::json_content(&extension)
|
||||
}
|
||||
|
||||
async fn handle_update_extension(
|
||||
@@ -10837,7 +10837,7 @@ impl McpServer {
|
||||
message: format!("Failed to update extension: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(extension).unwrap())
|
||||
Self::json_content(&extension)
|
||||
}
|
||||
|
||||
async fn handle_create_extension_group(
|
||||
@@ -10865,7 +10865,7 @@ impl McpServer {
|
||||
message: format!("Failed to create extension group: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(group).unwrap())
|
||||
Self::json_content(&group)
|
||||
}
|
||||
|
||||
async fn handle_update_extension_group(
|
||||
@@ -10908,7 +10908,7 @@ impl McpServer {
|
||||
message: format!("Failed to update extension group: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(group).unwrap())
|
||||
Self::json_content(&group)
|
||||
}
|
||||
|
||||
async fn handle_add_extension_to_group(
|
||||
@@ -10931,7 +10931,7 @@ impl McpServer {
|
||||
message: format!("Failed to add extension to group: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(group).unwrap())
|
||||
Self::json_content(&group)
|
||||
}
|
||||
|
||||
async fn handle_remove_extension_from_group(
|
||||
@@ -10954,7 +10954,7 @@ impl McpServer {
|
||||
message: format!("Failed to remove extension from group: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(group).unwrap())
|
||||
Self::json_content(&group)
|
||||
}
|
||||
|
||||
fn group_and_extension_ids(arguments: &serde_json::Value) -> Result<(&str, &str), McpError> {
|
||||
@@ -11004,7 +11004,9 @@ impl McpServer {
|
||||
message: format!("Failed to delete extension: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::json!({"success": true}))
|
||||
Ok(serde_json::json!({
|
||||
"content": [{ "type": "text", "text": format!("Extension '{extension_id}' deleted") }]
|
||||
}))
|
||||
}
|
||||
|
||||
async fn handle_delete_extension_group_mcp(
|
||||
@@ -11037,7 +11039,9 @@ impl McpServer {
|
||||
if let Err(e) = crate::events::emit_empty("extensions-changed") {
|
||||
log::warn!("Event not emitted event=extensions-changed err=\"{e}\"");
|
||||
}
|
||||
Ok(serde_json::json!({"success": true}))
|
||||
Ok(serde_json::json!({
|
||||
"content": [{ "type": "text", "text": format!("Extension group '{group_id}' deleted") }]
|
||||
}))
|
||||
}
|
||||
|
||||
async fn handle_assign_extension_group_to_profile(
|
||||
@@ -11105,7 +11109,14 @@ impl McpServer {
|
||||
message: format!("Failed to assign extension group: {e}"),
|
||||
data: None,
|
||||
})?;
|
||||
Ok(serde_json::to_value(profile).unwrap())
|
||||
let text = match &profile.extension_group_id {
|
||||
Some(group_id) => format!(
|
||||
"Extension group '{group_id}' assigned to profile '{}'",
|
||||
profile.name
|
||||
),
|
||||
None => format!("Extension group removed from profile '{}'", profile.name),
|
||||
};
|
||||
Ok(serde_json::json!({ "content": [{ "type": "text", "text": text }] }))
|
||||
}
|
||||
|
||||
async fn handle_get_team_locks(&self) -> Result<serde_json::Value, McpError> {
|
||||
|
||||
Reference in new issue
Block a user