This enables platform-specific tools (e.g., Apple Notes on macOS only), runtime-specific resources (e.g., Node.js file system), and environment-gated features (e.g., debug tools in development only).
The availableWhen Option
Add availableWhen to any entry’s metadata to constrain its availability:
Matching Semantics
- AND across fields — all specified fields must match
- OR within arrays — at least one value in an array must match
- Omitted fields — unconstrained (matches everything)
- Empty array — matches nothing (entry is never available)
- No
availableWhen— always available (default)
Available Fields
platform
Operating system, matching process.platform values:
| Value | OS |
|---|---|
'darwin' | macOS |
'linux' | Linux |
'win32' | Windows |
'freebsd' | FreeBSD |
runtime
JavaScript runtime:
| Value | Runtime |
|---|---|
'node' | Node.js |
'bun' | Bun |
'deno' | Deno |
'edge' | Edge runtime (Vercel, CF) |
'browser' | Browser |
deployment
Deployment mode:
| Value | Description |
|---|---|
'standalone' | Standard server |
'serverless' | Serverless (Lambda, Vercel) |
env
NODE_ENV value:
| Value | Description |
|---|---|
'production' | Production |
'development' | Development |
'test' | Testing |
Supported Entry Types
availableWhen works on all five entry types:
- Tool
- Resource
- Prompt
- Skill
- Agent
Runtime Context API
Insideexecute() methods, use runtime context helpers for imperative checks:
Available Methods
| Method | Returns | Description |
|---|---|---|
this.isPlatform('darwin') | boolean | Check OS platform |
this.isRuntime('node') | boolean | Check JavaScript runtime |
this.isDeployment('serverless') | boolean | Check deployment mode |
this.isEnv('production') | boolean | Check NODE_ENV |
this.runtimeContext | RuntimeContext | Full context object |
ToolContext, ResourceContext, PromptContext, and AgentContext.
Multi-Platform Pattern
When building tools that serve the same purpose across platforms, use separate files withavailableWhen in each:
Error Handling
When a client tries to call a tool that exists but is unavailable in the current environment, the SDK returns anEntryUnavailableError (HTTP 403) with both the constraint and the current context:
ToolNotFoundError (404), helping clients understand why a tool is inaccessible.
How It Works: Registry-Level Filtering
| Concern | Layer | When | Scope |
|---|---|---|---|
availableWhen | Registry (boot) | Server startup | Process-wide, immutable |
| Authorization | HTTP flow (request) | Per request | Per session/user |
| Rule-based filtering | HTTP flow (request) | Per request | Dynamic, policy-driven |
hideFromDiscovery | Registry (listing) | Per list call | Soft hide (entry still callable) |
availableWhenis a hard constraint — filtered entries cannot be listed OR called- It runs at registry initialization, not in HTTP flows — no per-request overhead
- The runtime context (OS, runtime, deployment, NODE_ENV) is detected once and cached
- Results are logged at boot time for operational visibility
Boot-Time Logging
When entries haveavailableWhen constraints, the SDK logs a summary at startup: