Class NoteMcpTool

java.lang.Object
io.meeds.notes.mcp.NoteMcpTool
All Implemented Interfaces:
io.meeds.mcp.server.plugin.McpToolPlugin

@Service @Profile("mcp-server") public class NoteMcpTool extends Object implements io.meeds.mcp.server.plugin.McpToolPlugin
  • Field Summary

    Fields inherited from interface io.meeds.mcp.server.plugin.McpToolPlugin

    DEFAULT_LIMIT, DEFAULT_OFFSET
  • Constructor Summary

    Constructors
    Constructor
    Description
    NoteMcpTool(WikiService wikiService, NoteService noteService, org.exoplatform.social.core.manager.ActivityManager activityManager, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.social.core.processor.I18NActivityProcessor i18NActivityProcessor, org.exoplatform.social.core.space.spi.SpaceService spaceService, io.meeds.social.translation.service.TranslationService translationService, org.exoplatform.social.core.profileproperty.ProfilePropertyService profilePropertyService, org.exoplatform.portal.config.UserACL userAcl, org.exoplatform.portal.config.UserPortalConfigService portalConfigService, io.meeds.portal.permlink.service.PermanentLinkService permanentLinkService, org.exoplatform.upload.UploadService uploadService, org.exoplatform.social.attachment.AttachmentService attachmentService, org.exoplatform.commons.file.services.FileService fileService, org.exoplatform.portal.mop.service.LayoutService layoutService, org.springframework.beans.factory.ObjectProvider<NotePublicationPlugin> publicationPlugins)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    createChildNote(Long parentNoteId, String title, String summary, String htmlContent)
    Creates a note as a child of an existing note, in the same notebook (space or personal) as its parent, as the current user.
    createPersonalNote(String title, String summary, String htmlContent)
    Creates a note in the calling user's own (personal) notebook, at its root.
    createSpaceNote(Long spaceId, String title, String summary, String htmlContent)
    Creates a note at the root of a space's notebook, as the current user.
    void
    deleteNote(long noteId)
     
    getNote(long noteId, String language, Long offset, Integer maxChars, Long versionNumber)
    Reads a note as the current user: its current content, or one version of its history, whole or part by part.
    getNoteTranslations(long noteId)
    Lists the language codes a note has translations for (e.g.
    getNoteVersions(long noteId, String language, Integer offset, Integer limit)
    Lists a page of the version history of a note, newest first: each version's number, id, title, date and author, without its content, which get_note reads with the version's number.
    protected Long
     
    getSpaceNoteTree(long spaceId)
     
    void
    moveNote(long noteId, long targetParentNoteId)
    Moves a note under another note, both editable by the current user.
    io.meeds.mcp.server.tool.model.ActivityModel
    publishNote(long noteId)
     
    removeNoteCover(long noteId, String language)
    Removes a note's cover ("featured") image.
    removeNoteTranslation(long noteId, String language)
    Removes ONE language's translation of a note, leaving the note's original content and its other translations intact.
    restoreNoteVersion(long noteId, long versionNumber, String language)
    Restores a note to a previous version identified by its version_number (from get_note_versions), creating a new current version from it.
    searchNotes(String query, Long spaceId, Integer offset, Integer limit, Boolean isFavorites)
    Full-text search over the notes the current user can read.
    setNoteCover(long noteId, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String altText, String language, String uploadId)
    Sets a note's cover ("featured") image from exactly one of a public http(s) URL, base64 bytes, an ACL-checked reference to an existing platform attachment, or one of the user's uploads sent through an upload link.
    setNoteSummary(long noteId, String summary, String language)
    Sets (or replaces) a note's summary — the short excerpt shown on note cards.
    updateNote(long noteId, String title, String htmlContent, String language)
    Updates a note's title and content, or one translation's, as the current user, and publishes the result as a new version.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.meeds.mcp.server.plugin.McpToolPlugin

    getCurrentUserAclIdentity, getCurrentUserLocale, getCurrentUserLocale, getCurrentUserName, getLocale
  • Constructor Details

    • NoteMcpTool

      public NoteMcpTool(WikiService wikiService, NoteService noteService, org.exoplatform.social.core.manager.ActivityManager activityManager, org.exoplatform.social.core.manager.IdentityManager identityManager, org.exoplatform.social.core.processor.I18NActivityProcessor i18NActivityProcessor, org.exoplatform.social.core.space.spi.SpaceService spaceService, io.meeds.social.translation.service.TranslationService translationService, org.exoplatform.social.core.profileproperty.ProfilePropertyService profilePropertyService, org.exoplatform.portal.config.UserACL userAcl, org.exoplatform.portal.config.UserPortalConfigService portalConfigService, io.meeds.portal.permlink.service.PermanentLinkService permanentLinkService, org.exoplatform.upload.UploadService uploadService, org.exoplatform.social.attachment.AttachmentService attachmentService, org.exoplatform.commons.file.services.FileService fileService, org.exoplatform.portal.mop.service.LayoutService layoutService, org.springframework.beans.factory.ObjectProvider<NotePublicationPlugin> publicationPlugins)
  • Method Details

    • getScopeSpaceId

      protected Long getScopeSpaceId()
      Returns:
      the space the current call is limited to, null when it isn't
      Throws:
      IllegalStateException - when the call's identity can't be read
    • getSpaceNoteTree

      public NoteRootTreeModel getSpaceNoteTree(long spaceId) throws org.exoplatform.commons.exception.ObjectNotFoundException, IllegalAccessException
      Throws:
      org.exoplatform.commons.exception.ObjectNotFoundException
      IllegalAccessException
    • getNote

      public NoteModel getNote(long noteId, String language, Long offset, Integer maxChars, Long versionNumber) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Reads a note as the current user: its current content, or one version of its history, whole or part by part. Without offset nor max_chars the whole HTML content is returned. With either, at most max_chars characters of the HTML content are returned from offset, cut where no tag, character reference or surrogate pair is split, with the content's total length and where the next part starts. A part of the current note also carries the number of the published version it was cut from, when that version is the one read: passed back as versionNumber, it pins the next parts to that version even if the note is edited between two calls.

      A version read returns the version's title, content, update date and last updater, with the current note's summary, url, breadcrumb and can_edit. The version is found in the history of getVersionsHistoryOfNoteByLang, which, on a note's default language with no history yet, records the current note as its first version.

      Parameters:
      noteId - the note id
      language - the translation to read, null or blank for the default
      offset - the first character of the HTML content to read, from 0, as next_offset gives it; null to read from the start
      maxChars - the most characters of the part, 40000 when null, clamped to 1 and 200000; null with a null offset to read the whole content
      versionNumber - the number of the version to read, from get_note_versions; null for the current note
      Returns:
      the note, or the part of it read
      Throws:
      IllegalAccessException - when the user can't view the note
      org.exoplatform.commons.exception.ObjectNotFoundException - when the note, or the version, doesn't exist
    • getNoteTranslations

      public List<String> getNoteTranslations(long noteId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Lists the language codes a note has translations for (e.g. ["en", "fr"]). The default (untranslated) content is what get_note returns without a language; an empty list means the note has only its default content. Read as the current user, so the note's ACL is enforced. Read-only.
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • removeNoteTranslation

      public NoteModel removeNoteTranslation(long noteId, String language) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Removes ONE language's translation of a note, leaving the note's original content and its other translations intact. Only a user who can edit the note may remove a translation. To delete the whole note (its original content and every translation) use delete_note instead.
      Parameters:
      noteId - the note id
      language - the language of the translation to remove
      Returns:
      the note's default version, read back as the current user
      Throws:
      IllegalAccessException - when the user can't edit the note
      org.exoplatform.commons.exception.ObjectNotFoundException - when the note, or that translation, doesn't exist
    • createSpaceNote

      public NoteModel createSpaceNote(Long spaceId, String title, String summary, String htmlContent) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates a note at the root of a space's notebook, as the current user. The space's notebook is created on first use. The Notes service enforces the space ACL (the user must be allowed to redact or publish in the space).
      Parameters:
      spaceId - id of the space whose notebook receives the note
      title - title of the note
      summary - optional plain-text summary shown on note cards
      htmlContent - body of the note, HTML or markdown
      Returns:
      the created note, read back as the current user
      Throws:
      IllegalAccessException - when the user can't access the space or add notes to it
      org.exoplatform.commons.exception.ObjectNotFoundException - when the space doesn't exist
    • createPersonalNote

      public NoteModel createPersonalNote(String title, String summary, String htmlContent) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates a note in the calling user's own (personal) notebook, at its root. The notebook is resolved from the authenticated user only, never from the tool arguments, so a caller can't target someone else's notebook; it is created on first use, as the Notes REST layer does. The Notes service then re-checks that the user manages that notebook (a personal notebook is only managed by its owner).
      Parameters:
      title - title of the note
      summary - optional plain-text summary shown on note cards
      htmlContent - body of the note, HTML or markdown
      Returns:
      the created note, read back as the current user
      Throws:
      IllegalAccessException - when there is no authenticated user, or the user isn't allowed to add notes to that notebook
      org.exoplatform.commons.exception.ObjectNotFoundException - when the notebook has no home note
    • createChildNote

      public NoteModel createChildNote(Long parentNoteId, String title, String summary, String htmlContent) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Creates a note as a child of an existing note, in the same notebook (space or personal) as its parent, as the current user.
      Parameters:
      parentNoteId - id of the note under which the new note is created
      title - title of the note
      summary - optional plain-text summary shown on note cards
      htmlContent - body of the note, HTML or markdown
      Returns:
      the created note, read back as the current user
      Throws:
      IllegalAccessException - when the user can't view the parent note or add notes to its notebook
      org.exoplatform.commons.exception.ObjectNotFoundException - when the parent note doesn't exist
    • updateNote

      public NoteModel updateNote(long noteId, String title, String htmlContent, String language) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Updates a note's title and content, or one translation's, as the current user, and publishes the result as a new version.
      Parameters:
      noteId - the note id
      title - the new title, blank to keep it
      htmlContent - the new content, HTML or markdown, blank to keep it
      language - the translation to write, null or blank for the default
      Returns:
      the version just written, read back as the current user
      Throws:
      IllegalAccessException - when the user can't edit the note
      org.exoplatform.commons.exception.ObjectNotFoundException - when the note doesn't exist
    • publishNote

      public io.meeds.mcp.server.tool.model.ActivityModel publishNote(long noteId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • deleteNote

      public void deleteNote(long noteId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • moveNote

      public void moveNote(long noteId, long targetParentNoteId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Moves a note under another note, both editable by the current user. In a call limited to a space, the new parent must belong to that space: the space scope checks the moved note only, and the new parent would otherwise carry the note to another space's notebook or a personal one. The note service refuses a new parent the user can't edit, and one that is the note itself or one of its sub-notes.
      Parameters:
      noteId - the note to move
      targetParentNoteId - the note that becomes its parent
      Throws:
      IllegalAccessException - when the current user can't edit either note, or, in a call limited to a space, the new parent belongs to another space or none, or the call's identity can't be read
      org.exoplatform.commons.exception.ObjectNotFoundException - when either note doesn't exist
      IllegalArgumentException - when the new parent is the note itself or one of its sub-notes
    • searchNotes

      public NoteSearchCollectionModel searchNotes(String query, Long spaceId, Integer offset, Integer limit, Boolean isFavorites)
      Full-text search over the notes the current user can read. A blank query lists the most recently updated notes first; a non-blank query is passed as typed and keeps the relevance order. Each hit is compact, without the note's content: get_note reads it. One more hit than the limit is asked for, to tell whether another page follows. Paging stops at the first 10000 hits, the most the search engine pages through: the offset is clamped so that the page ends within them, and no next page is offered past them.
      Parameters:
      query - the words to search for, blank to list the latest notes
      spaceId - the space whose notebook to search, null to search everywhere
      offset - the hits to skip, 0 when null, clamped to 0 and 10000 minus the limit and one
      limit - the most hits, 10 when null or 0, clamped to 1 and 100
      isFavorites - true to search the current user's favorite notes only
      Returns:
      the page of hits, with whether more follow and where
    • getNoteVersions

      public NoteVersionCollectionModel getNoteVersions(long noteId, String language, Integer offset, Integer limit) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Lists a page of the version history of a note, newest first: each version's number, id, title, date and author, without its content, which get_note reads with the version's number. The history is sorted by version number here, since the service returns it in no stated order, so the pages neither skip nor repeat a version. Read as the current user, so the note's ACL is enforced. Read-only.
      Parameters:
      noteId - the note id
      language - the translation whose history to list, null or blank for the default
      offset - the versions to skip, 0 when null
      limit - the most versions, 10 when null or 0, clamped to 1 and 100
      Returns:
      the page of versions, with whether more follow and where
      Throws:
      IllegalAccessException - when the user can't view the note
      org.exoplatform.commons.exception.ObjectNotFoundException - when the note doesn't exist
    • restoreNoteVersion

      public NoteModel restoreNoteVersion(long noteId, long versionNumber, String language) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Restores a note to a previous version identified by its version_number (from get_note_versions), creating a new current version from it. Only a user who can edit the note may restore it.
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • setNoteCover

      public NoteModel setNoteCover(long noteId, String imageUrl, String imageBase64, String attachmentObjectType, String attachmentObjectId, String altText, String language, String uploadId) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Sets a note's cover ("featured") image from exactly one of a public http(s) URL, base64 bytes, an ACL-checked reference to an existing platform attachment, or one of the user's uploads sent through an upload link. Every source is capped at UploadToolUtils.DEFAULT_MAX_BYTES and must hold a png, jpeg, gif or webp image. Only a user who can edit the note may set it. The image is wired into the note metadata so it actually renders on the note; it is staged in the platform's upload service for the metadata to read, and released on every path.
      Parameters:
      noteId - the note
      imageUrl - a public http(s) URL serving the image
      imageBase64 - the image bytes, base64-encoded
      attachmentObjectType - the type of the object holding an attached image
      attachmentObjectId - the id of the object holding an attached image
      altText - the image's alternative text
      language - the translation to target, blank for the default note
      uploadId - the id start_upload returned, once its curl command sent the image: one of the user's own uploads, consumed once read, whether the cover is set or not
      Returns:
      the note
      Throws:
      IllegalAccessException - when the user can't edit the note, or read the attachment
      org.exoplatform.commons.exception.ObjectNotFoundException - when the note, the attachment or the upload doesn't exist
    • setNoteSummary

      public NoteModel setNoteSummary(long noteId, String summary, String language) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Sets (or replaces) a note's summary — the short excerpt shown on note cards. Only a user who can edit the note may set it; the note's cover image is preserved.
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException
    • removeNoteCover

      public NoteModel removeNoteCover(long noteId, String language) throws IllegalAccessException, org.exoplatform.commons.exception.ObjectNotFoundException
      Removes a note's cover ("featured") image. Only a user who can edit the note may remove it.
      Throws:
      IllegalAccessException
      org.exoplatform.commons.exception.ObjectNotFoundException