List Changed
👨💼 When people use the Epic Me journal app, they expect the interface to always reflect what's possible right now. If a new journaling prompt becomes available, or a feature is temporarily disabled, users want the UI to update instantly. No confusion, no stale buttons, just a smooth, up-to-date experience.
That's why it's so important for our MCP server to notify the client whenever the set of available prompts, tools, or resources changes. This allows the client app to feel alive and responsive, and ensures users always see the right options for their current context, whether they're a first-time journaler or a seasoned reflection pro.
Let's look at an example of how this is done: imagine a smart vending machine that offers snacks based on the time of day. In the morning, it might offer coffee and bagels; in the afternoon, chips and soda. When the available snacks change, the server should notify the client so the snack menu updates automatically.
Here's how you might enable list change notifications for prompts using the MCP SDK:
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
const server = new McpServer(
{
name: 'SnackBot',
version: '1.0.0',
},
{
capabilities: {
prompts: { listChanged: true },
// ...other capabilities
},
},
)
// When the snack list changes, enable or disable prompts as needed
function updateSnackPrompts() {
if (isMorning()) {
if (!coffeePrompt.enabled) coffeePrompt.enable()
if (chipsPrompt.enabled) chipsPrompt.disable()
} else {
if (!chipsPrompt.enabled) chipsPrompt.enable()
if (coffeePrompt.enabled) coffeePrompt.disable()
}
}
The MCP SDK automatically sends
list_changed
notifications when you enable
or disable prompts, so the client always knows when to refresh its list.This approach means users never see a "Make Coffee" button at 3pm, or a "Get Chips" option before breakfast. The UI stays in sync with what's actually available, making the experience feel smart and effortless.
📜 For more details, see the Server Spec: Prompts.
The MCP Inspector supports list change notifications, but does not currently automatically refresh the UI when lists change. So you'll want to rely on the tests for this one.