Bun
Run fast MCP servers with Bun
The @modelfetch/bun
package lets you run MCP servers as Bun-native HTTP servers.
Installation
bun add @modelfetch/bun
Usage
Start The Server
import handle from "@modelfetch/bun";
import server from "./server.ts"; // Import your McpServer
// Run as a Bun HTTP server
handle(server);
Get Listening Address
import handle, { getListeningAddress } from "@modelfetch/bun";
import server from "./server.ts"; // Import your McpServer
// Run as a Bun HTTP server
const bunServer = handle(server);
// Print listening address
console.log(`The MCP server is listening at ${getListeningAddress(bunServer)}`);
Specify Custom Port
import handle, { getListeningAddress } 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,
});
// Print listening address
console.log(`The MCP server is listening at ${getListeningAddress(bunServer)}`);
API Reference
handle(server, options?)
Starts the MCP server
- server: Required
McpServer
instance from@modelcontextprotocol/sdk
- options: Optional
Bun.ServeOptions
getListeningAddress(server)
Gets listening address from the Bun.Server
instance
- server: Required
Bun.Server
instance returned by thehandle()
function