Skip to content

fix(onedrive): align tools with live Graph API docs, add missing endpoints#5478

Merged
waleedlatif1 merged 7 commits into
stagingfrom
validate/onedrive-integration
Jul 7, 2026
Merged

fix(onedrive): align tools with live Graph API docs, add missing endpoints#5478
waleedlatif1 merged 7 commits into
stagingfrom
validate/onedrive-integration

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Fixed a critical bug: search, move, copy, and create_share_link tools were registered but never wired into the block's operation switch/tools.access — selecting those operations in the UI would throw Invalid OneDrive operation
  • Fixed tools.config.params to correctly remap the new canonical subBlock ids (moveFileId, copyDestinationFolderId, etc.) to the tool param names the tools actually expect
  • Added onedrive_get_item and onedrive_get_drive_info tools (item metadata by id/path, drive quota) — both fully covered by the existing Files.Read scope, no new permissions needed
  • Added missing block inputs/outputs for the new operations
  • Alphabetized onedrive entries in tools/registry.ts
  • Validated every tool's request/response shape against the live Microsoft Graph API docs (driveItem resource, copy/move/search/createLink endpoints)

Constraint followed throughout: no new OAuth scopes added or proposed. Endpoints requiring broader scope (sharing-permission management beyond createLink, SharePoint-backed version history, cross-drive access) were identified and deliberately left out.

Type of Change

  • Bug fix

Testing

Tested manually. bun run lint, bunx tsc --noEmit, and existing onedrive/block/tool test suites all pass.

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)

…oints

- wire up search/move/copy/create_share_link tools into block operation switch (were registered but unreachable, would throw 'Invalid OneDrive operation')
- fix tools.config.params to remap new canonical subBlock ids to correct tool param names
- add onedrive_get_item and onedrive_get_drive_info tools (item metadata, drive quota) — both within existing Files.Read/Files.ReadWrite scope
- add missing block inputs/outputs for new operations
- alphabetize onedrive registry entries
@cursor

cursor Bot commented Jul 7, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Adds file move/delete/copy and sharing-link creation against live OneDrive data; mistakes could relocate or expose content, though behavior follows existing OAuth scopes and Graph patterns.

Overview
Fixes a UI/runtime bug where OneDrive operations like search, move, copy, and create sharing link were exposed in the block but not mapped in tools.access, the operation switch, or tools.config.params, so runs failed with Invalid OneDrive operation.

Expands the OneDrive block and tool layer with search, get item metadata, get drive info (quota), move/rename, copy (async 202 + monitor URL), and create sharing link—plus UI sub-blocks, inputs/outputs, and registry entries. List/search gain pageToken pagination (validated Graph next URLs), safer OData quoting for filters/search, and download URLs in list results.

Refactors tool params from folderSelector / manualFolderId to a single folderId aligned with the block’s canonical folder IDs.

Reviewed by Cursor Bugbot for commit 5584abe. Configure here.

@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 7, 2026 7:05pm

Request Review

@greptile-apps

greptile-apps Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a long-standing wiring bug where search, move, copy, and create_share_link operations were exposed in the OneDrive block UI but never routed to a tool, causing every call to throw Invalid OneDrive operation. It also adds two new tools (get_item, get_drive_info), consolidates the dual folderSelector/manualFolderId params into a single folderId, adds OData-safe escaping to the list filter, and introduces pagination support via pageToken.

  • Bug fix (critical): The block's tool() switch and tools.access array now correctly include all six previously dead operations, and the params() function remaps their canonical sub-block IDs (moveFileId, copyDestinationFolderId, shareLinkFileId, etc.) to the param names each tool expects.
  • New tools: onedrive_get_item (item metadata by ID or root) and onedrive_get_drive_info (quota/owner) are added within the existing Files.Read scope; onedrive_copy correctly handles the Graph API's async 202+Location pattern.
  • OData safety: escapeODataStringLiteral now guards both the list $filter predicate and the search(q='...') path component against single-quote injection; pagination nextLink URLs are validated via assertGraphNextPageUrl to prevent SSRF.

Confidence Score: 5/5

Safe to merge — the changes are additive and the critical wiring fix is correctly implemented.

The core bug fix correctly routes all previously dead operations through the switch and remaps canonical param IDs to tool param names. New tools follow established patterns; the async copy tool correctly handles the 202+Location contract. The framework’s !resolvedResponse.ok guard in executeRequest handles HTTP errors before transformResponse is reached, so the absence of explicit status checks in the simpler new tools is not a defect. OData escaping and pagination URL validation were applied consistently.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/blocks/blocks/onedrive.ts Wires six previously missing operations into the tool/operation switch and correctly remaps canonical sub-block IDs to tool param names; block inputs/outputs updated to match.
apps/sim/tools/onedrive/move.ts New tool implementing PATCH /me/drive/items/{id} for move/rename; validates that at least one of destinationFolderId or newName is present before sending the request.
apps/sim/tools/onedrive/copy.ts New tool implementing POST /me/drive/items/{id}/copy; correctly handles the 202 Accepted + Location header pattern for async Graph API copies.
apps/sim/tools/onedrive/search.ts New tool using /me/drive/root/search(q='...'); correctly uses OData double-quote escaping and delegates pagination URL validation to assertGraphNextPageUrl.
apps/sim/tools/onedrive/utils.ts Adds escapeODataStringLiteral which is functionally identical to the existing escapeODataString in sharepoint/utils.ts — minor duplication worth consolidating.
apps/sim/tools/onedrive/list.ts Consolidates folderSelector/manualFolderId into a single folderId param, adds pageToken support, and fixes OData escaping in the $filter predicate.
apps/sim/tools/onedrive/types.ts Adds response interfaces for all new operations and extends OneDriveToolParams with move/copy/share-link-specific fields.
apps/sim/tools/registry.ts Adds six new OneDrive tools to the registry in alphabetical order; straightforward registration change.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant UI as Block UI
    participant Block as onedrive.ts (block config)
    participant Exec as Tool Executor (utils.server.ts)
    participant Tool as Tool Handler
    participant Graph as Microsoft Graph API

    UI->>Block: User selects operation + fills params
    Block->>Block: tool() switch resolves tool ID
    Block->>Block: params() remaps canonical IDs to tool params
    Block->>Exec: executeRequest(toolId, tool, resolvedParams)
    Exec->>Graph: fetch(url, method, headers, body)
    Graph-->>Exec: HTTP Response
    alt "response.ok === false"
        Exec-->>Block: throw Error
    else "response.ok === true"
        Exec->>Tool: transformResponse(response, params)
        Tool-->>Exec: success + output
        Exec-->>Block: ToolResponse
    end
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant UI as Block UI
    participant Block as onedrive.ts (block config)
    participant Exec as Tool Executor (utils.server.ts)
    participant Tool as Tool Handler
    participant Graph as Microsoft Graph API

    UI->>Block: User selects operation + fills params
    Block->>Block: tool() switch resolves tool ID
    Block->>Block: params() remaps canonical IDs to tool params
    Block->>Exec: executeRequest(toolId, tool, resolvedParams)
    Exec->>Graph: fetch(url, method, headers, body)
    Graph-->>Exec: HTTP Response
    alt "response.ok === false"
        Exec-->>Block: throw Error
    else "response.ok === true"
        Exec->>Tool: transformResponse(response, params)
        Tool-->>Exec: success + output
        Exec-->>Block: ToolResponse
    end
Loading

Reviews (6): Last reviewed commit: "fix(onedrive): reuse shared assertGraphN..." | Re-trigger Greptile

Comment thread apps/sim/tools/onedrive/search.ts
Comment thread apps/sim/tools/onedrive/create_share_link.ts Outdated
…ink type

- encodeURIComponent doesn't escape single quotes, breaking the OData
  string literal for filenames containing an apostrophe
- clarify create_share_link's linkType description to include 'embed',
  which the block UI already exposes as a valid option
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/onedrive/create_share_link.ts
Comment thread apps/sim/tools/onedrive/search.ts
- add pageToken param that follows the @odata.nextLink continuation
  URL directly, so nextPageToken output is actually consumable
  instead of a dead end
- wire pageToken through the block as an advanced-mode field on the
  search operation
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/onedrive/search.ts
pageToken was used verbatim as the request URL with no host
validation, while the Authorization header is always attached —
a crafted pageToken pointing at an attacker-controlled host would
leak the OAuth access token. Pin the continuation URL to
graph.microsoft.com before using it.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/onedrive/search.ts Outdated
…oadUrl selection

- upload/create_folder/list all read params.folderSelector/manualFolderId, but
  the block only ever sends folderId — folder targeting silently fell back to
  drive root. Consolidate to a single folderId param matching what the block
  sends (same pattern already used for destinationFolderId on move/copy)
- search's percent-encode-then-replace('%27') "escape" is undone by Graph's
  standard URL-decode-before-parse, so an apostrophe in a query still breaks
  the OData string literal; list's $filter had no escaping at all. Both now
  double literal quotes (the correct OData V4 escape) via a shared
  escapeODataStringLiteral helper before encoding
- get_item/list/search all omitted @microsoft.graph.downloadUrl from $select,
  so webContentLink was always undefined on their outputs; added it
- list gains the same pageToken continuation support search already has, and
  the block's Page Token field is now shown for both operations
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/tools/onedrive/list.ts Outdated
…idation

Hostname-only check let http://graph.microsoft.com/... continuation tokens
through, which would send the Bearer token over cleartext. Sibling Graph
integrations (sharepoint, microsoft_teams, microsoft_planner, microsoft_ad)
already share assertGraphNextPageUrl/getGraphNextPageUrl in
tools/sharepoint/utils.ts, which checks the full origin (scheme + host).
Reuse it in list/search instead of hand-rolling the check twice.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile review

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5584abe. Configure here.

@waleedlatif1 waleedlatif1 merged commit 0134a5b into staging Jul 7, 2026
18 checks passed
@waleedlatif1 waleedlatif1 deleted the validate/onedrive-integration branch July 7, 2026 19:23
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.

1 participant