[ADD] ms365: read shared O365 documents (Graph Shares + text extraction)#185
Open
beorngb wants to merge 8 commits into
Open
[ADD] ms365: read shared O365 documents (Graph Shares + text extraction)#185beorngb wants to merge 8 commits into
beorngb wants to merge 8 commits into
Conversation
m365_read_shared and m365_list_shared duplicated the same fragile substring-based mapping from _graph_request exceptions to actionable error messages, each with an identical NOTE comment. Extract it into a single _graph_error_message() so the format assumption is documented and maintained in one place.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Extends the ms365 MCP plugin to read Office 365 documents shared with the
account — the case the existing tools couldn't reach (they only read files by
known SharePoint
site_id + file_pathor the user's own OneDrive).New tools
m365_read_shared(sharing_url | drive_id+item_id)— reads a shared document byshare link (from email) or by an item from
m365_list_shared. Resolves via theGraph Shares API (
/shares/{shareId}/driveItem) or/drives/{id}/items/{id},then returns extracted text. Works cross-tenant with the recipient's own
delegated token — no app in the sharer's tenant needed.
m365_list_shared()— lists "Shared with me" (/me/drive/sharedWithMe),paginated (cap 200 items / 5 pages,
truncatedflag), returningdrive_id/item_idto pass tom365_read_shared.Also
plugins/ms365/extract.py:extract_text(docx/xlsx/pdf/text viapython-docx/openpyxl/pypdf) and
encode_sharing_url(Graph shareId).m365_read_file/m365_read_drive_filenow extract Office text on binarycontent instead of returning "Binary file" — text files still decode as before
(utf-8-first).
@microsoft.graph.downloadUrlwith no auth header (avoids leaking the Graphbearer to the storage host), streamed with a 50 MB size guard; folders and
missing-downloadUrl items are guarded with clear errors.
ms365pyproject extra.Only the MCP-server path (
server.py) is touched; the legacy in-process tag pathis untouched.
Tests — 35 unit tests (
tests/unit/plugins/ms365/): extraction (all formatspagination, input contract, folder/size guards, error mapping. Repo-wide unit
suite green.
Runtime prerequisite (not in this PR) — the plugin is currently unconfigured
(no Azure app client_id in its DB config), so this is not yet live-verifiable.
To enable: register/point the Azure AD app, grant the
Files.Read.Alldelegatedpermission with admin consent, re-authenticate the account(s) via the OAuth flow,
then confirm end-to-end.
Follow-ups (non-blocking)
m365_read_shareddoes not update the "current file" continuity state thatread_file/read_drive_filefeed.context.pytool docs are on the legacy path and don't reach the live MCPsystem prompt (agents learn the tools from the
Tool()schemas).openpyxl/pypdf/python-docxare duplicated between thedataandms365pyproject extras (harmless).