Skip to content

Commit 1c62169

Browse files
test(server): use typed initialize request and schema parsing; drop re-initialization test
1 parent 47a1724 commit 1c62169

1 file changed

Lines changed: 6 additions & 22 deletions

File tree

packages/server/test/server/server.test.ts

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import type { JSONRPCMessage } from '@modelcontextprotocol/core';
1+
import type { JSONRPCMessage, JSONRPCRequest } from '@modelcontextprotocol/core';
22
import {
3+
InitializeResultSchema,
34
InMemoryTransport,
45
isJSONRPCResultResponse,
56
LATEST_PROTOCOL_VERSION,
@@ -28,7 +29,7 @@ async function initializeServer(server: Server, requestedVersion: string): Promi
2829
});
2930
await clientTransport.start();
3031

31-
await clientTransport.send({
32+
const initializeRequest: JSONRPCRequest = {
3233
jsonrpc: '2.0',
3334
id: 1,
3435
method: 'initialize',
@@ -37,13 +38,14 @@ async function initializeServer(server: Server, requestedVersion: string): Promi
3738
capabilities: {},
3839
clientInfo: { name: 'test-client', version: '1.0.0' }
3940
}
40-
} as JSONRPCMessage);
41+
};
42+
await clientTransport.send(initializeRequest);
4143

4244
const response = await responsePromise;
4345
if (!isJSONRPCResultResponse(response)) {
4446
throw new Error(`Expected a result response to initialize, got: ${JSON.stringify(response)}`);
4547
}
46-
return (response.result as { protocolVersion: string }).protocolVersion;
48+
return InitializeResultSchema.parse(response.result).protocolVersion;
4749
}
4850

4951
describe('Server', () => {
@@ -127,23 +129,5 @@ describe('Server', () => {
127129

128130
await server.close();
129131
});
130-
131-
it('is replaced when a new connection re-initializes with a different version', async () => {
132-
const server = new Server({ name: 'test', version: '1.0.0' }, { capabilities: {} });
133-
134-
await initializeServer(server, LATEST_PROTOCOL_VERSION);
135-
expect(server.getNegotiatedProtocolVersion()).toBe(LATEST_PROTOCOL_VERSION);
136-
await server.close();
137-
138-
// Like getClientCapabilities()/getClientVersion(), the value reflects the most recent
139-
// initialize handshake and is not cleared when the transport closes.
140-
expect(server.getNegotiatedProtocolVersion()).toBe(LATEST_PROTOCOL_VERSION);
141-
142-
// A new connection's initialize overwrites it.
143-
await initializeServer(server, OLDER_SUPPORTED_VERSION);
144-
expect(server.getNegotiatedProtocolVersion()).toBe(OLDER_SUPPORTED_VERSION);
145-
146-
await server.close();
147-
});
148132
});
149133
});

0 commit comments

Comments
 (0)