-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmcp-server.spec.ts
More file actions
1447 lines (1193 loc) · 50.6 KB
/
Copy pathmcp-server.spec.ts
File metadata and controls
1447 lines (1193 loc) · 50.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import type { Page } from "@playwright/test";
import { expect, test } from "../../../../fixtures/fixtures";
import { adjustScreenView } from "../../../../helpers/ui/adjust-screen-view";
import { awaitBootstrapTest } from "../../../../helpers/other/await-bootstrap-test";
import { openAddMcpServerModal } from "../../../../helpers/mcp/open-add-mcp-server-modal";
import { zoomOut } from "../../../../helpers/ui/zoom-out";
import { getAuthToken } from "../../../../helpers/auth/get-auth-token";
import { deleteFlow } from "../../../../helpers/flows/delete-flow";
import { openFlowById } from "../../../../helpers/flows/open-flow-by-id";
/**
* Add-MCP-Server modal: stdio / HTTP registration, field persistence and tool
* refresh. Spec doc: `docs/mcp/server/mcp-server.md`.
*
* STDIO CONTRACT (#1091). Langflow requires `command` to be a SINGLE executable
* — options and the package go in `args`. Registering
* "npx @modelcontextprotocol/server-everything" as the command is refused with
* a 422 ("MCP stdio command must be a single executable name or path"). The
* rule arrived with the multi-tenant hardening forward-port (upstream #14073,
* 2026-07-15) so every policy layer sees the same argv; `npx`/`uvx` themselves
* are still allowlisted. Every stdio registration below therefore fills
* `stdio-command-input` with the bare executable and `stdio-args_N` with the
* rest. The last test in this file pins that contract directly.
*/
// Package runners are `npx`, not `uvx`, wherever the subprocess must actually
// come up: the published `mcp-server-fetch`/`mcp-server-time` packages this file
// used to register now fail at import against the current `mcp` Python SDK
// (`McpError` renamed to `MCPError`), and pinning the server version does not
// help because its `mcp` dependency floats. That is a third-party breakage, not
// Langflow's — see the spec doc. `uvx` stays covered as a command by the
// field-persistence test, which never starts the subprocess.
const NPX = "npx";
const PKG_EVERYTHING = "@modelcontextprotocol/server-everything";
const PKG_SEQUENTIAL = "@modelcontextprotocol/server-sequential-thinking";
// `npx` downloads the package on a cold container, so the FIRST tool list of a
// run can take far longer than every dropdown interaction that follows it. The
// sibling stdio test in `mcp-client-regression.spec.ts` needed exactly this
// budget for the same reason (#463); the 30 s this file carried was never
// exercised in CI, because none of these tests were `@stable` until #1091.
const TOOL_LIST_TIMEOUT = 120_000;
// Flow ids observed on `POST /api/v1/flows` 201, plus the MCP servers each test
// registered. Pattern A from authoring-conventions: `awaitBootstrapTest` runs
// before the blank-flow / starter click, so the canvas URL id is the stale
// bootstrap one (#681) and only the response ids are trustworthy. Deleting a
// transient id 404s harmlessly — `deleteFlow` treats 404 as done.
const createdFlowIds: string[] = [];
const registeredServers: string[] = [];
/** Server names currently registered on the instance. */
async function listMcpServerNames(page: Page): Promise<string[]> {
const authHeader = await getAuthToken(page.request);
const resp = await page.request.get("/api/v2/mcp/servers", {
headers: authHeader ? { Authorization: authHeader } : undefined,
});
// Checked, not assumed: an error body is not an array, so an unchecked read
// fails as `servers.map is not a function` inside whichever assertion called
// this — hiding the status that actually explains the run.
if (!resp.ok()) {
throw new Error(
`GET /api/v2/mcp/servers: ${resp.status()} — ${await resp.text()}`,
);
}
const servers: Array<{ name: string }> = await resp.json();
return servers.map((s) => s.name);
}
test.beforeEach(async ({ page }) => {
createdFlowIds.length = 0;
registeredServers.length = 0;
page.on("response", (resp) => {
if (
resp.url().includes("/api/v1/flows") &&
resp.request().method() === "POST" &&
resp.status() === 201
) {
resp
.json()
.then((body: { id?: string }) => {
if (body?.id) createdFlowIds.push(body.id);
})
.catch(() => {}); // non-JSON / batch payloads
}
});
});
// Id-scoped cleanup — never a wipe (#553). The servers are listed first so a
// test that already deleted its own through the UI (the happy path for most of
// them) does not issue a 404 delete on every run.
test.afterEach(async ({ request }) => {
const names = registeredServers.splice(0);
const ids = createdFlowIds.splice(0);
if (names.length === 0 && ids.length === 0) return;
const bearer = await getAuthToken(request);
const options = bearer ? { headers: { Authorization: bearer } } : undefined;
if (names.length > 0) {
const resp = await request.get("/api/v2/mcp/servers", options);
const existing: string[] = resp.ok()
? ((await resp.json()) as Array<{ name: string }>).map((s) => s.name)
: names;
for (const name of names) {
if (existing.includes(name)) {
const del = await request.delete(
`/api/v2/mcp/servers/${name}`,
options,
);
// Warn rather than throw: the flow cleanup below still has to run, and
// a silent failure here is what lets registered servers accumulate on
// the shared instance (the buildup #545 set out to stop).
if (!del.ok()) {
console.warn(
`⚠️ MCP server cleanup failed: ${name} — ${del.status()} ${await del.text()}`,
);
}
}
}
}
// Deliberately NOT swallowed, unlike the precedent in
// `agent-tool-name-validation.spec.ts` — `deleteFlow` throws so a cleanup
// regression is visible instead of silent (see its docstring). A transient id
// 404s, which it treats as done, so this only fires on a real failure.
for (const id of ids) {
await deleteFlow(request, id, options);
}
});
// Quarantined for #1266 — recurrent flake on a TRANSPORT-level signature:
// `apiRequestContext.get: Timeout 20000ms exceeded.` on GET
// /api/v2/mcp/servers?action_count=true, same signature on the 2026-07-30,
// 2026-08-03 and 2026-08-04 dailies. Filed as load/reachability about this
// spec, not about changing tool mode (CONTRIBUTING.md -> Infra-signature
// exemption: a spec that keeps appearing as collateral while others do not).
// Lifting the quarantine (remove test.fixme + restore @stable) is a
// deliverable of #1266.
test.fixme(
"user must be able to change mode of MCP tools without any issues",
{ tag: ["@release", "@workspace", "@components", "@mcp"] },
async ({ page }) => {
(page as any).allowFlowErrors();
await page.waitForTimeout(5000);
await awaitBootstrapTest(page);
await page.waitForSelector('[data-testid="blank-flow"]', {
timeout: 30000,
});
await page.getByTestId("blank-flow").click();
await page.getByTestId("sidebar-nav-mcp").click();
// Use the first available MCP server component instead of a specific one
const firstServerBtn = page.locator('[data-testid^="add-component-button-"]').first();
await expect(firstServerBtn).toBeVisible({ timeout: 30000 });
await firstServerBtn.click();
// See if the color matches
const isDark = await page.evaluate(() => {
return document.body.classList.contains("dark");
});
for (const path of await page
.getByTestId("generic-node-title-arrangement")
.getByTestId("icon-Mcp")
.locator("path")
.all()) {
const color = await path.evaluate(
(el) => window.getComputedStyle(el).fill,
);
expect(color).toBe(isDark ? "rgb(255, 255, 255)" : "rgb(0, 0, 0)");
}
await adjustScreenView(page, { numberOfZoomOut: 3 });
await openAddMcpServerModal(page);
await page.getByTestId("stdio-tab").click();
await page.waitForSelector('[data-testid="stdio-name-input"]', {
state: "visible",
timeout: 30000,
});
const randomSuffix = Math.floor(Math.random() * 90000) + 10000; // 5-digit random number
const testName = `test_server_${randomSuffix}`;
registeredServers.push(testName);
await page.getByTestId("stdio-name-input").fill(testName);
await page.getByTestId("stdio-command-input").fill(NPX);
await page.getByTestId("stdio-args_0").fill(PKG_EVERYTHING);
await page.getByTestId("add-mcp-server-button").click();
// Poll API until server tools are loaded before interacting with dropdown
await expect
.poll(
async () => {
const resp = await page.request.get(
"/api/v2/mcp/servers?action_count=true",
);
const servers: Array<{ name: string; toolsCount: number | null }> =
await resp.json();
return servers.find((s) => s.name === testName)?.toolsCount ?? null;
},
{ timeout: TOOL_LIST_TIMEOUT, intervals: [3000] },
)
.not.toBeNull();
await expect(page.getByTestId("dropdown_str_tool")).toBeVisible({
timeout: 30000,
});
await page.evaluate(() => {
(
document.querySelector('[data-testid="dropdown_str_tool"]') as HTMLElement
)?.click();
});
await page.waitForFunction(
() => !!document.querySelector('[data-testid="echo-0-option"]'),
{ timeout: 15000 },
);
await page.evaluate(() => {
(
document.querySelector('[data-testid="echo-0-option"]') as HTMLElement
)?.click();
});
await adjustScreenView(page);
// The selected tool's own inputs arrive with a node rebuild that lands a
// beat after the option click, so this needs an auto-retrying assertion —
// a bare count() samples the node before `message` is on it. The `@stable`
// sibling that selects the same echo tool waits the same way
// (`mcp-client-regression.spec.ts`), which is why it never hit this race;
// here it stayed invisible because the registration above had been failing
// since 2026-07-15 and the test never got this far (#1091).
await expect(page.getByTestId("popover-anchor-input-message")).toBeVisible({
timeout: 30000,
});
await page.getByTestId("user_menu_button").click({ timeout: 3000 });
await page.getByTestId("menu_settings_button").click({ timeout: 3000 });
await page.waitForTimeout(500);
await page.waitForSelector('[data-testid="sidebar-nav-MCP Servers"]', {
timeout: 30000,
});
await page.getByTestId("sidebar-nav-MCP Servers").click({ timeout: 3000 });
await page.waitForSelector('[data-testid="add-mcp-server-button-page"]', {
timeout: 3000,
});
await expect(page.getByText(testName)).toBeVisible({
timeout: 3000,
});
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 3000 });
await page
.getByText("Edit", { exact: true })
.first()
.click({ timeout: 3000 });
await page.waitForTimeout(500);
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "visible",
timeout: 30000,
});
await expect(page.getByTestId("json-tab")).toBeDisabled({
timeout: 3000,
});
await expect(page.getByTestId("stdio-tab")).not.toBeDisabled({
timeout: 3000,
});
await expect(page.getByTestId("http-tab")).toBeDisabled({
timeout: 3000,
});
// Both halves of the split must round-trip: a backend that dropped `args`
// on save would still show the right command.
expect(await page.getByTestId("stdio-command-input").inputValue()).toBe(NPX);
expect(await page.getByTestId("stdio-args_0").inputValue()).toBe(
PKG_EVERYTHING,
);
await page.waitForTimeout(500);
await page.getByTestId("add-mcp-server-button").click();
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 30000 });
await page.waitForTimeout(500);
await page
.getByText("Delete", { exact: true })
.first()
.click({ timeout: 3000 });
await page.waitForSelector(
'[data-testid="btn_delete_delete_confirmation_modal"]',
{
timeout: 3000,
},
);
await page
.getByTestId("btn_delete_delete_confirmation_modal")
.click({ timeout: 3000 });
await page.waitForSelector('[data-testid="add-mcp-server-button-page"]', {
timeout: 3000,
});
await expect(page.getByText(testName)).not.toBeVisible({
timeout: 10000,
});
},
);
test(
"user must be able to add and delete MCP server from sidebar",
{ tag: ["@release", "@workspace", "@components", "@mcp", "@stable"] },
async ({ page }) => {
(page as any).allowFlowErrors();
await awaitBootstrapTest(page);
await page.waitForSelector('[data-testid="blank-flow"]', {
timeout: 30000,
});
await page.getByTestId("blank-flow").click();
await page.getByTestId("sidebar-nav-mcp").click();
await page.waitForTimeout(500);
const sidebarButton = page.getByTestId("sidebar-add-mcp-server-button");
const fallbackButton = page.getByTestId("add-mcp-server-button-sidebar");
if (await sidebarButton.isVisible({ timeout: 30000 }).catch(() => false)) {
await sidebarButton.click();
} else {
await fallbackButton.click();
}
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "visible",
timeout: 30000,
});
await page.getByTestId("stdio-tab").click();
await page.waitForSelector('[data-testid="stdio-name-input"]', {
state: "visible",
timeout: 30000,
});
const randomSuffix = Math.floor(Math.random() * 90000) + 10000; // 5-digit random number
const testName = `test_server_${randomSuffix}`;
registeredServers.push(testName);
await page.getByTestId("stdio-name-input").fill(testName);
await page.waitForTimeout(500);
await page.getByTestId("stdio-command-input").fill(NPX);
await page.getByTestId("stdio-args_0").fill(PKG_EVERYTHING);
await page.getByTestId("add-mcp-server-button").click();
await page
.getByTestId(`add-component-button-${testName}`)
.click({ timeout: 30000 });
// Component added to canvas — verify the MCPTools node is present
// MCPTools node is present on canvas with the new server
await expect(page.getByTestId("dropdown_str_tool")).toBeVisible({
timeout: 30000,
});
// Verify server appears in Settings → MCP Servers and can be deleted
await page.getByTestId("user_menu_button").click({ timeout: 3000 });
await page.getByTestId("menu_settings_button").click({ timeout: 3000 });
await page.waitForSelector('[data-testid="sidebar-nav-MCP Servers"]', {
timeout: 30000,
});
await page.getByTestId("sidebar-nav-MCP Servers").click({ timeout: 3000 });
await page.waitForSelector('[data-testid="add-mcp-server-button-page"]', {
timeout: 10000,
});
await expect(page.getByText(testName)).toBeVisible({ timeout: 5000 });
// Delete the server from Settings
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 5000 });
await page.getByText("Delete", { exact: true }).first().click({ timeout: 3000 });
await page.waitForSelector(
'[data-testid="btn_delete_delete_confirmation_modal"]',
{ timeout: 3000 },
);
await page
.getByTestId("btn_delete_delete_confirmation_modal")
.click({ timeout: 3000 });
await expect(page.getByText(testName)).not.toBeVisible({ timeout: 10000 });
await page.goto("/");
},
);
test(
"STDIO MCP server fields should persist after saving and editing",
{ tag: ["@release", "@workspace", "@components", "@mcp", "@stable"] },
async ({ page }) => {
await awaitBootstrapTest(page);
await page.waitForSelector('[data-testid="blank-flow"]', {
timeout: 30000,
});
await page.getByTestId("blank-flow").click();
await page.getByTestId("sidebar-nav-mcp").click();
await page.waitForSelector(
'[data-testid="add-component-button-lf-starter_project"]',
{
timeout: 30000,
},
);
await page.getByTestId("add-component-button-lf-starter_project").click();
await adjustScreenView(page, { numberOfZoomOut: 3 });
await openAddMcpServerModal(page);
// Go to STDIO tab and fill all fields
await page.getByTestId("stdio-tab").click();
await page.waitForSelector('[data-testid="stdio-name-input"]', {
state: "visible",
timeout: 30000,
});
// Test data with random suffix
const randomSuffix = Math.floor(Math.random() * 90000) + 10000; // 5-digit random number
const testName = `test_stdio_server_${randomSuffix}`;
registeredServers.push(testName);
// `uvx` keeps the second allowlisted package runner covered as a COMMAND.
// `mcp-server-test` is deliberately a package that does not exist: this test
// asserts form persistence, and registration is accepted independently of
// whether the subprocess ever starts.
const testCommand = "uvx";
const testPackageArg = "mcp-server-test";
const testArg1 = "--verbose";
const testArg2 = "--port=8080";
const testArg3 = "--config=test.json";
const testEnvKey1 = "NODE_ENV";
const testEnvValue1 = "production";
const testEnvKey2 = "DEBUG_MODE";
const testEnvValue2 = "true";
// Fill basic fields
await page.getByTestId("stdio-name-input").fill(testName);
await page.getByTestId("stdio-command-input").fill(testCommand);
// The package that used to be glued onto the command is now args[0]
await page.getByTestId("stdio-args_0").fill(testPackageArg);
// Add first option by clicking plus button
await page.getByTestId("input-list-plus-btn_-0").click();
await page.getByTestId("stdio-args_1").fill(testArg1);
// Add second option
await page.getByTestId("input-list-plus-btn_-0").click();
await page.getByTestId("stdio-args_2").fill(testArg2);
// Add third option
await page.getByTestId("input-list-plus-btn_-0").click();
await page.getByTestId("stdio-args_3").fill(testArg3);
// Add first environment variable
await page.getByTestId("stdio-env-key-0").fill(testEnvKey1);
await page.getByTestId("stdio-env-value-0").fill(testEnvValue1);
// Add second environment variable
await page.getByTestId("stdio-env-plus-btn-0").click();
await page.getByTestId("stdio-env-key-1").fill(testEnvKey2);
await page.getByTestId("stdio-env-value-1").fill(testEnvValue2);
// Save the server
await page.getByTestId("add-mcp-server-button").click();
// Go to settings to edit the server
await page.getByTestId("user_menu_button").click({ timeout: 30000 });
await page.getByTestId("menu_settings_button").click({ timeout: 10000 });
await page.waitForSelector('[data-testid="sidebar-nav-MCP Servers"]', {
timeout: 30000,
});
await page.getByTestId("sidebar-nav-MCP Servers").click({ timeout: 3000 });
await page.waitForSelector('[data-testid="add-mcp-server-button-page"]', {
timeout: 3000,
});
// Find and edit the server
await expect(page.getByText(testName)).toBeVisible({
timeout: 3000,
});
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 3000 });
await page
.getByText("Edit", { exact: true })
.first()
.click({ timeout: 3000 });
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "visible",
timeout: 30000,
});
// Verify all fields persisted correctly
expect(await page.getByTestId("stdio-name-input").inputValue()).toBe(
testName,
);
expect(await page.getByTestId("stdio-command-input").inputValue()).toBe(
testCommand,
);
expect(await page.getByTestId("stdio-args_0").inputValue()).toBe(
testPackageArg,
);
expect(await page.getByTestId("stdio-args_1").inputValue()).toBe(testArg1);
expect(await page.getByTestId("stdio-args_2").inputValue()).toBe(testArg2);
expect(await page.getByTestId("stdio-args_3").inputValue()).toBe(testArg3);
expect(await page.getByTestId("stdio-env-key-0").last().inputValue()).toBe(
testEnvKey1,
);
expect(
await page.getByTestId("stdio-env-value-0").last().inputValue(),
).toBe(testEnvValue1);
expect(await page.getByTestId("stdio-env-key-1").last().inputValue()).toBe(
testEnvKey2,
);
expect(
await page.getByTestId("stdio-env-value-1").last().inputValue(),
).toBe(testEnvValue2);
// Clean up - cancel the edit modal
await page.keyboard.press("Escape");
// Delete the test server
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 3000 });
await page
.getByText("Delete", { exact: true })
.first()
.click({ timeout: 3000 });
await page.waitForSelector(
'[data-testid="btn_delete_delete_confirmation_modal"]',
{
timeout: 3000,
},
);
await page
.getByTestId("btn_delete_delete_confirmation_modal")
.click({ timeout: 3000 });
},
);
test(
"HTTP/SSE MCP server fields should persist after saving and editing",
{ tag: ["@release", "@workspace", "@components", "@mcp", "@stable"] },
async ({ page }) => {
await awaitBootstrapTest(page);
await page.waitForSelector('[data-testid="blank-flow"]', {
timeout: 30000,
});
await page.getByTestId("blank-flow").click();
await page.getByTestId("sidebar-nav-mcp").click();
await page.waitForSelector(
'[data-testid="add-component-button-lf-starter_project"]',
{
timeout: 30000,
},
);
await page.getByTestId("add-component-button-lf-starter_project").click();
await adjustScreenView(page, { numberOfZoomOut: 3 });
await openAddMcpServerModal(page);
// Go to HTTP tab and fill all fields
await page.getByTestId("http-tab").click();
await page.waitForSelector('[data-testid="http-name-input"]', {
state: "visible",
timeout: 30000,
});
// Test data with random suffix
const randomSuffix = Math.floor(Math.random() * 90000) + 10000; // 5-digit random number
const testName = `test_http_server_${randomSuffix}`;
registeredServers.push(testName);
const testUrl = "https://api.example.com/mcp";
const testHeaderKey1 = "Authorization";
const testHeaderValue1 = "Bearer token123";
const testHeaderKey2 = "Content-Type";
const testHeaderValue2 = "application/json";
const testEnvKey1 = "API_TIMEOUT";
const testEnvValue1 = "30000";
const testEnvKey2 = "RETRY_COUNT";
const testEnvValue2 = "3";
// Fill basic fields
await page.getByTestId("http-name-input").fill(testName);
await page.getByTestId("http-url-input").fill(testUrl);
// Add first header
await page.getByTestId("http-headers-key-0").fill(testHeaderKey1);
await page
.getByTestId("popover-anchor-http-headers-value-0")
.first()
.fill(testHeaderValue1);
// Add second header
await page.getByTestId("http-headers-plus-btn-0").click();
await page.getByTestId("http-headers-key-1").fill(testHeaderKey2);
// Use nth(1) to get the second value field
await page
.getByTestId("popover-anchor-http-headers-value-1")
.first()
.fill(testHeaderValue2);
// Add first environment variable
await page.getByTestId("http-env-key-0").fill(testEnvKey1);
await page.getByTestId("http-env-value-0").fill(testEnvValue1);
// Add second environment variable
await page.getByTestId("http-env-plus-btn-0").click();
await page.getByTestId("http-env-key-1").fill(testEnvKey2);
await page.getByTestId("http-env-value-1").fill(testEnvValue2);
// Save the server
await page.getByTestId("add-mcp-server-button").click();
// Wait for save to complete and modal to close
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "hidden",
timeout: 30000,
});
// Go to settings to edit the server
await page.getByTestId("user_menu_button").click({ timeout: 30000 });
await page.getByTestId("menu_settings_button").click({ timeout: 10000 });
await page.waitForSelector('[data-testid="sidebar-nav-MCP Servers"]', {
timeout: 30000,
});
await page.getByTestId("sidebar-nav-MCP Servers").click({ timeout: 10000 });
await page.waitForSelector('[data-testid="add-mcp-server-button-page"]', {
timeout: 30000,
});
// Find and edit the server
await expect(page.getByText(testName)).toBeVisible({
timeout: 10000,
});
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 10000 });
await page
.getByText("Edit", { exact: true })
.first()
.click({ timeout: 10000 });
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "visible",
timeout: 30000,
});
// Wait for form fields to be populated
await page.waitForSelector('[data-testid="http-name-input"]', {
state: "visible",
timeout: 10000,
});
await page.waitForSelector(
'[data-testid="popover-anchor-http-headers-value-0"]',
{
state: "visible",
timeout: 10000,
},
);
// Verify all fields persisted correctly
expect(await page.getByTestId("http-name-input").inputValue()).toBe(
testName,
);
expect(await page.getByTestId("http-url-input").inputValue()).toBe(testUrl);
expect(await page.getByTestId("http-headers-key-0").inputValue()).toBe(
testHeaderKey1,
);
// Header values use InputComponent with global variables
expect(
await page
.getByTestId("popover-anchor-http-headers-value-0")
.first()
.inputValue(),
).toBe(testHeaderValue1);
expect(await page.getByTestId("http-headers-key-1").inputValue()).toBe(
testHeaderKey2,
);
expect(
await page
.getByTestId("popover-anchor-http-headers-value-1")
.first()
.inputValue(),
).toBe(testHeaderValue2);
expect(await page.getByTestId("http-env-key-0").inputValue()).toBe(
testEnvKey1,
);
expect(await page.getByTestId("http-env-value-0").inputValue()).toBe(
testEnvValue1,
);
expect(await page.getByTestId("http-env-key-1").inputValue()).toBe(
testEnvKey2,
);
expect(await page.getByTestId("http-env-value-1").inputValue()).toBe(
testEnvValue2,
);
// Clean up - cancel the edit modal
await page.keyboard.press("Escape");
// Delete the test server
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 10000 });
await page
.getByText("Delete", { exact: true })
.first()
.click({ timeout: 10000 });
await page.waitForSelector(
'[data-testid="btn_delete_delete_confirmation_modal"]',
{
timeout: 10000,
},
);
await page
.getByTestId("btn_delete_delete_confirmation_modal")
.click({ timeout: 10000 });
},
);
test(
"mcp server tools should be refreshed when editing a server",
{ tag: ["@release", "@workspace", "@components", "@mcp", "@stable"] },
async ({ page }) => {
// Three `TOOL_LIST_TIMEOUT` waits (register A, edit to B, re-register A)
// plus the settings round-trips do not fit the suite's 5-minute per-test
// cap. Without this the test would die at the TEST timeout on a slow npm
// registry instead of at the wait that actually ran out — the unattributed
// timeout that costs a triage cycle to explain (#1011/#1019).
test.setTimeout(8 * 60 * 1000);
await page.waitForTimeout(5000);
await awaitBootstrapTest(page);
await page.waitForSelector('[data-testid="blank-flow"]', {
timeout: 30000,
});
// The flow under test has to be addressed by id from here on (#1340), and
// the id has to satisfy BOTH sources — neither alone is enough here:
//
// - `page.url()` alone is the documented trap. `awaitBootstrapTest` reaches
// the templates modal through "New Flow", so before the blank-flow
// navigation the URL still carries the bootstrap PLACEHOLDER — the flow
// Langflow deletes the moment the modal navigates elsewhere, and the one
// authoring-conventions Pattern A warns about (#681/#505).
// - the tracked `POST /flows` 201 ids alone do not say which flow the editor
// ended up on: this page creates the placeholder AND the blank flow, so
// picking one means trusting arrival order of two async body reads, and
// the wrong pick is precisely the id that gets deleted.
//
// So: poll until the editor's URL carries an id this page is known to have
// created and that is not the placeholder. A transient or client-only id
// cannot satisfy the membership test, and a blank-flow click that never
// navigates fails HERE, naming the cause, instead of surfacing later as an
// unattributed timeout. Measured on nightly 1.12.0.dev18: the click issues
// its own `POST /flows` 201 and the URL changes every time (5/5) — the
// placeholder is never reused — so this is about attribution, not a defect.
const placeholderId = new URL(page.url()).pathname.match(
/\/flow\/([0-9a-f-]{36})/,
)?.[1];
await page.getByTestId("blank-flow").click();
const editorFlowId = () =>
new URL(page.url()).pathname.match(/\/flow\/([0-9a-f-]{36})/)?.[1];
await expect
.poll(
() => {
const id = editorFlowId();
return !!id && id !== placeholderId && createdFlowIds.includes(id);
},
{
timeout: 30000,
message:
"the blank-flow click never landed the editor on a newly created " +
"flow: the URL still holds the bootstrap placeholder, or its id is " +
"not among this page's POST /api/v1/flows 201 responses",
},
)
.toBe(true);
const flowUnderTest = editorFlowId()!;
await page.getByTestId("sidebar-nav-mcp").click();
await page.waitForSelector(
'[data-testid="add-component-button-lf-starter_project"]',
{
timeout: 30000,
},
);
await page.getByTestId("add-component-button-lf-starter_project").click();
await adjustScreenView(page, { numberOfZoomOut: 3 });
// Postcondition gate kept from the pre-#1087 sequence: adjustScreenView already
// leaves the menu closed by reading the trigger's `data-state` (#1053), so this
// only ASSERTS that it did — failing here, naming the canvas controls, instead
// of ~60 lines down as "<html> intercepts pointer events" on the
// mcp-server-dropdown click (#576). The `keyboard.press("Escape")` that used to
// precede it is gone on purpose: it would mask that regression (#997).
await expect(page.getByTestId("zoom_out")).toBeHidden();
await openAddMcpServerModal(page);
await page.getByTestId("stdio-tab").click();
await page.waitForSelector('[data-testid="stdio-name-input"]', {
state: "visible",
timeout: 30000,
});
const randomSuffix = Math.floor(Math.random() * 90000) + 10000; // 5-digit random number
const testName = `test_server_${randomSuffix}`;
registeredServers.push(testName);
await page.getByTestId("stdio-name-input").fill(testName);
// Server A — sequential-thinking serves exactly one tool, so the tool list
// it produces is unambiguous when compared against server B's below.
await page.getByTestId("stdio-command-input").fill(NPX);
await page.getByTestId("stdio-args_0").fill(PKG_SEQUENTIAL);
await page.getByTestId("add-mcp-server-button").click();
// Wait for save to complete and modal to close
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "hidden",
timeout: 30000,
});
await page.waitForSelector(
'[data-testid="dropdown_str_tool"]:not([disabled])',
{
timeout: TOOL_LIST_TIMEOUT,
state: "visible",
},
);
await page.getByTestId("dropdown_str_tool").click();
await page.waitForSelector('[data-testid="sequentialthinking-0-option"]', {
state: "visible",
timeout: 10000,
});
const sequentialOptionCount = await page
.getByTestId("sequentialthinking-0-option")
.count();
expect(sequentialOptionCount).toBeGreaterThan(0);
await page.getByTestId("sequentialthinking-0-option").click();
// Fit view only — no zoom step here. The helper waits on
// `canvas_controls_dropdown` itself (30 s), which subsumes the explicit
// 10 s wait this sequence used to open with.
await adjustScreenView(page, { numberOfZoomOut: 0 });
// The selected tool's OWN inputs must render on the node. `sequentialthinking`
// exposes `thoughtNumber` (integer) and `thought` (string); the node lowercases
// integer names into `int_int_<name>` but keeps the case of string inputs.
await page.waitForSelector('[data-testid="int_int_thoughtnumber"]', {
state: "visible",
timeout: 30000,
});
const thoughtNumberOptionCount = await page
.getByTestId("int_int_thoughtnumber")
.count();
expect(thoughtNumberOptionCount).toBeGreaterThan(0);
const thoughtOptionCount = await page
.getByTestId("anchor-popover-anchor-input-thought")
.count();
expect(thoughtOptionCount).toBeGreaterThan(0);
await page.getByTestId("user_menu_button").click({ timeout: 10000 });
await page.getByTestId("menu_settings_button").click({ timeout: 10000 });
await page.waitForSelector('[data-testid="sidebar-nav-MCP Servers"]', {
timeout: 30000,
});
await page.getByTestId("sidebar-nav-MCP Servers").click({ timeout: 10000 });
await page.waitForSelector('[data-testid="add-mcp-server-button-page"]', {
timeout: 30000,
});
await expect(page.getByText(testName)).toBeVisible({
timeout: 10000,
});
await page
.getByTestId(`mcp-server-menu-button-${testName}`)
.click({ timeout: 10000 });
await page
.getByText("Edit", { exact: true })
.first()
.click({ timeout: 10000 });
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "visible",
timeout: 30000,
});
await expect(page.getByTestId("json-tab")).toBeDisabled({
timeout: 10000,
});
await expect(page.getByTestId("stdio-tab")).not.toBeDisabled({
timeout: 10000,
});
await expect(page.getByTestId("http-tab")).toBeDisabled({
timeout: 10000,
});
// Wait for command input to be populated
await page.waitForSelector('[data-testid="stdio-command-input"]', {
state: "visible",
timeout: 10000,
});
expect(await page.getByTestId("stdio-command-input").inputValue()).toBe(NPX);
expect(await page.getByTestId("stdio-args_0").inputValue()).toBe(
PKG_SEQUENTIAL,
);
// Switch to server B. Both runners are `npx` now that the command field
// holds a bare executable, so the package in args[0] is what changes — which
// also proves `args` round-trips through an edit, not only through a create.
await page.getByTestId("stdio-args_0").fill(PKG_EVERYTHING);
await page.getByTestId("add-mcp-server-button").click();
// Wait for save to complete and modal to close
await page.waitForSelector('[data-testid="add-mcp-server-button"]', {
state: "hidden",
timeout: 30000,
});
await awaitBootstrapTest(page, { skipModal: true });
// By id, never a name-filtered `list-card` + `.first()` (#1340). Langflow