Skip to content

Commit dfae0de

Browse files
test: adapt tests to .legacy getter for session-dependent methods
Integration tests that exercise the pre-2026 session-dependent surface (server.createMessage / elicitInput / listRoots / sendLoggingMessage / ping / getClientCapabilities / getClientVersion / oninitialized / createElicitationCompletionNotifier / notification / request / setNotificationHandler; client.sendRootsListChanged / ping / subscribeResource / unsubscribeResource / request / notification) now go through `.legacy`. LegacyTestClient unchanged: it extends NEW Client and pins versions, so `connect()` skips the discover probe exactly as before. clientSend statelessClient() helper updated to set `_transport` / negotiated state on `c.legacy` (private state moved there).
1 parent a6e1529 commit dfae0de

12 files changed

Lines changed: 237 additions & 228 deletions

packages/client/test/client/clientSend.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ function mockTransport(handler: (req: JSONRPCRequest) => AsyncIterable<JSONRPCMe
1717
/** Forces the client into stateless mode without going through connect(). */
1818
function statelessClient(transport: Transport): Client {
1919
const c = new Client({ name: 'c', version: '1' }, { capabilities: { elicitation: {} } });
20-
Object.assign(c as object, {
21-
_isStateless: true,
20+
Object.assign(c as object, { _isStateless: true });
21+
Object.assign(c.legacy as object, {
2222
_negotiatedProtocolVersion: DRAFT_PROTOCOL_VERSION,
2323
_serverCapabilities: { tools: {}, prompts: {} },
2424
_transport: transport

test/conformance/src/everythingServerSetup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function createMcpServer(opts: SetupOptions): McpServer {
9696
message: string,
9797
_data?: unknown
9898
) {
99-
mcpServer.server
99+
mcpServer.server.legacy
100100
.notification({ method: 'notifications/message', params: { level, logger: 'conformance-test-server', data: _data || message } })
101101
.catch(() => {
102102
// Ignore error if no client is connected.

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ test('should respect client notification capabilities', async () => {
577577
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
578578

579579
// This should work because the client has the roots.listChanged capability
580-
await expect(client.sendRootsListChanged()).resolves.not.toThrow();
580+
await expect(client.legacy.sendRootsListChanged()).resolves.not.toThrow();
581581

582582
// Create a new client without the roots.listChanged capability
583583
const clientWithoutCapability = new LegacyTestClient(
@@ -594,7 +594,7 @@ test('should respect client notification capabilities', async () => {
594594
await clientWithoutCapability.connect(clientTransport);
595595

596596
// This should throw because the client doesn't have the roots.listChanged capability
597-
await expect(clientWithoutCapability.sendRootsListChanged()).rejects.toThrow(/^Client does not support/);
597+
await expect(clientWithoutCapability.legacy.sendRootsListChanged()).rejects.toThrow(/^Client does not support/);
598598
});
599599

600600
/***
@@ -631,7 +631,7 @@ test('should respect server notification capabilities', async () => {
631631
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
632632

633633
// These should work because the server has the corresponding capabilities
634-
await expect(server.sendLoggingMessage({ level: 'info', data: 'Test' })).resolves.not.toThrow();
634+
await expect(server.legacy.sendLoggingMessage({ level: 'info', data: 'Test' })).resolves.not.toThrow();
635635
await expect(server.sendResourceListChanged()).resolves.not.toThrow();
636636

637637
// This should throw because the server doesn't have the tools capability
@@ -756,7 +756,7 @@ test('should accept form-mode elicitation request when client advertises empty e
756756
// Server should be able to send form-mode elicitation request
757757
// This works because getSupportedElicitationModes defaults to form mode
758758
// when neither form nor url are explicitly declared
759-
const result = await server.elicitInput({
759+
const result = await server.legacy.elicitInput({
760760
mode: 'form',
761761
message: 'Please provide your username',
762762
requestedSchema: {
@@ -906,7 +906,7 @@ test('should reject missing-mode elicitation when client only supports URL mode'
906906
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
907907

908908
await expect(
909-
server.request({
909+
server.legacy.request({
910910
method: 'elicitation/create',
911911
params: {
912912
message: 'Please provide data',
@@ -1052,7 +1052,7 @@ test('should apply defaults for form-mode elicitation when applyDefaults is enab
10521052

10531053
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
10541054

1055-
const result = await server.elicitInput({
1055+
const result = await server.legacy.elicitInput({
10561056
mode: 'form',
10571057
message: 'Please confirm your preferences',
10581058
requestedSchema: {
@@ -1542,7 +1542,7 @@ test('should not activate listChanged handler when server does not advertise cap
15421542
expect(client.getServerCapabilities()?.tools?.listChanged).toBeFalsy();
15431543

15441544
// Send a tool list changed notification manually
1545-
await server.notification({ method: 'notifications/tools/list_changed' });
1545+
await server.legacy.notification({ method: 'notifications/tools/list_changed' });
15461546
await new Promise(resolve => setTimeout(resolve, 100));
15471547

15481548
// Handler should NOT have been activated because server didn't advertise listChanged
@@ -1591,7 +1591,7 @@ test('should activate listChanged handler when server advertises capability', as
15911591
expect(client.getServerCapabilities()?.tools?.listChanged).toBe(true);
15921592

15931593
// Send a tool list changed notification
1594-
await server.notification({ method: 'notifications/tools/list_changed' });
1594+
await server.legacy.notification({ method: 'notifications/tools/list_changed' });
15951595
await new Promise(resolve => setTimeout(resolve, 100));
15961596

15971597
// Handler SHOULD have been called
@@ -1649,9 +1649,9 @@ test('should not activate any handlers when server has no listChanged capabiliti
16491649
expect(caps?.resources?.listChanged).toBeFalsy();
16501650

16511651
// Send notifications for all three types
1652-
await server.notification({ method: 'notifications/tools/list_changed' });
1653-
await server.notification({ method: 'notifications/prompts/list_changed' });
1654-
await server.notification({ method: 'notifications/resources/list_changed' });
1652+
await server.legacy.notification({ method: 'notifications/tools/list_changed' });
1653+
await server.legacy.notification({ method: 'notifications/prompts/list_changed' });
1654+
await server.legacy.notification({ method: 'notifications/resources/list_changed' });
16551655
await new Promise(resolve => setTimeout(resolve, 100));
16561656

16571657
// No handlers should have been activated
@@ -1709,8 +1709,8 @@ test('should handle partial listChanged capability support', async () => {
17091709
expect(client.getServerCapabilities()?.prompts?.listChanged).toBeFalsy();
17101710

17111711
// Send notifications for both
1712-
await server.notification({ method: 'notifications/tools/list_changed' });
1713-
await server.notification({ method: 'notifications/prompts/list_changed' });
1712+
await server.legacy.notification({ method: 'notifications/tools/list_changed' });
1713+
await server.legacy.notification({ method: 'notifications/prompts/list_changed' });
17141714
await new Promise(resolve => setTimeout(resolve, 100));
17151715

17161716
// Tools handler should have been called
@@ -2350,7 +2350,7 @@ describe('Client sampling validation with tools', () => {
23502350
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
23512351
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
23522352

2353-
const result = await server.createMessage({
2353+
const result = await server.legacy.createMessage({
23542354
messages: [{ role: 'user', content: { type: 'text', text: 'hello' } }],
23552355
maxTokens: 100,
23562356
tools: [{ name: 'test_tool', inputSchema: { type: 'object' } }]
@@ -2376,7 +2376,7 @@ describe('Client sampling validation with tools', () => {
23762376
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
23772377
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
23782378

2379-
const result = await server.createMessage({
2379+
const result = await server.legacy.createMessage({
23802380
messages: [{ role: 'user', content: { type: 'text', text: 'hello' } }],
23812381
maxTokens: 100,
23822382
tools: [{ name: 'test_tool', inputSchema: { type: 'object' } }]
@@ -2400,7 +2400,7 @@ describe('Client sampling validation with tools', () => {
24002400
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
24012401
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
24022402

2403-
const result = await server.createMessage({
2403+
const result = await server.legacy.createMessage({
24042404
messages: [{ role: 'user', content: { type: 'text', text: 'hello' } }],
24052405
maxTokens: 100
24062406
});
@@ -2424,7 +2424,7 @@ describe('Client sampling validation with tools', () => {
24242424
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
24252425

24262426
await expect(
2427-
server.createMessage({
2427+
server.legacy.createMessage({
24282428
messages: [{ role: 'user', content: { type: 'text', text: 'hello' } }],
24292429
maxTokens: 100
24302430
})
@@ -2447,7 +2447,7 @@ describe('Client sampling validation with tools', () => {
24472447
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
24482448
await Promise.all([client.connect(clientTransport), server.connect(serverTransport)]);
24492449

2450-
const result = await server.createMessage({
2450+
const result = await server.legacy.createMessage({
24512451
messages: [{ role: 'user', content: { type: 'text', text: 'hello' } }],
24522452
maxTokens: 100,
24532453
tools: [{ name: 'test_tool', inputSchema: { type: 'object' } }],

test/integration/test/issues/test1277.zod.v4.description.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('Issue #1277: Zod v4', () => {
4747

4848
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
4949

50-
const result = await client.request({
50+
const result = await client.legacy.request({
5151
method: 'prompts/list'
5252
});
5353

test/integration/test/issues/test400.optional-tool-params.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('Issue #400: Zod v4', () => {
4545
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
4646

4747
// Call tool without arguments (arguments is undefined)
48-
const result = await client.request({
48+
const result = await client.legacy.request({
4949
method: 'tools/call',
5050
params: {
5151
name: 'optional-params-tool'

0 commit comments

Comments
 (0)