C.W.K.
Stream
Lesson 02 of 04 · published

Feature Detection over Version Sniffing

~20 min · feature-detection, capabilities, sniffing

Level 0Curious Reader
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Even with date revisions, the right mental model is feature detection, not version sniffing. The handshake's capabilities object is the source of truth for what the other side supports. Branching on revision numbers ("if version >= 2025-11-25 then …") is fragile; branching on advertised capability ("if 'sampling' in capabilities then …") survives every revision.

This shows up the most in transitional features. Async tasks landed in the 2025-11-25 revision; hosts that want to call long-running tools should check whether the server advertises the asyncTasks capability before picking the async path. A server that knows about async tasks but cannot run them in the current deployment can simply not advertise the capability — clients adapt without knowing the deployment story.

The same shape applies to client capabilities. A server that wants to use sampling MUST check whether the host advertised sampling before sending a sampling request. Sending one without the capability is a protocol violation; the host is allowed to drop the connection. Treat the capabilities object like a feature bitmap; treat version numbers as audit trail.

Code

Feature-detection branches·python
init = await session.initialize()
caps = init.capabilities

# Right — branch on advertised capability
if caps.get("logging"):
    await session.set_logging_level("info")

# Right — branch on extension presence (async tasks were added in 2025-11-25,
# but feature-detection works even before anyone hard-codes the date)
if caps.get("experimental", {}).get("asyncTasks"):
    return await call_async(...)
else:
    return await call_sync(...)
Wrong shape — sniffing the version·python
# Avoid this — fragile if a server backports or skips a feature
if init.protocolVersion >= "2025-11-25":
    return await call_async(...)

External links

Exercise

Search your client/server code for any string-comparison against a date or version number ('2025-11-25', '>=', etc.) and replace it with a capability check. Most version-sniffing code is just feature-detection that skipped the easier path.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.