Skip to content

improvement(api): centralize remaining v2 resource operations - #6412

Merged
TheodoreSpeaks merged 2 commits into
improvement/v2-endpointsfrom
codex/v2-application-tools
Aug 8, 2026
Merged

improvement(api): centralize remaining v2 resource operations#6412
TheodoreSpeaks merged 2 commits into
improvement/v2-endpointsfrom
codex/v2-application-tools

Conversation

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator

Summary

Migrates all 18 remaining v2 custom-tool, MCP-server, skill, and secret operations to declarative v2 JSON routes backed by shared Principal-aware semantic operations and authorized application use cases.

Copilot management tools now reuse the same application use cases through a shared trusted delegated-principal adapter. Semantic audit stays in the application wrapper, while v2 and Copilot product analytics remain surface-specific. Strict v2 create behavior remains separate from compatibility save/register operations.

Deferred by design: hybrid internal bulk/upsert routes and credential-wide surfaces retain their existing adapters and compatibility wrappers. v1, workspace files, knowledge, workflows, tables, billing, logs, credentials, audit logs, and workspaces are unchanged.

Fixes: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: application architecture migration

Testing

  • 53 focused Vitest regressions across routes, application authorization/audit, Principal delegation, errors, MCP lifecycle, and Copilot management tools
  • Full Biome lint and lint check
  • Sim and @sim/auth type checks
  • Strict API validation audit
  • OpenAPI, monorepo-boundary, shared-utils, and client-boundary checks
  • Generator projection checks and git diff check

Reviewers should focus on principal-kind policy, compatibility separation between strict create and save/register operations, audit attribution for workspace API keys, and MCP post-audit effects.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

Not applicable; no UI changes.

@vercel

vercelBot commented Aug 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
ProjectDeploymentActionsUpdated (UTC)
docsSkippedSkippedAug 8, 2026 12:36pm

Request Review

@cursor

cursorBot commented Aug 8, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Large refactor of public v2 APIs and Copilot write paths; authorization and compatibility (strict create vs save/register) now depend on centralized operation policies and delegated principals rather than inline route logic.

Overview
v2 custom-tools, MCP servers, skills, and secrets no longer run workspace access, rate limits, and domain logic inside withPublicApiRouteHandler handlers. Those routes are now defineV2JsonRoute wiring: v2 API key auth, public API rate limits, semantic operations, and application use cases with source: 'api' and orchestration error mapping.

Copilotmanage_custom_tool, manage_mcp_tool, and manage_skill call the same use cases through a trusted delegated principal built only from server execution context (not model-supplied user/workspace). Route-level audit for v2 writes moves into the application layer; PostHog stays on the v2 routes (personal keys for MCP/skills) and Copilot tool handlers.

defineV2JsonRoute adds optional onSuccess and statusForResult (e.g. secret PUT 201 vs 200). Create contracts for custom tools, MCP, and skills declare 201 responses.

New per-domain operations and delegation audiences gate principal kinds (e.g. workspace API keys denied for some “available” Copilot-only operations).

Reviewed by Cursor Bugbot for commit 58419aa. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-appsBot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR centralizes the remaining v2 custom-tool, MCP-server, skill, and secret routes around shared Principal-aware application operations while preserving separate compatibility paths for Copilot and workflow callers.

  • Replaces custom route adapters with declarative v2 JSON route definitions.
  • Consolidates authorization, audit attribution, and semantic operation handling in application use cases.
  • Delegates Copilot management actions through trusted workspace-scoped principals.
  • Moves MCP runtime effects into post-audit application hooks while retaining surface-specific analytics.

Confidence Score: 5/5

The PR appears safe to merge because no blocking failure remains in the available follow-up review scope.

No blocking failure remains.

Important Files Changed

FilenameOverview
apps/sim/lib/api/server/routes/v2-json-route.tsProvides the declarative v2 route pipeline that authenticates, validates, rate-limits, invokes authorized use cases, and presents responses.
apps/sim/lib/copilot/auth/workspace-application-delegation.tsConstructs trusted workspace-scoped delegated principals for Copilot application-use-case execution.
apps/sim/lib/custom-tools/application/use-cases.tsCentralizes custom-tool authorization, strict creation, compatibility save behavior, audit projection, and error normalization.
apps/sim/lib/mcp/application/use-cases.tsCentralizes MCP operations and sequences semantic audit before post-success runtime lifecycle effects.
apps/sim/lib/mcp/orchestration/server-lifecycle.tsExposes shared MCP persistence and runtime-effect primitives used by application and compatibility paths.
apps/sim/lib/skills/application/use-cases.tsCentralizes authorized skill resource operations for v2 and delegated Copilot callers.
apps/sim/lib/secrets/application/use-cases.tsMoves v2 secret operations behind shared Principal-aware application use cases.
apps/sim/app/api/v2/custom-tools/route.tsReplaces bespoke list/create handling with declarative contracts and shared custom-tool use cases.
apps/sim/app/api/v2/mcp-servers/route.tsRoutes MCP list/create requests through centralized semantic operations while retaining v2-specific presentation and analytics.
apps/sim/app/api/v2/skills/route.tsRoutes skill list/create requests through centralized authorization and application behavior.

Sequence Diagram

sequenceDiagram
participant Client as v2 API or Copilot
participant Adapter as Surface Adapter
participant UseCase as Authorized Use Case
participant Authz as Workspace Authorization
participant Domain as Semantic Operation
participant Audit as Audit
participant Effects as Post-success Effects
Client->>Adapter: Resource operation
Adapter->>UseCase: Principal and normalized input
UseCase->>Authz: Authorize principal and workspace
Authz-->>UseCase: Authorized context
UseCase->>Domain: Execute mutation or query
Domain-->>UseCase: Domain result
opt Audited mutation
UseCase->>Audit: Record semantic audit
end
opt MCP lifecycle mutation
UseCase->>Effects: Apply cache and connection effects
end
UseCase-->>Adapter: Result
Adapter-->>Client: Surface-specific response and analytics
Loading

Reviews (2): Last reviewed commit: "fix(api): preserve custom tool conflict ..." | Re-trigger Greptile

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 51dec53. Configure here.

Comment threadapps/sim/lib/custom-tools/application/use-cases.ts
@TheodoreSpeaks

Copy link
Copy Markdown
CollaboratorAuthor

@greptile

@TheodoreSpeaks
TheodoreSpeaks merged commit 5de6269 into improvement/v2-endpointsAug 8, 2026
5 checks passed
@TheodoreSpeaks
TheodoreSpeaks deleted the codex/v2-application-tools branch August 8, 2026 17:34
Sign up for freeto 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.

1 participant

@TheodoreSpeaks