Skip to content

Instantly share code, notes, and snippets.

@kuboon
Created December 23, 2025 12:07
Show Gist options
  • Select an option

  • Save kuboon/305e07ca14f9444e897b857e9a85b8be to your computer and use it in GitHub Desktop.

Select an option

Save kuboon/305e07ca14f9444e897b857e9a85b8be to your computer and use it in GitHub Desktop.
Local stdio mcp server to get local cache by url from DENO_DIR
import { createCache } from "jsr:@deno/cache-dir";
import { McpServer } from "npm:@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "npm:@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "npm:zod";
const { load } = createCache();
function isUint8Array(arg: string | Uint8Array): arg is Uint8Array {
return arg.constructor === Uint8Array;
}
async function getLocalCache(url: string): Promise<string | null> {
const result = await load(url);
switch (result?.kind) {
case "module":
return isUint8Array(result.content)
? new TextDecoder().decode(result.content)
: result.content;
case "redirect":
return getLocalCache(result.specifier);
default:
return null;
}
}
const textContent = (text: string, isError = false) => ({
content: [{ type: "text" as const, text }], isError,
});
const server = new McpServer({
name: "deno-cache-reader",
version: "0.1.0",
});
server.registerTool(
"read_deno_cache",
{
description: "Read a file from the Deno cache by URL",
inputSchema: {
url: z.string().describe("The URL of the module to read from cache"),
},
},
async ({ url }) => {
try {
const text = await getLocalCache(url);
if (text !== null) {
return textContent(text);
} else {
return textContent(`URL not found in cache: ${url}`, true);
};
} catch (error) {
return textContent(`Error reading cache: ${error}`, true);
}
}
);
const transport = new StdioServerTransport();
await server.connect(transport);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment