No automatic completion support unless needed - Revisited yet again (#1237)

This commit is contained in:
Cliff Hall 2025-12-04 23:12:16 -05:00 • committed by GitHub
commit a57303c335
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2669,6 +2669,41 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
).rejects.toThrow(/Resource test:\/\/nonexistent not found/);
});
/***
* Test: Registering a resource template without a complete callback should not update server capabilities to advertise support for completion
*/
test('should not advertise support for completion when a resource template without a complete callback is defined', async () => {
const mcpServer = new McpServer({
name: 'test server',
version: '1.0'
});
const client = new Client({
name: 'test client',
version: '1.0'
});
mcpServer.resource(
'test',
new ResourceTemplate('test://resource/{category}', {
list: undefined
}),
async () => ({
contents: [
{
uri: 'test://resource/test',
text: 'Test content'
}
]
})
);
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
expect(client.getServerCapabilities()).not.toHaveProperty('completions');
});
/***
* Test: Registering a resource template with a complete callback should update server capabilities to advertise support for completion
*/
@ -3548,6 +3583,46 @@ describe.each(zodTestMatrix)('$zodVersionLabel', (entry: ZodMatrixEntry) => {
).rejects.toThrow(/Prompt nonexistent-prompt not found/);
});
/***
* Test: Registering a prompt without a completable argument should not update server capabilities to advertise support for completion
*/
test('should not advertise support for completion when a prompt without a completable argument is defined', async () => {
const mcpServer = new McpServer({
name: 'test server',
version: '1.0'
});
const client = new Client({
name: 'test client',
version: '1.0'
});
mcpServer.prompt(
'test-prompt',
{
name: z.string()
},
async ({ name }) => ({
messages: [
{
role: 'assistant',
content: {
type: 'text',
text: `Hello ${name}`
}
}
]
})
);
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await Promise.all([client.connect(clientTransport), mcpServer.server.connect(serverTransport)]);
const capabilities = client.getServerCapabilities() || {};
const keys = Object.keys(capabilities);
expect(keys).not.toContain('completions');
});
/***
* Test: Registering a prompt with a completable argument should update server capabilities to advertise support for completion
*/