Web-Plattform-Integration
Übersicht
Abschnitt betitelt „Übersicht“Der MCP-Server liefert generierte Dokumente über drei Methoden:
| Methode | Auslöser | Antwortfeld | Größenlimit |
|---|---|---|---|
| Base64 (inline) | ARTIFACTS_BASE_URL nicht gesetzt |
data (base64-String) |
10 MB |
| Local URL | ARTIFACTS_BASE_URL gesetzt (stdio) |
downloadUrl + expiresAt |
Keins |
| S3 presigned URL | S3-Speicher aktiviert (HTTP) | downloadUrl + expiresAt |
Konfigurierbar |
Antwortformat
Abschnitt betitelt „Antwortformat“interface DocumentArtifact { // Base64 mode (when ARTIFACTS_BASE_URL is unset) data?: string;
// URL mode (Local URL or S3/MinIO) downloadUrl?: string; expiresAt?: string; // ISO 8601 timestamp
// Common fields size: number; mimeType: string; filename: string; deliveryMethod: 'url' | 'base64'; truncated?: boolean; truncationReason?: string;}MIME-Typen
Abschnitt betitelt „MIME-Typen“| Dokumenttyp | MIME-Typ | Erweiterung |
|---|---|---|
| Word | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.docx |
| PowerPoint | application/vnd.openxmlformats-officedocument.presentationml.presentation |
.pptx |
| Excel | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
.xlsx |
application/pdf |
.pdf |
JavaScript-Handler
Abschnitt betitelt „JavaScript-Handler“-
MCP-Tool-Ergebnis behandeln
async function handleDocumentGeneration(toolResult) {const content = toolResult.structuredContent || toolResult.content;if (!content.success) {throw new Error(content.error || 'Generation failed');}if (content.data) {// Inline base64return downloadFromBase64(content.data, content.filename, content.mimeType);} else if (content.downloadUrl) {// Presigned URLreturn downloadFromUrl(content.downloadUrl, content.filename);} else {throw new Error('No document data in response');}} -
Von base64 herunterladen
function downloadFromBase64(base64Data, filename, mimeType) {const blob = base64ToBlob(base64Data, mimeType);const url = URL.createObjectURL(blob);const link = document.createElement('a');link.href = url;link.download = filename;document.body.appendChild(link);link.click();document.body.removeChild(link);setTimeout(() => URL.revokeObjectURL(url), 100);return { success: true, filename, size: blob.size };}function base64ToBlob(base64, mimeType) {const bytes = atob(base64);const array = new Uint8Array(bytes.length);for (let i = 0; i < bytes.length; i++) {array[i] = bytes.charCodeAt(i);}return new Blob([array], { type: mimeType });} -
Von URL herunterladen
async function downloadFromUrl(downloadUrl, filename) {// Direct navigation (opens in new tab)window.open(downloadUrl, '_blank');return { success: true, filename, url: downloadUrl };}
React-Integration
Abschnitt betitelt „React-Integration“import { useState } from 'react';
function useDocumentGeneration() { const [loading, setLoading] = useState(false); const [error, setError] = useState<string | null>(null);
const generate = async (template, data, format) => { setLoading(true); setError(null); try { const result = await callMcpTool('onlyoffice_generate_document', { template, data, format }); return await handleDocumentGeneration(result); } catch (err) { setError(err.message); throw err; } finally { setLoading(false); } };
return { generate, loading, error };}Artefakt-Lebenszyklus
Abschnitt betitelt „Artefakt-Lebenszyklus“URL-Modus-Artefakte sind temporär:
- Server schreibt Dokument nach
ARTIFACTS_DIR(oder S3-Bucket) - Gibt
downloadUrlmitexpiresAt-Zeitstempel zurück - Artefakt-Aufräumdienst entfernt abgelaufene Dateien (Standard-TTL: 1 Stunde)
- Download-Endpunkt (
/artifacts/<id>) bedient Dateien, solange gültig
Konfigurieren Sie die TTL über ARTIFACTS_TTL_SECONDS (Standard: 3600 = 1 Stunde).
Verwandte Themen
Abschnitt betitelt „Verwandte Themen“- STDIO-Einrichtung - URL-Modus für lokale Clients konfigurieren
- HTTP-Einrichtung - Remote-Clients konfigurieren
- Speicherübersicht - S3/MinIO-Presigned-URL-Konfiguration