Subscriptions

Loading "Subscriptions"
👨‍💼 When people use our EpicMe journaling MCP, they want the LLM they're using to always have the latest version of their journaling data. Exposing subscriptions for resources (like a particular entry, tag, or video) allows clients to be notified of changes to specific resources the LLM is using in its context or the client may be using for other purposes.
To make this possible, our MCP server needs to support resource subscriptions. This means clients can subscribe to updates for specific resources, and the server will notify them when those resources change.
The key to enabling this with the MCP SDK is the setRequestHandler method. This lets the server listen for subscription requests from clients and track which URIs they're interested in. When something changes, the server can send a notification to just those clients.
Here's an example:
import {
	SubscribeRequestSchema,
	UnsubscribeRequestSchema,
} from '@modelcontextprotocol/sdk/types.js'

const petSubscriptions = new Set<string>()

// NOTE: the server.server is how the MCP SDK exposes the underlying server
// instance for more advanced APIs like this one.

// Allow clients to subscribe to updates for a specific pet
server.server.setRequestHandler(SubscribeRequestSchema, async ({ params }) => {
	petSubscriptions.add(params.uri)
	return {} // no specific response data is needed
})

// Allow clients to unsubscribe from updates
server.server.setRequestHandler(
	UnsubscribeRequestSchema,
	async ({ params }) => {
		petSubscriptions.delete(params.uri)
		return {} // no specific response data is needed
	},
)

// When a pet's status changes, notify subscribed clients
function onPetStatusChange(petId: string, newStatus: string) {
	const uri = `pethotel://pets/${petId}`
	if (petSubscriptions.has(uri)) {
		server.server.notification({
			method: 'notifications/resources/updated',
			params: { uri, title: `Pet ${petId} status updated to ${newStatus}` },
		})
	}
}
👨‍💼 In our journaling MCP, you'll want to use a similar pattern to let clients subscribe to updates for entries, tags, and videos. When any of these resources change, notify the right clients so their UI stays perfectly in sync.
📜 For more details on setRequestHandler and subscriptions, see the official MCP Server Spec: Resources.
The goal is to make real-time updates feel effortless and automatic for users, so they can focus on their journaling—not on hitting the refresh button.
The MCP Inspector supports subscriptions, but does not currently automatically refresh the UI when a resource changes. So you'll want to rely on the tests for this one.

Please set the playground first

Loading "Subscriptions"
Loading "Subscriptions"
Login to get access to the exclusive discord channel.
  • General
    Epic MCP server not initializing
    steve ⚡:
    I am attempting to configure the Epic MCP Server per Kent's instructions here: https://www.epicai.pr...
    • 2
    3 · a day ago
  • 💪Adv. MCP Features
    Elicitation
    nicolai-marina ⚡:
    After completing the elicitation exercise, I am not able to see the form, which confirms the deletio...
    • 1
    5 · 2 days ago
  • General
    What will tomorrows MCP hosts look like?
    Paul 🚀:
    Hi Kent,

Thanks for putting together the course, I’m really enjoying it. Im interested if you have...
    • 1
    2 · 2 days ago
  • 💪Adv. MCP Features
    console.log(capabilities) in Elicit Confirmation exercise
    Rednar ⚡:
    In the solution video, at second 0:55, there's a console.log(capabilities) and Kent says we'll come ...
    • 1
    3 · 3 days ago
  • General
    VS Code Copilot and Epic Workshop MCP Server
    Alexandre 🚀:
    I might have missed something, but how do we install the Epic Workshop MCP Server so we can ask Copi...
    • 1
    3 · 3 days ago
  • 💪Adv. MCP Features
    Resource Templates returning text instead of a schema
    BeyondLimits99 ⚡:
    I was just wondering about the resource templates. I noticed that you're returning the entry schema ...
    • 1
    5 · 3 days ago
  • 🐣MCP Fundamentals
    💪Adv. MCP Features
    🔐MCP Auth
    💻MCP UI
    What about the usage of MCP Servers for some kind of chat interacting with a local LLM?
    frankfullstack ⚡:
    I would like to raise a general question about the usage of MCP Servers and how we could interact fr...
    • 1
    5 · 9 days ago
  • 💪Adv. MCP Features
    Stateful Server Discussion: Elicitation Exercise and Sampling Exercise
    jbandi:
    I am still trying to wrap my head around the stateful communication model of MCP, which is different...
    • 1
    53 · 6 days ago
  • 🐣MCP Fundamentals
    General
    It'd be really cool to have a basic deployment guide.
    BeyondLimits99 ⚡:
    The course has been amazing so far! I'd love to have a basic deployment guide just so I can practice...
    • 2
    3 · 6 days ago
  • 💪Adv. MCP Features
    McpServer Instance Lifecycle
    jbandi:
    ​You just said in the q&a of the office hours that the Mcp Server Instance is "long running" like an...
    • 1
    1 · 5 days ago
  • 💪Adv. MCP Features
    Figuring out isOpenWorld when calling ffmpeg or similar
    Kamran ⚡:
    I would love if you wanted to take this into office hours and expand on how you think about isOpenWo...
    • 👍2
    • 1
    1 · 6 days ago
  • General
    non-related question: how do you rollout updates?
    mark:
    I'm very curious to hear: How do you roll-out new updates? do you use some kind of libary?
    • 1
    5 · 10 days ago
  • 🐣MCP Fundamentals
    General
    How do you teach the LLMs to use ResourceTemplates and ResourceTemplatesList?
    frontendwizard:
    I'm playing around with building an mcp with claude and he has a tendency to go for json for everyth...
    • 1
    8 · 8 days ago
  • 🐣MCP Fundamentals
    General
    MCP to MCP
    Mahendra Hirapra ⚡:
    Does it possible one MCP sever connect to other MCP like chain? I would like to connect Figma MCP Se...
    • 1
    4 · 9 days ago
  • 🐣MCP Fundamentals
    General
    When does an MCP become overkill—that is, when should one avoid building one?
    Lax ⚡:
    Just wondering what scenarios to skip 🙂
    • 1
    2 · 9 days ago
  • 🐣MCP Fundamentals
    General
    💻MCP UI
    🔐MCP Auth
    Are the live sessions, Q&A's or will there be some lectures about concepts around MPC Stack?
    Handax ⚡:
    I’m interested in diving deeper into the Model Contexts Protocol (MCP) and was wondering if there wi...
    • 1
    1 · 9 days ago
  • General
    Lesson lengths
    ffkml ⚡:
    I’m excited for the class to kick off next week. Planning ahead, how long should we plan for lessons...
    • 👍3
    • 1
    1 · 14 days ago