You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Host SHOULD open the URL in the user's default browser or a new tab.
1015
1017
1018
+
`ui/download-file` - Request host to download a file
1019
+
1020
+
```typescript
1021
+
// Request (EmbeddedResource — inline content)
1022
+
{
1023
+
jsonrpc: "2.0",
1024
+
id: 1,
1025
+
method: "ui/download-file",
1026
+
params: {
1027
+
contents: [
1028
+
{
1029
+
type: "resource",
1030
+
resource: {
1031
+
uri: "file:///export.json", // Used for suggested filename
1032
+
mimeType: "application/json",
1033
+
text: "{ ... }"// Text content (or `blob` for base64 binary)
1034
+
}
1035
+
}
1036
+
]
1037
+
}
1038
+
}
1039
+
1040
+
// Request (ResourceLink — host fetches)
1041
+
{
1042
+
jsonrpc: "2.0",
1043
+
id: 1,
1044
+
method: "ui/download-file",
1045
+
params: {
1046
+
contents: [
1047
+
{
1048
+
type: "resource_link",
1049
+
uri: "https://api.example.com/reports/q4.pdf",
1050
+
name: "Q4 Report",
1051
+
mimeType: "application/pdf"
1052
+
}
1053
+
]
1054
+
}
1055
+
}
1056
+
1057
+
// Success Response
1058
+
{
1059
+
jsonrpc: "2.0",
1060
+
id: 1,
1061
+
result: {} // Empty result on success
1062
+
}
1063
+
1064
+
// Error Response (if denied or failed)
1065
+
{
1066
+
jsonrpc: "2.0",
1067
+
id: 1,
1068
+
error: {
1069
+
code: -32000, // Implementation-defined error
1070
+
message: "Download denied by user"|"Invalid content"|"Policy violation"
1071
+
}
1072
+
}
1073
+
```
1074
+
1075
+
MCP Apps run in sandboxed iframes where direct file downloads are blocked (`allow-downloads` is not set). `ui/download-file` provides a host-mediated mechanism for apps to offer file exports — useful for visualization tools (SVG/PNG export), document editors, data analysis tools, and any app that produces downloadable artifacts.
1076
+
1077
+
The `contents` array uses standard MCP resource types (`EmbeddedResource` and `ResourceLink`), avoiding custom content formats. For `EmbeddedResource`, content is inline via `text` (UTF-8) or `blob` (base64). For `ResourceLink`, the host can retrieve the content directly from the URI.
1078
+
1079
+
Host behavior:
1080
+
* Host SHOULD show a confirmation dialog before initiating the download.
1081
+
* For `EmbeddedResource`, host SHOULD derive the filename from the last segment of `resource.uri`.
1082
+
* Host MAY reject the download based on security policy, file size limits, or user preferences.
1083
+
* Host SHOULD sanitize filenames to prevent path traversal.
1084
+
1016
1085
`ui/message` - Send message content to the host's chat interface
0 commit comments