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
FieldsModifier and TypeFieldDescriptionstatic final longThe upload limit, in MB, when no property sets a positive one.static final StringWhat remains when the link cannot be used.static final StringWhat the caller does once the link is open.static final StringThe placeholder of the curl command the caller replaces with the file's path.static final StringThe 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
ConstructorsConstructorDescriptionUploadMcpTool(org.exoplatform.upload.UploadService uploadService, String maxSizeInMB) Builds the tool over the platform upload registry. -
Method Summary
Modifier and TypeMethodDescriptionTells 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, waitMethods inherited from interface io.meeds.mcp.server.plugin.McpToolPlugin
getCurrentUserAclIdentity, getCurrentUserLocale, getCurrentUserLocale, getCurrentUserName, getLocale
-
Field Details
-
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_MBThe upload limit, in MB, when no property sets a positive one.- See Also:
-
PATH_PLACEHOLDER
The placeholder of the curl command the caller replaces with the file's path.- See Also:
-
NEXT_STEP
-
FALLBACK
-
-
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 intomaxSizeInMB- the largest file a link accepts, in MB: themeeds.mcp.upload.maxSizeInMBproperty, else the platform's upload limitexo.uploadLimit, which the token's size replaces for its upload, else 200L when blank, not a number or not positive (anexo.uploadLimitof 0, unlimited for the platform, gives a link that default)
-
-
Method Details
-
startUpload
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 quotessize- 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
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
unknownstatus when this node holds no such upload for the user - Throws:
IllegalArgumentException- when the upload id is blank
-