KE

keithagroves/elysia-mcp

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

24 stars 4 forks 质量 41 趋势 10

Bun 和 Elysia 的模型上下文协议(MCP)服务器

概览

这是基于 Bun 和 Elysia Web 框架的模型上下文协议(MCP)服务器实现。该项目使您能够创建高性能的 MCP 服务器,通过标准化接口向大型语言模型(LLM)开放资源、工具和提示。 - Bun 和 Elysia 的服务器发送事件(SSE)传输实现 - 完整的 MCP 协议支持,包含资源、工具和提示 - 得益于 Bun 的 JavaScript 运行时,实现高性能 - TypeScript 支持和正确的类型定义 - 创建兼容 MCP 服务器的易用 API - 已安装 Bun 于你的系统中 - 对 TypeScript 和 Elysia 有基本熟悉 这会在 dist 目录中创建一个压缩的 Node.js 兼容构建。 - src/index.ts - 服务器的主要入口 - src/SSEElysiaTransport。

概述(AI 翻译)

这是基于 Bun 和 Elysia Web 框架的模型上下文协议(MCP)服务器实现。该项目使您能够创建高性能的 MCP 服务器,通过标准化接口向大型语言模型(LLM)开放资源、工具和提示。

特色

  • Bun 和 Elysia 的服务器发送事件(SSE)传输实现
  • 完整的MCP协议支持,包括资源、工具和提示
  • 得益于 Bun 的 JavaScript 运行时,实现了高性能
  • 支持TypeScript并定义合适的类型
  • 易于使用的 API,用于创建兼容 MCP 的服务器

先修条件

  • Bun已安装在你的系统上
  • 对TypeScript和Elysia有基本熟悉

安装

用途

启动服务器

为生产而建

这将在 dist 目录中创建一个缩小的 Node.js兼容构建。

发展

项目结构

  • src/index.ts - 服务器的主要入口
  • src/SSEElysiaTransport.ts - Bun 和 Elysia 的 SSE 传输实现

创建MCP服务器

调试

你可以用 MCP Inspector 工具调试 MCP 服务器,并通过 SSE 连接

这将打开一个网页界面,您可以:

本页由 AI 翻译,技术细节请以原文为准。

README

以下为原文 README 节选,完整内容请查看原文。

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 
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

在 GitHub 查看完整 README

安装

npx @modelcontextprotocol/inspector
新手?先看 mcpskill.org 教程 →