Repository navigation
Add SharePoint file content tool and Sites.Selected setup - #1817
Merged
Merged
Conversation
Add sharepoint_get_file_content (GET /drives/{drive_id}/items/{item_id}/content,
optional format=pdf): text files come back as text capped at 200 KB, other
files as an attachment up to 10 MB through the binary response mapping.
Document how to restrict the connector to selected sites with the delegated
Sites.Selected permission, and test the connection with /me, which answers
under every scope set, instead of /sites/root.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some organisations want the SharePoint connector to see only a few sites, not every site the signed-in user can open. Microsoft Graph supports this with the delegated
Sites.Selectedpermission plus a per-site grant for the app. This PR documents that setup and removes the one thing that broke under it (the connection test called/sites/root, which returns 403 unless the root site is granted).The AI also could not read a file's content at all, only metadata and
webUrl. The newsharepoint_get_file_contenttool uses the existing binary response handling (as the Word, PowerPoint and Moss adapters already do), so this is now possible with the 10 MB cap the old note said was missing.Behaviour is identical on Cloud and self-hosted: the change is adapter JSON only, and the binary response handling, response limits and redirect handling are shared code with no deployment-mode branch.
Changes
sharepoint_get_file_content:GET /drives/{drive_id}/items/{item_id}/content, optionalformat(enumpdf, Graph's conversion for Office and other formats, files up to 2 MB per the Graph docs).responseMapping.binary.maxBytes10485760 (PDFs, images, other files are attached), plustransform{ expression: "@", maxBytes: 200000 }, which only applies to text bodies (txt/csv/md/json...) so a large text file is cut and marked_truncatedinstead of filling the context. Binary bodies skip the transform (dynamic-mcp-tools.ts). Read-only via the derived GET annotation, enabled at install.connector.healthcheckPath:/sites/rootchanged to/me(works withUser.Readunder any scope set).probeis left onsharepoint_get_root_site. A probe must name a tool, and there is no/metool. It is also never run for this adapter: for an OAUTH2 connector authorized in the browser,runImportProbereturns null andverifyCredentialsreturnsskipped: 'authorization'(adapters.service.ts). So changing it would mean adding a tool without changing any behaviour.offline_access User.Read Sites.Selected(not the shared Outlook app, because the token carries every consented Graph scope), admin consent, the per-site grant via GraphPOST /v1.0/sites/{siteId}/permissionsor PnPGrant-PnPEntraIDAppSitePermission,writegrants for write tools, setting OAuth Scopes and re-authorizing, disablingsharepoint_get_root_site/sharepoint_search_sites/sharepoint_search, entering sites withsharepoint_get_site_by_path, and that effective access is the intersection of the user's rights and the site grant. Also updated: the sentence that said the connector does not download file content, the out-of-scope paragraph, the 403 error line, the403verify hint, and the adapter description ("read files").formatquery param only when given, binary and transform mapping, read-only, enabled),healthcheckPath/me, the Sites.Selected section, and the/contentmethod guard now allows the one GET.Redirect handling (verified in code): Graph answers
/contentwith a 302 to a pre-authenticated download URL on another host. The REST engine sends throughoutboundRequest(common/outbound-http.ts), which follows redirects itself (maxRedirects: 0on the client, up to 5 hops, SSRF check on every hop). InredirectedConfig, when the target origin differs (keepsCredentialsfalse), it deletesAuthorization,Cookie,Proxy-Authorization, Basic auth, any credential-named header and the engine'scredentialHeaders. So the bearer token is not forwarded to the download host. This is covered by the existing tests inoutbound-http.spec.ts("drops credential headers and Basic auth when the redirect leaves the origin").maxContentLength(tool response limit, default 10 MB) applies to every hop.Type
Testing
Commands and results (macOS, Node 22):
node scripts/validate-adapters.mjs --warntool-prefixforsharepoint_get_file_content(not prefixedmicrosoft_sharepoint_). It is the same rule all 29 existing SharePoint tools already hit; the adapter usessharepoint_and its spec pins that prefix.node scripts/regenerate-catalog.mjscatalog.tsnode scripts/adapter-count.mjs --checkOK: every quoted count equals 957 adapters (51 keyless, 20016 tools); tool counts are not quoted in checked filespackages/backendnpx prisma generate(dummyDATABASE_URL)packages/backendnpx jest --maxWorkers=4 src/adapters/intl/microsoft-sharepoint src/adapters/catalogpackages/backendnpx jest --maxWorkers=4 'src/adapters/[^/]+\.spec\.ts$'packages/backendnpx tsc --noEmit -p tsconfig.jsonpackages/backendnpm run lintNot verified (no tenant available): no live call against a real Microsoft 365 tenant. Specifically untested:
/contentand?format=pdfend to end through the 302.Sites.Selectedcovers/drives/{id}/items/{id}/content. The conversion docs listFiles.ReadandSites.Read.All, notSites.Selected.sharepoint_search_sitesandsharepoint_searchfail underSites.Selected..md/.csv. Non-text-typed UTF-8 bodies are still decoded as text bydecodeResponseBody.The live block of the spec (
MS_GRAPH_ACCESS_TOKEN=...) was not run.Checklist
npm test): the adapter and catalog suites above; full suite runs in CIRelated Issues
None.