ModelFetch

Bun

Run lightning-fast MCP servers with Bun

The @modelfetch/bun package lets you run MCP servers as Bun-native HTTP servers.

Installation

Terminal
bun add @modelfetch/bun

Usage

Start The Server

src/index.ts
import handle from "@modelfetch/bun";
import server from "./server.ts"; // Import your McpServer

// Run as a Bun HTTP server
handle(server);

Log The Endpoint

src/index.ts
import handle, { getEndpoint } from "@modelfetch/bun";
import server from "./server.ts"; // Import your McpServer

// Run as a Bun HTTP server
const bunServer = handle(server);

// Log the endpoint when the server starts listening
console.log(`MCP server is available at ${getEndpoint(bunServer)}`);

Specify Custom Port

src/index.ts
import handle, { getEndpoint } from "@modelfetch/bun";
import server from "./server.ts"; // Import your McpServer

// Run as a Bun HTTP server
const bunServer = handle(server, {
  // Customize server options
  port: 8080,
});

console.log(`MCP server is available at ${getEndpoint(bunServer)}`);

API Reference

handle(server, options?)

Starts the MCP server

getEndpoint(server)

Gets the MCP server endpoint from the Bun.Server instance

  • server: Required Bun.Server instance returned by the handle() function