Class UploadMcpTool

java.lang.Object
io.meeds.mcp.server.tool.UploadMcpTool
All Implemented Interfaces:
io.meeds.mcp.server.plugin.McpToolPlugin

@Service public class UploadMcpTool extends Object implements io.meeds.mcp.server.plugin.McpToolPlugin
Lets an agent send a file from its own machine to the platform without passing the bytes through the conversation: start_upload opens a one-time upload link on the platform's upload endpoint, the agent sends the file with the returned curl command, and passes the returned upload_id to the tool that consumes the file, which reads it through the owner-checked accessor of UploadService and removes it.

Pending uploads: a link unused within its validity is dropped by the platform; an uploaded file no tool consumes is removed when the HTTP session of the upload request expires (the container's session timeout). Both live in this server node's memory and disk only. The number a user may hold pending is not bounded here: each link is one call, approved by the user when the caller's token carries the approval scope, and each file is at most the upload limit; the platform's upload registry exposes no per-user count to bound it with.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final long
    The upload limit, in MB, when no property sets a positive one.
    static final String
    What remains when the link cannot be used.
    static final String
    What the caller does once the link is open.
    static final String
    The placeholder of the curl command the caller replaces with the file's path.
    static final String
    The upload endpoint the token is presented to, from the platform's base URL.

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

    DEFAULT_LIMIT, DEFAULT_OFFSET
  • Constructor Summary

    Constructors
    Constructor
    Description
    UploadMcpTool(org.exoplatform.upload.UploadService uploadService, String maxSizeInMB)
    Builds the tool over the platform upload registry.
  • Method Summary

    Modifier and Type
    Method
    Description
    getUpload(String uploadId)
    Tells where an upload of the current user stands on this server node.
    startUpload(String name, Long size)
    Opens a one-time upload link for a file of the current user: generates an unguessable upload id, has the platform issue a token bound to the user, that id and the declared size, and returns the ready curl command that sends the file.

    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
  • Field Details

    • UPLOAD_PATH

      public static final String UPLOAD_PATH
      The upload endpoint the token is presented to, from the platform's base URL.
      See Also:
    • DEFAULT_MAX_SIZE_IN_MB

      public static final long DEFAULT_MAX_SIZE_IN_MB
      The upload limit, in MB, when no property sets a positive one.
      See Also:
    • PATH_PLACEHOLDER

      public static final String PATH_PLACEHOLDER
      The placeholder of the curl command the caller replaces with the file's path.
      See Also:
    • NEXT_STEP

      public static final String NEXT_STEP
      What the caller does once the link is open.
      See Also:
    • FALLBACK

      public static final String FALLBACK
      What remains when the link cannot be used.
      See Also:
  • Constructor Details

    • UploadMcpTool

      public UploadMcpTool(org.exoplatform.upload.UploadService uploadService, @Value("${meeds.mcp.upload.maxSizeInMB:${exo.uploadLimit:200}}") String maxSizeInMB)
      Builds the tool over the platform upload registry.
      Parameters:
      uploadService - the platform upload registry the link registers into
      maxSizeInMB - the largest file a link accepts, in MB: the meeds.mcp.upload.maxSizeInMB property, else the platform's upload limit exo.uploadLimit, which the token's size replaces for its upload, else 200L when blank, not a number or not positive (an exo.uploadLimit of 0, unlimited for the platform, gives a link that default)
  • Method Details

    • startUpload

      public UploadLinkModel startUpload(String name, Long size)
      Opens a one-time upload link for a file of the current user: generates an unguessable upload id, has the platform issue a token bound to the user, that id and the declared size, and returns the ready curl command that sends the file.
      Parameters:
      name - the file name, extension included, without path or quotes
      size - the file's size in bytes, positive and at most the upload limit
      Returns:
      the upload id, the upload URL, the curl command, the link's validity and the next step
      Throws:
      IllegalArgumentException - when the name or the size is refused
    • getUpload

      public UploadStatusModel getUpload(String uploadId)
      Tells where an upload of the current user stands on this server node.
      Parameters:
      uploadId - the upload id start_upload returned
      Returns:
      its status, size, file name and mime type, or the unknown status when this node holds no such upload for the user
      Throws:
      IllegalArgumentException - when the upload id is blank