Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/fix-inline-list-changed-notifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modelcontextprotocol/server': patch
---

Allow `sendToolListChanged`, `sendResourceListChanged`, and `sendPromptListChanged` to forward notification options such as `relatedRequestId`. This lets streamable HTTP servers deliver those notifications inline on the active POST SSE response instead of silently dropping them
when no standalone GET SSE channel is open.
13 changes: 7 additions & 6 deletions packages/server/src/server/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
ListResourcesResult,
ListToolsResult,
LoggingMessageNotification,
NotificationOptions,
Prompt,
PromptReference,
ReadResourceResult,
Expand Down Expand Up @@ -973,27 +974,27 @@ export class McpServer {
/**
* Sends a resource list changed event to the client, if connected.
*/
sendResourceListChanged() {
sendResourceListChanged(options?: NotificationOptions) {
if (this.isConnected()) {
this.server.sendResourceListChanged();
this.server.sendResourceListChanged(options);
}
}

/**
* Sends a tool list changed event to the client, if connected.
*/
sendToolListChanged() {
sendToolListChanged(options?: NotificationOptions) {
if (this.isConnected()) {
this.server.sendToolListChanged();
this.server.sendToolListChanged(options);
}
}

/**
* Sends a prompt list changed event to the client, if connected.
*/
sendPromptListChanged() {
sendPromptListChanged(options?: NotificationOptions) {
if (this.isConnected()) {
this.server.sendPromptListChanged();
this.server.sendPromptListChanged(options);
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions packages/server/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,20 @@ export class Server extends Protocol<ServerContext> {
});
}

async sendResourceListChanged() {
return this.notification({
method: 'notifications/resources/list_changed'
});
async sendResourceListChanged(options?: NotificationOptions) {
return this.notification(
{
method: 'notifications/resources/list_changed'
},
options
);
}

async sendToolListChanged() {
return this.notification({ method: 'notifications/tools/list_changed' });
async sendToolListChanged(options?: NotificationOptions) {
return this.notification({ method: 'notifications/tools/list_changed' }, options);
}

async sendPromptListChanged() {
return this.notification({ method: 'notifications/prompts/list_changed' });
async sendPromptListChanged(options?: NotificationOptions) {
return this.notification({ method: 'notifications/prompts/list_changed' }, options);
}
}
65 changes: 65 additions & 0 deletions packages/server/test/server/streamableHttp.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ function parseSSEData(text: string): unknown {
return JSON.parse(dataLine.slice(5).trim());
}

function parseSSEEvents(text: string): unknown[] {
return text
.split('\n\n')
.map(chunk => chunk.trim())
.filter(chunk => chunk.includes('data:'))
.map(parseSSEData);
}

function expectErrorResponse(data: unknown, expectedCode: number, expectedMessagePattern: RegExp): void {
expect(data).toMatchObject({
jsonrpc: '2.0',
Expand Down Expand Up @@ -271,6 +279,63 @@ describe('Zod v4', () => {
});
});

it('should inline tool list change notifications on the active POST SSE stream', async () => {
sessionId = await initializeServer();

mcpServer.registerTool(
'unlock-tools',
{
description: 'Unlocks additional tools',
inputSchema: z.object({})
},
async (_args, ctx): Promise<CallToolResult> => {
mcpServer.registerTool(
'secret-tool',
{
description: 'A newly unlocked tool',
inputSchema: z.object({})
},
async (): Promise<CallToolResult> => ({
content: [{ type: 'text', text: 'Unlocked tool' }]
})
);

await mcpServer.sendToolListChanged({ relatedRequestId: ctx.mcpReq.id });

return { content: [{ type: 'text', text: 'Unlocked tools' }] };
}
);

const toolCallMessage: JSONRPCMessage = {
jsonrpc: '2.0',
method: 'tools/call',
params: {
name: 'unlock-tools',
arguments: {}
},
id: 'call-1'
};

const request = createRequest('POST', toolCallMessage, { sessionId });
const response = await transport.handleRequest(request);

expect(response.status).toBe(200);

const events = parseSSEEvents(await response.text());

expect(events).toContainEqual({
jsonrpc: '2.0',
method: 'notifications/tools/list_changed'
});
expect(events).toContainEqual({
jsonrpc: '2.0',
result: {
content: [{ type: 'text', text: 'Unlocked tools' }]
},
id: 'call-1'
});
});

it('should reject requests without a valid session ID', async () => {
const request = createRequest('POST', TEST_MESSAGES.toolsList);
const response = await transport.handleRequest(request);
Expand Down
Loading