Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/frontend/src/components/tool-editor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,15 @@ export function ToolEditor({
// What the loaded tool has beyond what the form renders; written back on save.
const [preserved, setPreserved] = useState<PreservedMapping | undefined>(undefined);

// Initialize from existing tool
// Initialize from existing tool. The connector page passes `existingTool`
// as a new object on every render, so the reset is keyed on its content:
// keyed on the object, any re-render of the page (a status message, the
// "Add Tool" panel opening) wiped what the user had typed.
const existingToolJson = existingTool ? JSON.stringify(existingTool) : '';
useEffect(() => {
if (existingTool) {
const form = formStateFromParsed(parseExistingTool(existingTool, type));
if (existingToolJson) {
const loaded = JSON.parse(existingToolJson) as ExistingTool;
const form = formStateFromParsed(parseExistingTool(loaded, type));
setName(form.name);
setDescription(form.description);
setMethod(form.method);
Expand All @@ -219,7 +224,7 @@ export function ToolEditor({
setResponseMappingExtra(form.responseMappingExtra);
setPreserved(form.preserved);
}
}, [existingTool, type]);
}, [existingToolJson, type]);

// Auto-detect path params from {param} patterns
const detectPathParams = useCallback((pathStr: string) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/frontend/src/lib/sentry-scrub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ export const BROWSER_IGNORE_ERRORS: Array<string | RegExp> = [
// A WebExtension (runtime.sendMessage is extension-only API; the site
// never calls it) messaging a tab that has closed (ANYTHINGMCP-WEBSITE-J on the site).
/Invalid call to runtime\.sendMessage\(\)\. Tab not found/,
// Chrome's answer when an extension's content script messages an extension
// page that is not listening; the app never calls chrome.runtime
// (ANYTHINGMCP-CLOUD-FRONTEND-13, on /login).
/^Could not establish connection\. Receiving end does not exist\.$/,
// Google Tag Manager's own beacons blocked by an ad blocker or dropped by
// the network; the SDK names the host in the message (ANYTHINGMCP-CLOUD-FRONTEND-D).
// GA4 sends its beacons to analytics.google.com (ANYTHINGMCP-CLOUD-FRONTEND-N, -P),
Expand Down
86 changes: 86 additions & 0 deletions packages/frontend/tests/e2e/tool-editor-keeps-edits.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { expect, test } from '@playwright/test';

/**
* The connector page hands the tool editor a new `existingTool` object on
* every render. The editor reset its form whenever that object changed, so
* any re-render of the page while a tool was open (here: opening the
* "Add Tool" panel) threw away what the user had typed.
*/

const USER = {
id: 'u1',
email: 'test@example.com',
name: 'Test User',
role: 'ADMIN',
organizationId: 'o1',
emailVerified: true,
};

const CONNECTOR = {
id: 'c1',
name: 'Tool Edit Connector',
type: 'REST',
baseUrl: 'https://api.example.com',
authType: 'NONE',
authConfig: null,
isActive: true,
headers: {},
envVars: { API_REGION: 'eu' },
maskedEnvVars: [],
config: {},
tools: [
{
id: 't1',
name: 'get_users',
description: 'List users.',
isEnabled: true,
parameters: { type: 'object', properties: {} },
endpointMapping: { method: 'GET', path: '/users' },
responseMapping: null,
},
],
createdAt: '2026-09-01T00:00:00Z',
userId: 'u1',
organizationId: 'o1',
};

test('editing a tool keeps typed text when the page re-renders', async ({ page, baseURL }) => {
await page.context().addCookies([{ name: 'amcp_token', value: 'test-token', url: baseURL! }]);
await page.addInitScript((user) => {
localStorage.setItem('amcp_token', 'test-token');
localStorage.setItem('amcp_user', JSON.stringify(user));
}, USER);

await page.route(/\/api\//, async (route) => {
const url = route.request().url();
const json = (body: unknown) =>
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify(body) });
if (url.includes('/api/connectors/proxy-availability')) return json({ available: false });
if (url.includes('/api/connectors/c1/catalog-diff')) return json({ catalogManaged: false });
if (url.includes('/api/connectors/c1')) return json(CONNECTOR);
if (url.includes('/api/users/me/onboarding-state')) return json({ onboardingCompletedAt: '2026-01-01T00:00:00Z' });
if (url.includes('/api/users/me')) return json(USER);
if (url.includes('/api/organizations/current')) return json({ id: 'o1', name: 'Acme', createdAt: '2026-01-01' });
if (url.includes('/api/organizations/mine')) return json([{ id: 'o1', name: 'Acme', role: 'ADMIN', joinedAt: '2026-01-01' }]);
if (url.includes('/api/license/status')) return json({ plan: 'community', status: 'active' });
if (url.includes('/api/connectors')) return json([CONNECTOR]);
return json({});
});

await page.goto('/connectors/c1');

const card = page.locator('div', { has: page.getByText('get_users', { exact: true }) }).filter({
has: page.getByRole('button', { name: 'Edit', exact: true }),
});
await card.last().getByRole('button', { name: 'Edit', exact: true }).click();

const nameField = page.getByPlaceholder('get_users');
await expect(nameField).toHaveValue('get_users');
await nameField.fill('list_active_users');

// Re-renders the page while the editor stays open.
await page.getByRole('button', { name: 'Add Tool' }).click();

await expect(page.getByPlaceholder('get_users')).toHaveCount(2);
await expect(page.getByPlaceholder('get_users').last()).toHaveValue('list_active_users');
});
Loading