Build and Deploy MCP Integrations
Build a Model Context Protocol client and server, then verify the integration with a compatible host.
server/discover, declared capabilities, and talking to legacy and modern software alike.
How does a host know which optional interaction a server actually supports?
Capability discovery moves assumptions into declared data. Read the advertised capabilities, choose a mutually supported flow, and gate operations that rely on optional support.
Host requests available capabilities
Server declares what it supports
Host offers only operations whose requirements are met
Host requests available capabilities
Server declares what it supports
Host offers only operations whose requirements are met
Given Host requests available capabilities and Host offers only operations whose requirements are met, write down the missing step that connects them.
Server declares what it supports
Now take Server declares what it supports and the result above. Write an input and an implementation that could produce this trace.
Host requests available capabilities. Check that your implementation produces the result shown above.
A tool needs an interactive response from the client, and the client declares no such capability. Should the host start the call?
The host should prevent the incompatible call and explain the missing capability. Otherwise the server can reach a point where it needs a response the client cannot provide.
Check this when debugging. Using a client capability the request didn't declare.
Versions and stateless requests made every MCP request stand on its own. That raises two questions. How does a client find out what a server can do before it starts asking? And how do new clients keep talking to the many servers that still open with a handshake? MCP answers the first with a method called server/discover and a vocabulary of capabilities, and the second with dual-era software that speaks both styles. You'll meet both in the wild, and the server you build in Capstone: a production MCP server has to get them right.
What it offers: its versions, capabilities and instructions
Discovery tells the client what the server can do and which protocol revisions it speaks, so the client knows what to ask for and how. This lesson covers that sign on the door.
This rests on Versions and stateless requests: every request names its own version and capabilities. Two questions follow. How does a client learn what a server offers before it asks? And how does a new client still reach a server that wants a handshake?
Walk up to a shop and the sign on the door tells you the hours, what it sells and whether it takes cards. You know before you go in.
Every modern server must implement server/discover. It's that sign. It returns:
supportedVersions: the revisions it speaks, newest first.capabilities: the optional features it offers (more on these below).serverInfo, inside the result's _meta: its name and version.instructions (optional): plain-language guidance a host can pass to the model about how to use the server. "Use confirm_order only after the customer has seen the total" is the kind of thing that goes here.ttlMs and cacheScope: how long the answer may be cached, in milliseconds, and whether a shared cache may keep it ("public") or only this caller ("private"). Every discover result carries both.supportedVersions
supportedVersions lists the revisions, newest first. capabilities lists optional features, and serverInfo, in the result's _meta, names the server.
Calling it first is optional. A client can send any request straight away and handle a version error if one comes back. But discover is a cheap way to show "what can this server do?" in one call, and a host can cache the result for as long as ttlMs allows. Like any request, discover itself carries _meta with a version and capabilities. If the server doesn't speak that version, it says so with -32022, the same error as for any other method.
In plain words: discover is one call that returns everything a client needs to decide how to talk to this server.
ours = ["2026-07-28", "2025-11-25"] error = {"code": -32022, "data": {"supported": ["2025-11-25", "2025-06-18"], "requested": "2026-07-28"}} retry_with = next((v for v in ours if v in error["data"]["supported"]), None) print(error["code"] == -32022, retry_with)
True 2025-11-25
The client's first choice isn't in the server's list, and its second is, so it retries with 2025-11-25. A version is one thing the two sides have to agree on. Capabilities, in this lesson, are the other: which optional features each side supports.
The practice server is dual-era. Send server/discover and read the versions, capabilities and instructions it returns. An unsupported version gets a 400 listing the supported ones, and the legacy initialize still works. The headers are covered in the Streamable HTTP lesson.
instructions string from a server's discover result. What should it do with it?Pass it to the model as guidance on using this server's tools
instructions is the server's advice to the model, such as when a tool should or shouldn't be called. Versions come from supportedVersions, and the user never needs to see it.
Capabilities are how each side says which optional features it supports. It's like telling a caller that your phone can't receive photos, so they don't send one.
tools, resources and prompts. Each may add details, such as listChanged, which means the server can announce when its list changes.elicitation, which means the server may ask the user a question mid-call.extensions: optional add-ons named like io.modelcontextprotocol/tasks.Because every request carries the client's capabilities, a server knows on each call what it may do. The rule is strict. A server must never rely on a capability the client didn't declare. If a request can't be done without one, the server answers MissingRequiredClientCapability, error code -32021, saying which capabilities it needed:
{"jsonrpc": "2.0", "id": 5, "error": {"code": -32021,
"message": "confirm_order needs elicitation",
"data": {"requiredCapabilities": {"elicitation": {}}}}}
The client can then decide: add the capability if it has it, or tell the user that this tool needs a feature their app lacks. An empty clientCapabilities of {} is valid. It means "only the basics", and it keeps simple scripts simple.
In plain words: each side declares what it can do, and nobody uses a feature the other side didn't declare.
elicitation capability. What does this print for three clients' declared capabilities?def can_ask_user(client_capabilities): return "elicitation" in client_capabilities print(can_ask_user({"elicitation": {}}), can_ask_user({}), can_ask_user({"sampling": {}}))
True False False
Only the first client said it can show a question to its user. For the other two, the server must not send one and hope. It answers with MissingRequiredClientCapability, which names what was needed, and the client can decide what to do about it.
New software must still talk to old software. Think of a bilingual receptionist who answers each caller in whichever language they open with. The spec defines dual-era clients and servers that speak both styles.
A dual-era server looks at how each request opens. An initialize request gets the legacy handshake. A request carrying modern _meta is served statelessly. The same server does both.
A dual-era client has to find out which kind of server it's facing. On stdio, it sends server/discover first. A proper discover result means the server is modern. So does a modern error such as UnsupportedProtocolVersion, because only a modern server knows that code. Any other error, or no answer at all, means the server is legacy, so the client falls back to initialize. Over HTTP it tries a modern request and reads the body of a 400 the same way.
server/discover and gets UnsupportedProtocolVersion back. What kind of server is it?Modern: only a modern server knows that error
A legacy server has never heard of that error code. Getting it back proves the server speaks the modern style, in a different version.
The answer is a property of the server, not of the moment, so clients cache it instead of probing every time. A client asks again only when its cached discover result's ttlMs runs out, or when a call that used to work starts returning a version error, which means the server was upgraded underneath it.
A modern-only client can't use a legacy server, and a legacy-only client can't use a modern-only server. That's why many SDKs and hosts stay dual-era during the transition, and why the spec now keeps a deprecated feature for at least twelve months before it may be removed (ninety days under an expedited exception).
In plain words: a dual-era client asks "discover?" once. A real answer or a modern error means modern; anything else means legacy.
Write a sentence or two, then compare it with a good answer in the lesson.
This part writes the server's guard and the client's probe, and runs the probe against a server that really is dual-era.
A server checks the request's declared capabilities before it does anything that needs one. The same tool is refused for a plain client and runs for a richer one.
PV = "io.modelcontextprotocol/protocolVersion" CAPS = "io.modelcontextprotocol/clientCapabilities" def needs(meta, *names): """The capabilities a request lacks, so the server can refuse before it starts.""" declared = meta.get(CAPS, {}) return [n for n in names if n not in declared] plain = {PV: "2026-07-28", CAPS: {}} rich = {PV: "2026-07-28", CAPS: {"elicitation": {}, "extensions": {"io.modelcontextprotocol/tasks": {}}}} for label, meta in [("plain client", plain), ("rich client", rich)]: missing = needs(meta, "elicitation") if missing: print(label, "-> error -32021, requiredCapabilities:", {m: {} for m in missing}) else: print(label, "-> ask the user, then confirm")
The check happens before the tool does any work, so a refused call changes nothing. The error's data names exactly what was missing (elicitation, for the plain client), so a client can fix its request instead of guessing.
Capabilities are nested dictionaries, like {"tools": {"listChanged": True}, "resources": {}}. Write supports(caps, path): path is dotted, like "tools.listChanged" or "resources". Return True if every key along the path exists and the final value isn't False or None (an empty dict still means "supported").
def supports(caps, path): return path in caps caps = {"tools": {"listChanged": True}, "resources": {}, "prompts": {"listChanged": False}} print(supports(caps, "tools.listChanged"), supports(caps, "elicitation"))
{}. What should the server do?Return MissingRequiredClientCapability (-32021), naming elicitation as required
Servers may only use capabilities the client declared on that request. The error tells the client exactly what's missing.
A dual-era client sends server/discover and decides from the reply. Four replies, four decisions.
MODERN_ERRORS = {-32022, -32021} # only a modern server knows these codes
def era(reply):
"""Decide from a server's reply to server/discover."""
if reply is None:
return "legacy" # no answer at all
if "result" in reply:
return "modern"
code = reply["error"]["code"]
return "modern" if code in MODERN_ERRORS else "legacy"
print(era({"result": {"supportedVersions": ["2026-07-28"]}}))
print(era({"error": {"code": -32022, "message": "Unsupported protocol version"}}))
print(era({"error": {"code": -32601, "message": "Method not found"}}))
print(era(None))A result is modern, and so is a version error, because the server understood the question. Method not found and silence both mean the server never learned discover, so the client should send initialize next. The decision is cached per server.
The practice server speaks both eras. This cell runs era() on three exchanges: a discover that gets a result, a discover with a version the server doesn't know (a modern error, so still modern) and the legacy initialize on the same server.
import requests URL = "https://api.gradient.test/mcp" PV = "io.modelcontextprotocol/protocolVersion" CAPS = "io.modelcontextprotocol/clientCapabilities" MODERN_ERRORS = {-32022, -32021} def post(method, version=None, params=None): params = dict(params or {}) headers = {} if version: params["_meta"] = {PV: version, CAPS: {}} headers = {"MCP-Protocol-Version": version, "Mcp-Method": method} body = {"jsonrpc": "2.0", "id": 1, "method": method, "params": params} return requests.post(URL, json=body, headers=headers).json() def era(reply): if reply is None: return "legacy" if "result" in reply: return "modern" return "modern" if reply["error"]["code"] in MODERN_ERRORS else "legacy" print(era(post("server/discover", "2026-07-28"))) print(era(post("server/discover", "2027-01-15"))) legacy = post("initialize", params={"protocolVersion": "2025-06-18"}) print(legacy["result"]["protocolVersion"], "from the same server")
Write summary(result): from a discovery result with capabilities, and the server's name and version in its _meta under INFO, return "NAME VERSION: " followed by the capability names that are present, sorted and joined with ", ", or "no capabilities" if there are none.
INFO = "io.modelcontextprotocol/serverInfo" RESULT = { "_meta": {INFO: {"name": "campaigns", "version": "1.4.0"}}, "capabilities": {"tools": {"listChanged": True}, "resources": {}, "logging": {}}, } def summary(result): return result["_meta"][INFO]["name"] print(summary(RESULT))
def era(reply): if "result" in reply: return "modern" return "modern" if reply["error"]["code"] in (-32022, -32021) else "legacy" print(era({"error": {"code": -32601}}), era({"error": {"code": -32021}}))
legacy modern
-32601 (Method not found) isn't a modern code, so the first is legacy. -32021 (MissingRequiredClientCapability) is one, so the second server is modern even though it refused.
Write a sentence or two, then compare it with a good answer in the lesson.
Purpose. See what a real host does with the discover result, and which part of it reaches the model.
Of everything in a discover result, the host sends one field to the model: instructions. Versions and capabilities stay inside the host's client, where they decide what to call. The instructions go into the system prompt, labeled by server, next to the host's own. Server authors set the string when they build the server (the official SDKs take an instructions setting; check the name in the SDK you use).
Because instructions reaches the model, it is also text the model may obey. A server you don't control can put anything there, so a careful host shows it to the user when the server is added, the way it shows tool descriptions (MCP security).
In an engineer's week. A new host version starts probing with server/discover, and a legacy server that logs every unknown method starts logging errors. That is expected: it is the probe. What goes wrong is a client that treats the first error as "server down" instead of "legacy", and a probe repeated on every call because nobody cached the era.
Write a sentence or two, then compare it with a good answer in the lesson.
Start with a short baseline or choose guided, independent, or AI-assisted practice.
A dual-era client on stdio sends server/discover and gets a "Method not found" error. What should it conclude?
575 lessons in thirteen phases. 176 are free without an account, and a free account opens the rest. See every lesson.
Build a Model Context Protocol client and server, then verify the integration with a compatible host.
Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write