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
|
|
@ -16,6 +16,7 @@ const DIST_DIR = import.meta.filename.endsWith(".ts")
|
|||
? path.join(import.meta.dirname, "dist")
|
||||
: import.meta.dirname;
|
||||
const RESOURCE_URI = "ui://get-time/mcp-app.html";
|
||||
const SAMPLE_DOWNLOAD_URI = "resource:///sample-report.txt";
|
||||
|
||||
/**
|
||||
* Creates a new MCP server instance with tools and resources registered.
|
||||
|
|
@ -70,5 +71,28 @@ export function createServer(): McpServer {
|
|||
},
|
||||
);
|
||||
|
||||
// Sample downloadable resource — used to demo ResourceLink in ui/download-file
|
||||
server.resource(
|
||||
SAMPLE_DOWNLOAD_URI,
|
||||
SAMPLE_DOWNLOAD_URI,
|
||||
{
|
||||
mimeType: "text/plain",
|
||||
},
|
||||
async (): Promise<ReadResourceResult> => {
|
||||
const content = [
|
||||
"Integration Test Server — Sample Report",
|
||||
`Generated: ${new Date().toISOString()}`,
|
||||
"",
|
||||
"This file was downloaded via MCP ResourceLink.",
|
||||
"The host resolved it by calling resources/read on the server.",
|
||||
].join("\n");
|
||||
return {
|
||||
contents: [
|
||||
{ uri: SAMPLE_DOWNLOAD_URI, mimeType: "text/plain", text: content },
|
||||
],
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
return server;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue