JSPM

  • Created
  • Published
  • Downloads 14
  • Score
    100M100P100Q75498F
  • License MIT

Deno runtime adapter for building MCP servers with ModelFetch

Package Exports

  • @modelfetch/deno

Readme

@modelfetch/deno

npm version License: MIT GitHub

Deno runtime adapter for building MCP (Model Context Protocol) servers with ModelFetch.

Installation

deno add npm:@modelfetch/deno

Quick Start

// server.ts
import { McpServer } from "npm:@modelcontextprotocol/sdk@^1.15.0/server/mcp.js";
import { z } from "npm:zod@^3.25.74";

const server = new McpServer({
  title: "My Deno MCP Server",
  name: "my-deno-server",
  version: "1.0.0",
});

server.registerTool(
  "roll_dice",
  {
    title: "Roll Dice",
    description: "Rolls an N-sided dice",
    inputSchema: { sides: z.number().int().min(2) },
  },
  ({ sides }) => ({
    content: [
      {
        type: "text",
        text: `🎲 You rolled a ${1 + Math.floor(Math.random() * sides)}!`,
      },
    ],
  }),
);

export default server;
// index.ts
import handle, { getEndpoint } from "npm:@modelfetch/deno";
import server from "./server.ts";

// Start the server
const httpServer = handle(server);
httpServer.finished.then(() => {
  console.log("Server stopped");
});

// Get the server address
const address = httpServer.addr;
if (address) {
  console.log(`Server running at: ${getEndpoint(address)}`);
}

API Reference

handle(server, options?)

Starts the MCP server with Deno-specific optimizations and returns a Deno.HttpServer instance.

  • server: The MCP server instance from @modelcontextprotocol/sdk
  • options: Optional Deno.ServeOptions for configuring the HTTP server

Returns: Deno.HttpServer

const httpServer = handle(server, {
  port: 3000,
  hostname: "localhost",
});

getEndpoint(address)

Gets the MCP server endpoint URL for connecting clients.

  • address: A Deno.Addr object from the HTTP server

Returns: string - The complete endpoint URL

const endpoint = getEndpoint(httpServer.addr); // "http://localhost:3000/mcp"

Running Your Server

# Development (with all permissions)
deno run -A index.ts

# Production (with specific permissions)
deno run --allow-net index.ts

# Compiled executable
deno compile -A index.ts -o mcp-server
./mcp-server

Permissions

Deno requires explicit permissions. For MCP servers, you typically need:

  • --allow-net: For the HTTP server
  • --allow-read: If reading files
  • --allow-write: If writing files
  • --allow-env: For environment variables
  • -A: Allow all (development only)

Configuration

Optional deno.json:

{
  "compilerOptions": {
    "strict": true
  },
  "imports": {
    "@modelfetch/deno": "npm:@modelfetch/deno",
    "@modelcontextprotocol/sdk": "npm:@modelcontextprotocol/sdk@^1.15.0",
    "zod": "npm:zod@^3.25.74"
  },
  "tasks": {
    "dev": "deno run -A index.ts",
    "build": "deno compile -A index.ts"
  }
}

Documentation

For complete documentation, examples, and guides, visit www.modelfetch.com/docs/runtimes/deno.

License

MIT