Bun
Run lightning-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);
Log The Endpoint
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
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
- server: Required
McpServer
instance from@modelcontextprotocol/sdk
- options: Optional
Bun.ServeOptions
getEndpoint(server)
Gets the MCP server endpoint from the Bun.Server
instance
- server: Required
Bun.Server
instance returned by thehandle()
function