Class OnlyofficeMcpTool
- All Implemented Interfaces:
io.meeds.mcp.server.plugin.McpToolPlugin
document_id) and MODIFY (a document_id is given, saved
back as a new version) native office files through the ONLYOFFICE Document
Server Document Builder:
edit_spreadsheet→ xlsxedit_presentation→ pptxedit_document→ docx
generate_document (template + search/replace merge),
convert_document (format→format), export_document_as_pdf
and get_document_editor_link.
Every method acts as the current user: source / target JCR nodes are resolved
through a user SessionProvider (built from the user's ACL identity),
so document ACLs are enforced. The Document Builder script and its assets are
run through the shared, security-critical
OnlyofficeEditorService.runDocBuilderScript(String, Map, String, String, String) primitive (see its javadoc
for the trust model). A null/empty Document Server result is always
translated into an LLM-directed IllegalStateException.
operations argument. The nested operations array is accepted as a JSON
string (a JSON array of {"type":...} objects) because the MCP
argument binder does not reliably bind a nested array; it is parsed
server-side.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final classHolds a userSessionProviderand its openedSession; closing it releases the provider. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringName of theSpaceScopeResolverthat tells the space of a document node.static final StringIn-app preview URL of a stored file (same shape as the Documents add-on).Fields inherited from interface io.meeds.mcp.server.plugin.McpToolPlugin
DEFAULT_LIMIT, DEFAULT_OFFSET -
Constructor Summary
ConstructorsConstructorDescriptionOnlyofficeMcpTool(OnlyofficeEditorService onlyofficeEditorService, org.exoplatform.documents.service.DocumentFileService documentFileService, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.portal.config.UserACL userAcl, org.exoplatform.services.jcr.RepositoryService repositoryService, org.exoplatform.upload.UploadService uploadService, org.exoplatform.social.attachment.AttachmentService attachmentService, org.exoplatform.commons.file.services.FileService fileService, org.springframework.beans.factory.ObjectProvider<io.meeds.mcp.server.plugin.SpaceScopeResolver> spaceScopeResolvers) -
Method Summary
Modifier and TypeMethodDescriptionconvertDocument(String documentId, String targetFormat, String folderId) Converts an existing office document to another format using the ONLYOFFICE Document Server, storing the result as<originalName>.<target_format>.editDocument(String documentId, String parentFolderId, String name, String operations, String attachmentObjectType, String attachmentObjectId) Creates or modifies a text document (docx).editPresentation(String documentId, String parentFolderId, String name, String operations, String attachmentObjectType, String attachmentObjectId) Creates or modifies a presentation (pptx).editSpreadsheet(String documentId, String parentFolderId, String name, String operations) Creates or modifies a spreadsheet (xlsx).exportDocumentAsPdf(String documentId, String parentFolderId) Exports an existing office document as a PDF, stored as<name>.pdf.generateDocument(String templateDocumentId, String folderId, String name, String data) Generates a new document from a template by replacing every placeholder with its value (a search/replace merge run through the Document Builder).getDocumentEditorLink(String documentId) Returns the ONLYOFFICE online editor URL of a document, so it can be opened for editing.protected LonggetSpreadsheetCells(String documentId, String sheet, String range) Reads the cells of a range of one sheet of a spreadsheet the user can read, each with its A1 position, its value and its formula, plus the list of the workbook's sheets, so a grid can be filled back in its own format withedit_spreadsheet.protected booleanprotected StringmaterializeUpload(byte[] zipBytes, String zipName) protected OnlyofficeMcpTool.UserSessionprotected voidreleaseUpload(String uploadId) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface io.meeds.mcp.server.plugin.McpToolPlugin
getCurrentUserAclIdentity, getCurrentUserLocale, getCurrentUserLocale, getCurrentUserName, getLocale
-
Field Details
-
FILE_URL_FORMAT
In-app preview URL of a stored file (same shape as the Documents add-on).- See Also:
-
DOCUMENT_RESOLVER
Name of theSpaceScopeResolverthat tells the space of a document node.- See Also:
-
-
Constructor Details
-
OnlyofficeMcpTool
public OnlyofficeMcpTool(OnlyofficeEditorService onlyofficeEditorService, org.exoplatform.documents.service.DocumentFileService documentFileService, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.portal.config.UserACL userAcl, org.exoplatform.services.jcr.RepositoryService repositoryService, org.exoplatform.upload.UploadService uploadService, org.exoplatform.social.attachment.AttachmentService attachmentService, org.exoplatform.commons.file.services.FileService fileService, org.springframework.beans.factory.ObjectProvider<io.meeds.mcp.server.plugin.SpaceScopeResolver> spaceScopeResolvers) - Parameters:
onlyofficeEditorService- the ONLYOFFICE editor servicedocumentFileService- reads the documentsidentityManager- the social identity manageruserAcl- the user ACL, to build the user's JCR sessionrepositoryService- the JCR repository serviceuploadService- the upload serviceattachmentService- the attachment servicefileService- the file servicespaceScopeResolvers- the resolvers contributed to the MCP server, among which the "document" one tells the space of an image node
-
-
Method Details
-
editSpreadsheet
public OfficeDocumentModel editSpreadsheet(String documentId, String parentFolderId, String name, String operations) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Creates or modifies a spreadsheet (xlsx). Passdocument_idto MODIFY an existing spreadsheet (saved back as a new version), orparent_folder_idandnameto CREATE a new one. Theoperationsare applied via the ONLYOFFICE Document Builder.Supported operations (a JSON array string):
{"type":"set_cells","start":"A1","values":[["Region","Sales"],["North",120]]}{"type":"set_formula","cell":"B4","formula":"=SUM(B2:B3)"}{"type":"add_chart","chart":"bar|line|pie","range":"Sheet1!$A$1:$B$3","title":"..."}{"type":"add_sheet","name":"Q3"}(subsequent ops target the new sheet)
- Parameters:
documentId- optional JCR uuid of an existing spreadsheet to modifyparentFolderId- folder id where a new spreadsheet is created (create mode)name- new spreadsheet name WITHOUT extension (create mode)operations- a JSON array string of spreadsheet operations- Returns:
- the created / modified document (id + name)
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
editPresentation
public OfficeDocumentModel editPresentation(String documentId, String parentFolderId, String name, String operations, String attachmentObjectType, String attachmentObjectId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Creates or modifies a presentation (pptx). Passdocument_idto MODIFY (saved back as a new version) orparent_folder_id+nameto CREATE.Supported operations (a JSON array string):
{"type":"add_slide","layout":"title|content|closing","title":"...","bullets":["a","b"]}{"type":"set_slide","index":0,"title":"...","bullets":[...]}(replaces the slide content){"type":"add_image","slide":1,"url":"https://.../pic.png"}or{"type":"add_image","slide":1,"document_id":"<uuid>"}
When the user attaches an image in the EVA chat, the agent injects the chat-attachment reference into the top-level
attachmentObjectType/attachmentObjectIdparameters; anyadd_imageoperation that has neitherurlnordocument_idthen resolves its bytes from that attachment (seeresolveImageBytes(JSONObject, Session, String, String)).- Parameters:
documentId- optional JCR uuid of an existing presentation to modifyparentFolderId- folder id where a new presentation is created (create mode)name- new presentation name WITHOUT extension (create mode)operations- a JSON array string of presentation operationsattachmentObjectType- object type of the EVA chat-attachment image source (auto-filled by the agent)attachmentObjectId- object id of the EVA chat-attachment image source (auto-filled by the agent)- Returns:
- the created / modified document (id + name)
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
editDocument
public OfficeDocumentModel editDocument(String documentId, String parentFolderId, String name, String operations, String attachmentObjectType, String attachmentObjectId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Creates or modifies a text document (docx). Passdocument_idto MODIFY (saved back as a new version) orparent_folder_id+nameto CREATE.Supported operations (a JSON array string):
{"type":"add_heading","level":1,"text":"..."}{"type":"add_paragraph","text":"...","bold":false,"italic":false}{"type":"add_table","rows":[["A","B"],["1","2"]]}{"type":"add_image","url":"https://.../pic.png"}or{"type":"add_image","document_id":"<uuid>"}{"type":"replace_text","search":"{{name}}","replace":"ACME"}{"type":"set_html","html":"<h1>..</h1>"}(CREATE only, must be the only operation; authored via the HTML conversion path, not the Builder)
When the user attaches an image in the EVA chat, the agent injects the chat-attachment reference into the top-level
attachmentObjectType/attachmentObjectIdparameters; anyadd_imageoperation that has neitherurlnordocument_idthen resolves its bytes from that attachment (seeresolveImageBytes(JSONObject, Session, String, String)).- Parameters:
documentId- optional JCR uuid of an existing document to modifyparentFolderId- folder id where a new document is created (create mode)name- new document name WITHOUT extension (create mode)operations- a JSON array string of document operationsattachmentObjectType- object type of the EVA chat-attachment image source (auto-filled by the agent)attachmentObjectId- object id of the EVA chat-attachment image source (auto-filled by the agent)- Returns:
- the created / modified document (id + name)
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
isSpaceScoped
protected boolean isSpaceScoped()- Returns:
- true when the current call is limited to a space; also true when its identity can't be read, which a limited call must never be taken for the opposite of
-
getSpaceScope
- Returns:
- the id of the space the current call is limited to, or null when it isn't limited or its identity can't be read
-
generateDocument
public OfficeDocumentModel generateDocument(String templateDocumentId, String folderId, String name, String data) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Generates a new document from a template by replacing every placeholder with its value (a search/replace merge run through the Document Builder). Unlikeedit_document'sreplace_text(which edits a document in place for one-off substitutions), this is the template-fill workflow: it always CREATES a new file from a template document and takes the whole placeholder map at once.- Parameters:
templateDocumentId- the JCR uuid of the template document (e.g. a docx with{{client}}placeholders)folderId- optional destination folder; defaults to the template's foldername- the produced document name WITHOUT extension; defaults to the template namedata- a JSON object string mapping each placeholder to its replacement, e.g.{"{{client}}":"ACME","{{amount}}":"42,000 EUR"}- Returns:
- the generated document (id + name)
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
convertDocument
public OfficeDocumentModel convertDocument(String documentId, String targetFormat, String folderId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Converts an existing office document to another format using the ONLYOFFICE Document Server, storing the result as<originalName>.<target_format>.- Parameters:
documentId- the JCR uuid of the source documenttargetFormat- the produced format, e.g. docx, xlsx, pptx, odt, pdf, csvfolderId- optional destination folder; defaults to the source folder- Returns:
- the created document (id + name)
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
exportDocumentAsPdf
public OfficeDocumentModel exportDocumentAsPdf(String documentId, String parentFolderId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Exports an existing office document as a PDF, stored as<name>.pdf.- Parameters:
documentId- the JCR uuid of the source documentparentFolderId- optional destination folder; defaults to the source folder- Returns:
- the created PDF document (id + name)
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
getDocumentEditorLink
public OfficeEditorLinkModel getDocumentEditorLink(String documentId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Returns the ONLYOFFICE online editor URL of a document, so it can be opened for editing. The user must have edit permission on the document.- Parameters:
documentId- the JCR uuid of the document- Returns:
- the document id, name and editor URL
- Throws:
IllegalAccessExceptionorg.exoplatform.commons.exception.ObjectNotFoundException
-
getSpreadsheetCells
public SpreadsheetCellsModel getSpreadsheetCells(String documentId, String sheet, String range) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException Reads the cells of a range of one sheet of a spreadsheet the user can read, each with its A1 position, its value and its formula, plus the list of the workbook's sheets, so a grid can be filled back in its own format withedit_spreadsheet. Read from the file as stored: a formula's value is the one computed when the file was last saved.- Parameters:
documentId- the JCR uuid of the spreadsheetsheet- the sheet to read, blank for the active onerange- the range in A1 notation, blank for the sheet's used range- Returns:
- the sheets and the non-empty cells of the range
- Throws:
IllegalAccessException- when the user can't read the documentorg.exoplatform.commons.exception.ObjectNotFoundException- when the document doesn't exist
-
openUserSession
-
materializeUpload
-
releaseUpload
-