Skip to content

Commit 32ef72b

Browse files
test: 189 LegacyTestClient migrations + InMemory acceptance scenarios
Migrate existing connection-model tests to LegacyTestClient (client.test, server.test, mcp.test, elicitation.test, stateManagementStreamableHttp, taskResumability) — they exercise server-to-client RPCs / oninitialized which require the legacy initialize path. statelessAcceptance.test.ts: add 'Client over InMemory' describe block (auto-probe, legacy negotiate, subscribe demux, MRTR auto-resume). NEW zeroChangeConsumer.test.ts: InMemory describe.each over Server/McpServer ctors + MRTR hardening (accumulate, max-rounds, requestSampling).
1 parent 03ab8f3 commit 32ef72b

6 files changed

Lines changed: 391 additions & 183 deletions

File tree

test/integration/test/client/client.test.ts

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Client, getSupportedElicitationModes } from '@modelcontextprotocol/client';
1+
import { getSupportedElicitationModes } from '@modelcontextprotocol/client';
22
import type { Prompt, Resource, Tool, Transport } from '@modelcontextprotocol/core';
33
import {
44
InMemoryTransport,
@@ -10,6 +10,8 @@ import {
1010
} from '@modelcontextprotocol/core';
1111
import { McpServer, Server } from '@modelcontextprotocol/server';
1212

13+
import { LegacyTestClient } from '../__fixtures__/testClient.js';
14+
1315
/***
1416
* Test: Initialize with Matching Protocol Version
1517
*/
@@ -37,7 +39,7 @@ test('should initialize with matching protocol version', async () => {
3739
})
3840
};
3941

40-
const client = new Client(
42+
const client = new LegacyTestClient(
4143
{
4244
name: 'test client',
4345
version: '1.0'
@@ -95,7 +97,7 @@ test('should initialize with supported older protocol version', async () => {
9597
})
9698
};
9799

98-
const client = new Client(
100+
const client = new LegacyTestClient(
99101
{
100102
name: 'test client',
101103
version: '1.0'
@@ -144,7 +146,7 @@ test('should restore negotiated protocol version on transport when reconnecting
144146
})
145147
};
146148

147-
const client = new Client({ name: 'test client', version: '1.0' });
149+
const client = new LegacyTestClient({ name: 'test client', version: '1.0' });
148150
await client.connect(initialTransport);
149151

150152
// Initial handshake should have set the protocol version on the transport
@@ -197,7 +199,7 @@ test('should reject unsupported protocol version', async () => {
197199
})
198200
};
199201

200-
const client = new Client(
202+
const client = new LegacyTestClient(
201203
{
202204
name: 'test client',
203205
version: '1.0'
@@ -254,7 +256,7 @@ test('should connect new client to old, supported server version', async () => {
254256

255257
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
256258

257-
const client = new Client(
259+
const client = new LegacyTestClient(
258260
{
259261
name: 'new client',
260262
version: '1.0'
@@ -314,7 +316,7 @@ test('should negotiate version when client is old, and newer server supports its
314316

315317
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
316318

317-
const client = new Client(
319+
const client = new LegacyTestClient(
318320
{
319321
name: 'old client',
320322
version: '1.0'
@@ -375,7 +377,7 @@ test("should throw when client is old, and server doesn't support its version",
375377

376378
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
377379

378-
const client = new Client(
380+
const client = new LegacyTestClient(
379381
{
380382
name: 'old client',
381383
version: '1.0'
@@ -433,7 +435,7 @@ test('should respect server capabilities', async () => {
433435

434436
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
435437

436-
const client = new Client(
438+
const client = new LegacyTestClient(
437439
{
438440
name: 'test client',
439441
version: '1.0'
@@ -507,7 +509,7 @@ test('should return empty lists for missing capabilities by default', async () =
507509
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
508510

509511
// Client with default settings (enforceStrictCapabilities not set)
510-
const client = new Client(
512+
const client = new LegacyTestClient(
511513
{
512514
name: 'test client',
513515
version: '1.0'
@@ -556,7 +558,7 @@ test('should respect client notification capabilities', async () => {
556558
}
557559
);
558560

559-
const client = new Client(
561+
const client = new LegacyTestClient(
560562
{
561563
name: 'test client',
562564
version: '1.0'
@@ -578,7 +580,7 @@ test('should respect client notification capabilities', async () => {
578580
await expect(client.sendRootsListChanged()).resolves.not.toThrow();
579581

580582
// Create a new client without the roots.listChanged capability
581-
const clientWithoutCapability = new Client(
583+
const clientWithoutCapability = new LegacyTestClient(
582584
{
583585
name: 'test client without capability',
584586
version: '1.0'
@@ -614,7 +616,7 @@ test('should respect server notification capabilities', async () => {
614616
}
615617
);
616618

617-
const client = new Client(
619+
const client = new LegacyTestClient(
618620
{
619621
name: 'test client',
620622
version: '1.0'
@@ -640,7 +642,7 @@ test('should respect server notification capabilities', async () => {
640642
* Test: Only Allow setRequestHandler for Declared Capabilities
641643
*/
642644
test('should only allow setRequestHandler for declared capabilities', () => {
643-
const client = new Client(
645+
const client = new LegacyTestClient(
644646
{
645647
name: 'test client',
646648
version: '1.0'
@@ -671,7 +673,7 @@ test('should only allow setRequestHandler for declared capabilities', () => {
671673
});
672674

673675
test('should allow setRequestHandler for declared elicitation capability', () => {
674-
const client = new Client(
676+
const client = new LegacyTestClient(
675677
{
676678
name: 'test-client',
677679
version: '1.0.0'
@@ -723,7 +725,7 @@ test('should accept form-mode elicitation request when client advertises empty e
723725
}
724726
);
725727

726-
const client = new Client(
728+
const client = new LegacyTestClient(
727729
{
728730
name: 'test client',
729731
version: '1.0'
@@ -784,7 +786,7 @@ test('should accept form-mode elicitation request when client advertises empty e
784786
});
785787

786788
test('should reject form-mode elicitation when client only supports URL mode', async () => {
787-
const client = new Client(
789+
const client = new LegacyTestClient(
788790
{
789791
name: 'test-client',
790792
version: '1.0.0'
@@ -881,7 +883,7 @@ test('should reject missing-mode elicitation when client only supports URL mode'
881883
}
882884
);
883885

884-
const client = new Client(
886+
const client = new LegacyTestClient(
885887
{
886888
name: 'test client',
887889
version: '1.0'
@@ -926,7 +928,7 @@ test('should reject missing-mode elicitation when client only supports URL mode'
926928
});
927929

928930
test('should reject URL-mode elicitation when client only supports form mode', async () => {
929-
const client = new Client(
931+
const client = new LegacyTestClient(
930932
{
931933
name: 'test-client',
932934
version: '1.0.0'
@@ -1022,7 +1024,7 @@ test('should apply defaults for form-mode elicitation when applyDefaults is enab
10221024
}
10231025
);
10241026

1025-
const client = new Client(
1027+
const client = new LegacyTestClient(
10261028
{
10271029
name: 'test client',
10281030
version: '1.0'
@@ -1098,7 +1100,7 @@ test('should handle client cancelling a request', async () => {
10981100

10991101
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
11001102

1101-
const client = new Client(
1103+
const client = new LegacyTestClient(
11021104
{
11031105
name: 'test client',
11041106
version: '1.0'
@@ -1154,7 +1156,7 @@ test('should handle request timeout', async () => {
11541156

11551157
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
11561158

1157-
const client = new Client(
1159+
const client = new LegacyTestClient(
11581160
{
11591161
name: 'test client',
11601162
version: '1.0'
@@ -1194,7 +1196,7 @@ test('should handle tool list changed notification with auto refresh', async ()
11941196
);
11951197

11961198
// Configure listChanged handler in constructor
1197-
const client = new Client(
1199+
const client = new LegacyTestClient(
11981200
{
11991201
name: 'test-client',
12001202
version: '1.0.0'
@@ -1252,7 +1254,7 @@ test('should handle tool list changed notification with manual refresh', async (
12521254
server.registerTool('initial-tool', {}, async () => ({ content: [] }));
12531255

12541256
// Configure listChanged handler with manual refresh (autoRefresh: false)
1255-
const client = new Client(
1257+
const client = new LegacyTestClient(
12561258
{
12571259
name: 'test-client',
12581260
version: '1.0.0'
@@ -1318,7 +1320,7 @@ test('should handle prompt list changed notification with auto refresh', async (
13181320
);
13191321

13201322
// Configure listChanged handler in constructor
1321-
const client = new Client(
1323+
const client = new LegacyTestClient(
13221324
{
13231325
name: 'test-client',
13241326
version: '1.0.0'
@@ -1373,7 +1375,7 @@ test('should handle resource list changed notification with auto refresh', async
13731375
}));
13741376

13751377
// Configure listChanged handler in constructor
1376-
const client = new Client(
1378+
const client = new LegacyTestClient(
13771379
{
13781380
name: 'test-client',
13791381
version: '1.0.0'
@@ -1442,7 +1444,7 @@ test('should handle multiple list changed handlers configured together', async (
14421444
);
14431445

14441446
// Configure multiple listChanged handlers in constructor
1445-
const client = new Client(
1447+
const client = new LegacyTestClient(
14461448
{
14471449
name: 'test-client',
14481450
version: '1.0.0'
@@ -1518,7 +1520,7 @@ test('should not activate listChanged handler when server does not advertise cap
15181520
}));
15191521

15201522
// Configure listChanged handler that should NOT be activated
1521-
const client = new Client(
1523+
const client = new LegacyTestClient(
15221524
{ name: 'test-client', version: '1.0.0' },
15231525
{
15241526
listChanged: {
@@ -1567,7 +1569,7 @@ test('should activate listChanged handler when server advertises capability', as
15671569
}));
15681570

15691571
// Configure listChanged handler that SHOULD be activated
1570-
const client = new Client(
1572+
const client = new LegacyTestClient(
15711573
{ name: 'test-client', version: '1.0.0' },
15721574
{
15731575
listChanged: {
@@ -1616,7 +1618,7 @@ test('should not activate any handlers when server has no listChanged capabiliti
16161618
}));
16171619

16181620
// Configure listChanged handlers for all three types
1619-
const client = new Client(
1621+
const client = new LegacyTestClient(
16201622
{ name: 'test-client', version: '1.0.0' },
16211623
{
16221624
listChanged: {
@@ -1682,7 +1684,7 @@ test('should handle partial listChanged capability support', async () => {
16821684
prompts: [{ name: 'prompt-1' }]
16831685
}));
16841686

1685-
const client = new Client(
1687+
const client = new LegacyTestClient(
16861688
{ name: 'test-client', version: '1.0.0' },
16871689
{
16881690
listChanged: {
@@ -1775,7 +1777,7 @@ describe('outputSchema validation', () => {
17751777
throw new Error('Unknown tool');
17761778
});
17771779

1778-
const client = new Client(
1780+
const client = new LegacyTestClient(
17791781
{
17801782
name: 'test-client',
17811783
version: '1.0.0'
@@ -1868,7 +1870,7 @@ describe('outputSchema validation', () => {
18681870
throw new Error('Unknown tool');
18691871
});
18701872

1871-
const client = new Client(
1873+
const client = new LegacyTestClient(
18721874
{
18731875
name: 'test-client',
18741876
version: '1.0.0'
@@ -1958,7 +1960,7 @@ describe('outputSchema validation', () => {
19581960
throw new Error('Unknown tool');
19591961
});
19601962

1961-
const client = new Client(
1963+
const client = new LegacyTestClient(
19621964
{
19631965
name: 'test-client',
19641966
version: '1.0.0'
@@ -2044,7 +2046,7 @@ describe('outputSchema validation', () => {
20442046
throw new Error('Unknown tool');
20452047
});
20462048

2047-
const client = new Client(
2049+
const client = new LegacyTestClient(
20482050
{
20492051
name: 'test-client',
20502052
version: '1.0.0'
@@ -2157,7 +2159,7 @@ describe('outputSchema validation', () => {
21572159
throw new Error('Unknown tool');
21582160
});
21592161

2160-
const client = new Client(
2162+
const client = new LegacyTestClient(
21612163
{
21622164
name: 'test-client',
21632165
version: '1.0.0'
@@ -2255,7 +2257,7 @@ describe('outputSchema validation', () => {
22552257
throw new Error('Unknown tool');
22562258
});
22572259

2258-
const client = new Client(
2260+
const client = new LegacyTestClient(
22592261
{
22602262
name: 'test-client',
22612263
version: '1.0.0'
@@ -2335,7 +2337,7 @@ describe('Client sampling validation with tools', () => {
23352337
test('should validate array content with tool_use when request includes tools', async () => {
23362338
const server = new Server({ name: 'test server', version: '1.0' }, { capabilities: {} });
23372339

2338-
const client = new Client({ name: 'test client', version: '1.0' }, { capabilities: { sampling: { tools: {} } } });
2340+
const client = new LegacyTestClient({ name: 'test client', version: '1.0' }, { capabilities: { sampling: { tools: {} } } });
23392341

23402342
// Handler returns array content with tool_use - should validate with CreateMessageResultWithToolsSchema
23412343
client.setRequestHandler('sampling/createMessage', async () => ({
@@ -2362,7 +2364,7 @@ describe('Client sampling validation with tools', () => {
23622364
test('should validate single content when request includes tools', async () => {
23632365
const server = new Server({ name: 'test server', version: '1.0' }, { capabilities: {} });
23642366

2365-
const client = new Client({ name: 'test client', version: '1.0' }, { capabilities: { sampling: { tools: {} } } });
2367+
const client = new LegacyTestClient({ name: 'test client', version: '1.0' }, { capabilities: { sampling: { tools: {} } } });
23662368

23672369
// Handler returns single content (text) - should still validate with CreateMessageResultWithToolsSchema
23682370
client.setRequestHandler('sampling/createMessage', async () => ({
@@ -2386,7 +2388,7 @@ describe('Client sampling validation with tools', () => {
23862388
test('should validate single content when request has no tools', async () => {
23872389
const server = new Server({ name: 'test server', version: '1.0' }, { capabilities: {} });
23882390

2389-
const client = new Client({ name: 'test client', version: '1.0' }, { capabilities: { sampling: {} } });
2391+
const client = new LegacyTestClient({ name: 'test client', version: '1.0' }, { capabilities: { sampling: {} } });
23902392

23912393
// Handler returns single content - should validate with CreateMessageResultSchema
23922394
client.setRequestHandler('sampling/createMessage', async () => ({
@@ -2409,7 +2411,7 @@ describe('Client sampling validation with tools', () => {
24092411
test('should reject array content when request has no tools', async () => {
24102412
const server = new Server({ name: 'test server', version: '1.0' }, { capabilities: {} });
24112413

2412-
const client = new Client({ name: 'test client', version: '1.0' }, { capabilities: { sampling: {} } });
2414+
const client = new LegacyTestClient({ name: 'test client', version: '1.0' }, { capabilities: { sampling: {} } });
24132415

24142416
// Handler returns array content - should fail validation with CreateMessageResultSchema
24152417
client.setRequestHandler('sampling/createMessage', async () => ({
@@ -2432,7 +2434,7 @@ describe('Client sampling validation with tools', () => {
24322434
test('should validate array content when request includes toolChoice', async () => {
24332435
const server = new Server({ name: 'test server', version: '1.0' }, { capabilities: {} });
24342436

2435-
const client = new Client({ name: 'test client', version: '1.0' }, { capabilities: { sampling: { tools: {} } } });
2437+
const client = new LegacyTestClient({ name: 'test client', version: '1.0' }, { capabilities: { sampling: { tools: {} } } });
24362438

24372439
// Handler returns array content with tool_use
24382440
client.setRequestHandler('sampling/createMessage', async () => ({

0 commit comments

Comments
 (0)