Skip to content

fix: rename platform to os and add new availability axes for provider, target, and surface#433

Open
frontegg-david wants to merge 1 commit into
mainfrom
fix/417-availability-axes
Open

fix: rename platform to os and add new availability axes for provider, target, and surface#433
frontegg-david wants to merge 1 commit into
mainfrom
fix/417-availability-axes

Conversation

@frontegg-david
Copy link
Copy Markdown
Contributor

@frontegg-david frontegg-david commented May 17, 2026

Summary by CodeRabbit

  • New Features

    • Expanded environment availability constraints with additional axes (os, provider, target, surface) for more granular feature gating across different platforms and deployment scenarios.
    • Enhanced error reporting that clearly indicates which constraints failed when a feature is unavailable.
    • Improved environment detection for deployment providers and build targets.
  • Documentation

    • Updated guides reflecting expanded environment constraint options and new error reporting behavior.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 17, 2026

📝 Walkthrough

Walkthrough

This PR implements expanded environment availability axes for granular entry filtering. It adds runtime detection for deployment providers (Vercel, Lambda, Cloudflare, etc.) and build targets, introduces per-request surface filtering, and extends error handling to report which constraint axes failed—enabling better client-side diagnostics when tools become unavailable.

Changes

Environment Availability Axes Expansion

Layer / File(s) Summary
Core environment axes types, detection, and matching
libs/utils/src/env/runtime-context.ts, libs/utils/src/env/browser-runtime-context.ts, libs/utils/src/env/provider.ts, libs/utils/src/env/build-target.ts, libs/utils/src/env/index.ts
RuntimeContext adds os (with deprecated platform alias), provider, and target fields. EntryAvailability expands to include constraints for these axes plus per-request surface gating. Provider detection follows env-var precedence (override → platform-specific vars → Docker check → bare), and build-target resolution checks globalThis then process.env. Both use caching for efficiency. checkEntryAvailability computes availability and returns a list of failed axes (missingAxes).
Test availability axes and environment detection
libs/utils/src/env/__tests__/availability-axes.spec.ts, libs/utils/src/env/__tests__/provider.spec.ts, libs/utils/src/env/__tests__/build-target.spec.ts
Comprehensive test suite covering isEntryAvailable and checkEntryAvailability across all axes, provider detection with override precedence and caching behavior, build-target resolution with priority ordering, and platform/os alias semantics.
Structured error handling with missingAxes
libs/sdk/src/errors/mcp.error.ts
EntryUnavailableError now captures entry metadata (entryType, entryName) and computed missingAxes, and its toJsonRpcError() method returns structured data containing entryType, entry, missingAxes, plus optional constraint and context fields.
Wire availability checking into tool calls
libs/sdk/src/tool/flows/call-tool.flow.ts, libs/sdk/src/transport/mcp-handlers/call-tool-request.handler.ts
Tool-call flow computes missingAxes via checkEntryAvailability and throws EntryUnavailableError with structured diagnostics; request handler tags context with surface: 'mcp' to enable transport-specific filtering.
User-facing documentation
docs/frontmcp/features/environment-awareness.mdx, libs/skills/catalog/frontmcp-development/references/create-tool.md
Documented new constraint axes (os/deprecated platform, provider, target, surface) including detection sources, environment-variable overrides, and enumerated values; introduced "Structured errors" section describing EntryUnavailableError.data.missingAxes for client diagnostics.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

  • agentfront/frontmcp#417: Implements the exact feature requested—adding provider, target, surface axes with runtime detection, checkEntryAvailability, structured missingAxes reporting, and integration into tool-call availability handling.

Possibly related PRs

  • agentfront/frontmcp#329: Both PRs refine entry-availability filtering in the tool-call path; this PR extends the axes and error diagnostics building on the same availability-checking mechanism introduced in #329.

Poem

🐰 A rabbit hops through axes new—
os, provider, target too!
With surface gating per request sent,
missingAxes tells where things went bent.
Availability, now crystalline and clear! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% which is insufficient. The required threshold is 65.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes in the PR: renaming the platform axis to os and adding new availability axes (provider, target, and surface).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/417-availability-axes

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
docs/frontmcp/features/environment-awareness.mdx (2)

330-342: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Inconsistent error format: Missing missingAxes field.

This section documents an EntryUnavailableError response without the missingAxes field, but Lines 160-180 (Structured errors section) document the same error scenario with a missingAxes array. Both describe "tool exists but is unavailable in the current environment."

Per the guideline and issue #417, the error should include missingAxes in its data payload. Either update this example to match the structured error format, or clarify that this section shows a legacy format and reference the Structured errors section for the current implementation.

🔧 Suggested fix: Update to structured error format
 {
   "code": -32003,
-  "message": "Tool \"apple_notes_search\" is not available in the current environment (requires: {\"platform\":[\"darwin\"]}) (current: {\"platform\":\"linux\",\"runtime\":\"node\",\"deployment\":\"standalone\",\"env\":\"production\"})"
+  "message": "Tool \"apple_notes_search\" is not available in the current environment ...",
+  "data": {
+    "entryType": "Tool",
+    "entry": "apple_notes_search",
+    "missingAxes": ["os"],
+    "constraint": { "os": ["darwin"] },
+    "context": { "os": "linux", "runtime": "node", "deployment": "standalone", "env": "production", ... }
+  }
 }

Note: Also changed platform to os to use the non-deprecated field name.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/frontmcp/features/environment-awareness.mdx` around lines 330 - 342,
Update the EntryUnavailableError example so it uses the structured error format:
include a data object with a missingAxes array (e.g., listing the unavailable
axis "os": ["darwin"]) and replace deprecated "platform" with "os"; ensure the
JSON message, code (-32003) and error name EntryUnavailableError remain, and
either reference the Structured errors section or mirror its exact schema so
this example matches the implemented structured error payload.

267-273: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Clarify the relationship between the os property and isPlatform() method in the Runtime Context API section.

The RuntimeContext interface has been renamed to use os as the primary property (with platform as a deprecated alias per issue #417), but the table only documents isPlatform() method. Either:

  1. If isOs() is planned: Add it to the table and note that isPlatform() is deprecated.
  2. If isPlatform() remains the only method: Update the table to explain that isPlatform() checks against the deprecated .platform property, and clarify that users should access .os directly or the method should be updated to use .os.

Additionally, consider adding a row for direct property access (e.g., this.runtimeContext.os) to show the modern way to check the OS axis.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/frontmcp/features/environment-awareness.mdx` around lines 267 - 273,
Update the Runtime Context API docs to clarify the os/platform relationship:
state that RuntimeContext now exposes the OS via the os property
(RuntimeContext.os) and that platform is a deprecated alias; then either add a
new table row for direct property access (this.runtimeContext.os → string |
Description: modern OS axis access) and, if an isOs() helper exists or will be
added, add a row for isOs() and mark isPlatform() as deprecated, or if
isPlatform() remains the only helper, update its table entry to note that
isPlatform() checks the deprecated .platform alias and recommend using
this.runtimeContext.os (or an isOs() helper) going forward. Ensure you reference
RuntimeContext, os, platform, isPlatform(), isOs(), and this.runtimeContext.os
in the text so readers can locate the code/API.
🧹 Nitpick comments (4)
docs/frontmcp/features/environment-awareness.mdx (3)

293-302: ⚡ Quick win

Use os instead of deprecated platform in multi-platform example.

The multi-platform pattern example uses the deprecated platform field. Update to os to demonstrate the preferred axis name.

📝 Suggested fix
 `@Tool`({
   name: 'notes_search',
   description: 'Search notes on this system',
   inputSchema: { query: z.string() },
-  availableWhen: { platform: ['darwin'] },
+  availableWhen: { os: ['darwin'] },
 })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/frontmcp/features/environment-awareness.mdx` around lines 293 - 302,
Update the `@Tool` decorator's availability axis: replace the deprecated
availableWhen: { platform: ['darwin'] } with availableWhen: { os: ['darwin'] }
in the AppleNotesSearchTool declaration (the `@Tool` with name 'notes_search' and
class AppleNotesSearchTool) so the example uses the current os field for
multi-platform scoping.

26-26: ⚡ Quick win

Use the preferred os field instead of deprecated platform alias.

The example introduces availableWhen using the deprecated platform field. Since Line 57 explicitly documents platform as a deprecated alias for os, examples should demonstrate the preferred, non-deprecated name to guide users toward current best practices.

📝 Suggested fix
-  availableWhen: { platform: ['darwin'] },
+  availableWhen: { os: ['darwin'] },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/frontmcp/features/environment-awareness.mdx` at line 26, Replace the
deprecated "platform" alias with the preferred "os" field in the example: update
the availableWhen object (symbol: availableWhen) so it uses os instead of
platform (reference: the existing platform: ['darwin'] entry) to demonstrate the
non-deprecated usage.

188-240: ⚡ Quick win

Update all entry type examples to use os instead of deprecated platform.

The examples in the Tabs demonstrate availableWhen usage across all five entry types (Tool, Resource, Prompt, Skill, Agent), but all use the deprecated platform field. Update them to use os to demonstrate the preferred, non-deprecated axis name.

📝 Suggested changes

Replace platform: ['darwin'] with os: ['darwin'] in:

  • Line 194 (Tool example)
  • Line 204 (Resource example)
  • Line 214 (Prompt example)
  • Line 225 (Skill example)
-      availableWhen: { platform: ['darwin'] },
+      availableWhen: { os: ['darwin'] },

Also update Line 204 (Resource example):

-      availableWhen: { platform: ['darwin', 'linux'] },
+      availableWhen: { os: ['darwin', 'linux'] },
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/frontmcp/features/environment-awareness.mdx` around lines 188 - 240,
Update the examples to use the non-deprecated axis name "os" instead of
"platform": replace availableWhen: { platform: [...] } with availableWhen: { os:
[...] } in the Tool example (AppleNotesSearchTool), Resource example
(SystemInfoResource), Prompt example (XcodeReviewPrompt), Skill example
(IosDeploySkill), and Agent example (LocalBuildAgent); ensure you also change
the Resource entry that currently lists both darwin and linux to use os:
['darwin', 'linux'] so all snippets consistently use "os".
libs/skills/catalog/frontmcp-development/references/create-tool.md (1)

558-570: ⚡ Quick win

Use os instead of deprecated platform in macOS-only tool example.

This example demonstrates platform-specific tooling but uses the deprecated platform field. Per Lines 588, os is the preferred name with platform kept as a deprecated alias. Update the example to use os.

📝 Suggested fix
 // macOS-only tool
 `@Tool`({
   name: 'apple_notes_search',
   description: 'Search Apple Notes',
   inputSchema: { query: z.string() },
-  availableWhen: { platform: ['darwin'] },
+  availableWhen: { os: ['darwin'] },
 })
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@libs/skills/catalog/frontmcp-development/references/create-tool.md` around
lines 558 - 570, Update the macOS-only tool example to use the newer
availableWhen.os key instead of the deprecated availableWhen.platform: in the
`@Tool` decorator for AppleNotesSearchTool replace availableWhen: { platform:
['darwin'] } with availableWhen: { os: ['darwin'] } so the Tool metadata uses os
(platform is only a deprecated alias).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@docs/frontmcp/features/environment-awareness.mdx`:
- Around line 330-342: Update the EntryUnavailableError example so it uses the
structured error format: include a data object with a missingAxes array (e.g.,
listing the unavailable axis "os": ["darwin"]) and replace deprecated "platform"
with "os"; ensure the JSON message, code (-32003) and error name
EntryUnavailableError remain, and either reference the Structured errors section
or mirror its exact schema so this example matches the implemented structured
error payload.
- Around line 267-273: Update the Runtime Context API docs to clarify the
os/platform relationship: state that RuntimeContext now exposes the OS via the
os property (RuntimeContext.os) and that platform is a deprecated alias; then
either add a new table row for direct property access (this.runtimeContext.os →
string | Description: modern OS axis access) and, if an isOs() helper exists or
will be added, add a row for isOs() and mark isPlatform() as deprecated, or if
isPlatform() remains the only helper, update its table entry to note that
isPlatform() checks the deprecated .platform alias and recommend using
this.runtimeContext.os (or an isOs() helper) going forward. Ensure you reference
RuntimeContext, os, platform, isPlatform(), isOs(), and this.runtimeContext.os
in the text so readers can locate the code/API.

---

Nitpick comments:
In `@docs/frontmcp/features/environment-awareness.mdx`:
- Around line 293-302: Update the `@Tool` decorator's availability axis: replace
the deprecated availableWhen: { platform: ['darwin'] } with availableWhen: { os:
['darwin'] } in the AppleNotesSearchTool declaration (the `@Tool` with name
'notes_search' and class AppleNotesSearchTool) so the example uses the current
os field for multi-platform scoping.
- Line 26: Replace the deprecated "platform" alias with the preferred "os" field
in the example: update the availableWhen object (symbol: availableWhen) so it
uses os instead of platform (reference: the existing platform: ['darwin'] entry)
to demonstrate the non-deprecated usage.
- Around line 188-240: Update the examples to use the non-deprecated axis name
"os" instead of "platform": replace availableWhen: { platform: [...] } with
availableWhen: { os: [...] } in the Tool example (AppleNotesSearchTool),
Resource example (SystemInfoResource), Prompt example (XcodeReviewPrompt), Skill
example (IosDeploySkill), and Agent example (LocalBuildAgent); ensure you also
change the Resource entry that currently lists both darwin and linux to use os:
['darwin', 'linux'] so all snippets consistently use "os".

In `@libs/skills/catalog/frontmcp-development/references/create-tool.md`:
- Around line 558-570: Update the macOS-only tool example to use the newer
availableWhen.os key instead of the deprecated availableWhen.platform: in the
`@Tool` decorator for AppleNotesSearchTool replace availableWhen: { platform:
['darwin'] } with availableWhen: { os: ['darwin'] } so the Tool metadata uses os
(platform is only a deprecated alias).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cfcc2e1b-18bf-4592-9363-d066e20083a3

📥 Commits

Reviewing files that changed from the base of the PR and between 4328981 and a626df7.

📒 Files selected for processing (13)
  • docs/frontmcp/features/environment-awareness.mdx
  • libs/sdk/src/errors/mcp.error.ts
  • libs/sdk/src/tool/flows/call-tool.flow.ts
  • libs/sdk/src/transport/mcp-handlers/call-tool-request.handler.ts
  • libs/skills/catalog/frontmcp-development/references/create-tool.md
  • libs/utils/src/env/__tests__/availability-axes.spec.ts
  • libs/utils/src/env/__tests__/build-target.spec.ts
  • libs/utils/src/env/__tests__/provider.spec.ts
  • libs/utils/src/env/browser-runtime-context.ts
  • libs/utils/src/env/build-target.ts
  • libs/utils/src/env/index.ts
  • libs/utils/src/env/provider.ts
  • libs/utils/src/env/runtime-context.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: target / surface / provider filtering for @Tool — make tools available only where they make sense

1 participant