Build an MCP server with Deno
Expose a validated MCP tool with the official TypeScript SDK, Zod, and stdio
An MCP server exposes tools, resources, and prompts to AI clients through a protocol. Deno is a natural fit for a local stdio server: single-file TypeScript, explicit permissions, and no separate compile step.
deno add npm:@modelcontextprotocol/sdk npm:zod
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const server = new McpServer({ name: "project-info", version: "1.0.0" });
server.registerTool(
"read_project_note",
{
description: "Read one approved note by its short name",
inputSchema: { name: z.string().regex(/^[a-z0-9-]+$/) },
},
async ({ name }) => ({
content: [{
type: "text",
text: await Deno.readTextFile(`./notes/${name}.md`),
}],
}),
);
await server.connect(new StdioServerTransport());
Grant the client read access only to the notes directory:
{
"mcpServers": {
"project-info": {
"command": "deno",
"args": ["run", "--allow-read=./notes", "mcp_server.ts"]
}
}
}
Prefer Streamable HTTP for remote servers. The old HTTP+SSE transport exists only for compatibility. A public deployment also needs authentication, Origin and DNS-rebinding defenses, rate limits, and authorization on every tool call.
Official references: Deno MCP server example, MCP TypeScript SDK server, and Model Context Protocol.