Cover image
Try Now
2025-03-08

Model Context Protocol (MCP) Server for Bun and Elysia

3 years

Works with Finder

1

Github Watches

1

Github Forks

6

Github Stars

MCP Server for Bun and Elysia

An implementation of the Model Context Protocol (MCP) server using Bun and the Elysia web framework. This project enables you to create high-performance MCP servers that expose resources, tools, and prompts to LLMs through a standardized interface.

Features

  • Server-Sent Events (SSE) transport implementation for Bun and Elysia
  • Complete MCP protocol support with resources, tools, and prompts
  • High-performance thanks to Bun's JavaScript runtime
  • TypeScript support with proper type definitions
  • Easy-to-use API for creating MCP-compatible servers

Prerequisites

  • Bun installed on your system
  • Basic familiarity with TypeScript and Elysia

Installation

# Clone the repository
git clone <your-repo-url>
cd mcp-server

# Install dependencies
bun install

Usage

Starting the server

# Start the server
bun start

# Start with hot reloading for development
bun dev

Building for production

# Build for production
bun run build

This will create a minified Node.js-compatible build in the dist directory.

Development

Project Structure

  • src/index.ts - Main entry point for the server
  • src/SSEElysiaTransport.ts - SSE transport implementation for Bun and Elysia

Creating an MCP Server

import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import { SSEElysiaTransport } from "./SSEElysiaTransport";
import { Elysia } from "elysia";

// Create MCP server
const server = new McpServer({
  name: "my-mcp-server",
  version: "1.0.0"
});

// Add resources, tools, and prompts
server.resource(
  "example",
  "example://resource",
  async (uri) => ({
    contents: [{
      uri: uri.href,
      text: "Example resource content"
    }]
  })
);

// Create Elysia app
const app = new Elysia()
  .get("/", () => "MCP Server")
  .get("/sse", async (context) => {
    try {
      // Create transport
      const transport = new SSEElysiaTransport("/messages", context);
      
      // Store transport
      const sessionId = transport.sessionId;
      // ... store transport in a map
      
      // Connect to MCP server
      await server.connect(transport);
      
      return;
    } catch (error) {
      // Handle error
    }
  })
  .post("/messages", async (context) => {
    // Handle incoming messages
  });

// Start server
app.listen(3001, () => {
  console.log("MCP Server running at http://localhost:3001");
});

Debugging

You can debug your MCP server using the MCP Inspector tool and connect through sse

npx @modelcontextprotocol/inspector

This will open a web interface where you can:

  • List available resources, tools, and prompts
  • Test calling tools and retrieving resources
  • Inspect the communication between the client and server

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Khalid kalib
  • Write professional emails

  • https://tovuti.be
  • Oede knorrepot die vasthoudt an de goeie ouwe tied van 't boerenleven

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • Gil kaminski
  • Make sure you are post-ready before you post on social media

  • J. DE HARO OLLE
  • Especialista en juegos de palabras en varios idiomas.

  • ShrimpingIt
  • Micropython I2C-based manipulation of the MCP series GPIO expander, derived from Adafruit_MCP230xx

  • huahuayu
  • A unified API gateway for integrating multiple etherscan-like blockchain explorer APIs with Model Context Protocol (MCP) support for AI assistants.

  • deemkeen
  • control your mbot2 with a power combo: mqtt+mcp+llm

  • zhaoyunxing92
  • 本项目是一个钉钉MCP(Message Connector Protocol)服务,提供了与钉钉企业应用交互的API接口。项目基于Go语言开发,支持员工信息查询和消息发送等功能。

  • apappascs
  • Discover the most comprehensive and up-to-date collection of MCP servers in the market. This repository serves as a centralized hub, offering an extensive catalog of open-source and proprietary MCP servers, complete with features, documentation links, and contributors.

  • justmywyw
  • Short and sweet example MCP server / client implementation for Tools, Resources and Prompts.

    Reviews

    4 (1)
    Avatar
    user_lKkwOAVq
    2025-04-15

    As a devoted MCP application user, I highly recommend the GitHub MCP Server in Go by metoro-io. This server is seamlessly efficient and aligns perfectly with Go’s concurrency model, offering reliable performance for managing MCP tasks. It's an essential tool for any developer needing a robust and scalable solution. Check it out!