refactor: use MCP resource types for ui/download-file params
Replace custom {filename, content, mimeType, encoding} params with
standard MCP resource types: EmbeddedResource for inline content and
ResourceLink for host-resolved references.
New params shape:
params: { contents: (EmbeddedResource | ResourceLink)[] }
This reuses existing MCP primitives instead of inventing new ones,
and enables hosts to show resource 'bubbles' or resolve ResourceLink
URIs via resources/read on the MCP server.
This commit is contained in:
parent
494c73e7ca
commit
3757271641
1 changed files with 366 additions and 125 deletions
|
|
@ -137,8 +137,7 @@ function GetTimeAppInner({
|
|||
log.info("Open link request", isError ? "rejected" : "accepted");
|
||||
}, [app, linkUrl]);
|
||||
|
||||
const canDownload =
|
||||
app.getHostCapabilities()?.downloadFile !== undefined;
|
||||
const canDownload = app.getHostCapabilities()?.downloadFile !== undefined;
|
||||
|
||||
const handleDownloadFile = useCallback(async () => {
|
||||
const sampleContent = JSON.stringify(
|
||||
|
|
@ -148,13 +147,35 @@ function GetTimeAppInner({
|
|||
);
|
||||
log.info("Requesting file download...");
|
||||
const { isError } = await app.downloadFile({
|
||||
filename: "export.json",
|
||||
content: sampleContent,
|
||||
mimeType: "application/json",
|
||||
contents: [
|
||||
{
|
||||
type: "resource",
|
||||
resource: {
|
||||
uri: "file:///export.json",
|
||||
mimeType: "application/json",
|
||||
text: sampleContent,
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
log.info("Download", isError ? "rejected" : "accepted");
|
||||
}, [app, serverTime]);
|
||||
|
||||
const handleDownloadLink = useCallback(async () => {
|
||||
log.info("Requesting resource link download...");
|
||||
const { isError } = await app.downloadFile({
|
||||
contents: [
|
||||
{
|
||||
type: "resource_link",
|
||||
uri: "resource:///sample-report.txt",
|
||||
name: "sample-report.txt",
|
||||
mimeType: "text/plain",
|
||||
},
|
||||
],
|
||||
});
|
||||
log.info("Resource link download", isError ? "rejected" : "accepted");
|
||||
}, [app]);
|
||||
|
||||
return (
|
||||
<main
|
||||
className={styles.main}
|
||||
|
|
@ -203,8 +224,11 @@ function GetTimeAppInner({
|
|||
|
||||
{canDownload && (
|
||||
<div className={styles.action}>
|
||||
<p>Export current server time as JSON file</p>
|
||||
<button onClick={handleDownloadFile}>Download File</button>
|
||||
<p>Download file via EmbeddedResource or ResourceLink</p>
|
||||
<div style={{ display: "flex", gap: "8px" }}>
|
||||
<button onClick={handleDownloadFile}>Embedded</button>
|
||||
<button onClick={handleDownloadLink}>Link</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</main>
|
||||
|
|
|
|||
Loading…
Reference in a new issue