Serve subscriptions/listen with a pluggable event bus (SEP-2575) (#3035)

This commit is contained in:
Max 2026-06-30 23:01:04 +01:00 • committed by GitHub
commit ca10dade2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,7 +13,7 @@ from typing import Annotated, Any
import click
from mcp.server import ServerRequestContext
from mcp.server.mcpserver import Context, MCPServer, RequestStateSecurity
from mcp.server.mcpserver.prompts.base import UserMessage
from mcp.server.mcpserver.prompts.base import Prompt, UserMessage
from mcp.server.streamable_http import EventCallback, EventMessage, EventStore
from mcp.shared.exceptions import MCPError
from mcp_types import (
@ -585,6 +585,34 @@ async def test_reconnection(ctx: Context) -> str:
return "Reconnection test completed"
def _dynamic_tool() -> str:
"""A tool registered and removed by test_trigger_tool_change."""
return "dynamic"
def _dynamic_prompt() -> str:
"""A prompt registered and removed by test_trigger_prompt_change."""
return "dynamic"
@mcp.tool()
async def test_trigger_tool_change(ctx: Context) -> str:
"""Mutates the tool list and announces it to subscriptions/listen streams (SEP-2575)"""
mcp.add_tool(_dynamic_tool, name="test_dynamic_tool")
mcp.remove_tool("test_dynamic_tool")
await ctx.notify_tools_changed()
return "tool list changed"
@mcp.tool()
async def test_trigger_prompt_change(ctx: Context) -> str:
"""Mutates the prompt list and announces it to subscriptions/listen streams (SEP-2575)"""
mcp.add_prompt(Prompt.from_function(_dynamic_prompt, name="test_dynamic_prompt", description="dynamic"))
mcp.remove_prompt("test_dynamic_prompt")
await ctx.notify_prompts_changed()
return "prompt list changed"
# Resources
@mcp.resource("test://static-text")
def static_text_resource() -> str: