fix: cap Base64 media transfers at 10 MB, upload limit at most 32 MB

This commit is contained in:
2026-09-26 05:04:38 +02:00
parent 7f58301a71
commit 28bb033a8b
12 changed files with 122 additions and 25 deletions
@@ -13,8 +13,9 @@ use WP_Error;
* Delivers a media file (original or a named image size) as an MCP embedded resource
* (spec §4.3). Direct tool: like ImageContent (lit-media-preview), an embedded resource
* is only turned into a content block by mcp-adapter for a tool called directly, never
* via mcp-adapter-execute-ability (ruling Q6). Files above the upload limit (Limits) are
* refused; the caller falls back to the URL.
* via mcp-adapter-execute-ability (ruling Q6). The whole file is read into memory and sent
* as Base64, so files above Limits::inlineBytes() (upload limit, at most 10 MB) are refused;
* the caller falls back to the file URL.
*/
final class MediaDownloadAbility implements Ability
{
@@ -35,7 +36,8 @@ final class MediaDownloadAbility implements Ability
public function description(): string
{
return 'Liefert eine Datei der Mediathek (Original oder Bildgröße, siehe sizes in lit/media-get) als '
. 'eingebettete Ressource. Dateien über dem Upload-Limit werden nicht übertragen; dann die URL nutzen.';
. 'eingebettete Ressource. Dateien über dem Upload-Limit (höchstens 10 MB) werden nicht übertragen; '
. 'dann die Datei-URL nutzen.';
}
public function inputSchema(): array
@@ -103,14 +105,14 @@ final class MediaDownloadAbility implements Ability
}
$bytesOnDisk = (int) filesize($path);
if ($bytesOnDisk > $this->limits->uploadBytes()) {
if ($bytesOnDisk > $this->limits->inlineBytes()) {
return Errors::unsupported(
sprintf(
'Die Datei ist zu groß für die Übertragung (%.1f MB, Limit %d MB).',
$bytesOnDisk / 1048576,
$this->limits->uploadMegabytes()
$this->limits->inlineMegabytes()
),
'Kleinere Bildgröße (size) wählen oder die URL aus lit/media-get verwenden.'
'Die Datei-URL (url aus lit/media-get) verwenden oder eine kleinere Bildgröße (size) wählen.'
);
}