Cancellation

Loading "Cancellation"
👨‍💼 When users embark on creating their personalized wrapped video, the process can take a while (especially if they journal a lot). Sometimes, halfway through, they realize they picked the wrong year, or maybe their cat walks across the keyboard and they want to stop the operation immediately. It's essential that our app gives users the power to cancel these long-running tasks, so they always feel in control and never stuck waiting for something they no longer want.
Let's make sure users can hit the "Stop" button and have their request canceled right away, freeing up system resources and making the experience feel responsive and modern.
NOTE: As of this writing, there is no support for a stop button in the MCP inspector. Follow this issue for updates.
Here's an example of how cancellation can be handled in our MCP server using the AbortController and signals:
// the signal comes from the SDK and is passed to our tool
const controller = new AbortController()
const signal = controller.signal

async function createPlaylistMashup({
	songs,
	onProgress,
	// we pass the signal to our utility so we can add an event listener to it
	signal,
}: {
	songs: string[]
	onProgress?: (progress: number) => void
	signal?: AbortSignal
}) {
	if (signal?.aborted) throw new Error('Mashup creation was cancelled')

	// our logic...
	const promise = doTheAsyncThing()

	function onAbort() {
		// we can do something here, like send a notification to the user
		// that the mashup was cancelled. This should trigger the async thing to throw an error.
	}
	signal.addEventListener('abort', onAbort)
	await promise.finally(() => {
		// make sure to clean up regardless of whether the promise resolves or rejects
		signal.removeEventListener('abort', onAbort)
	})

	return 'Mashup complete!'
}

// Somewhere in the SDK, this gets called when the user wants to cancel:
controller.abort()
AppUserAppUserMashup in progressStart playlist mashup (id: 42)notifications/cancelled (requestId: 42, reason: "Changed my mind!")(No response for cancelled request)
📜 For more details on how to implement cancellation, see the MCP Cancellation Documentation.
The goal is to empower users to stop long-running operations at any time, making the app feel fast, flexible, and user-friendly—even when things don't go as planned.
Now, please update our create_wrapped_video tool to support cancellation.
Because the MCP Inspector does not support cancellation yet, you'll need to rely on the tests to verify your cancellation is working.

Please set the playground first

Loading "Cancellation"
Loading "Cancellation"
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