关于 MCP Server for Bun and Elysia
基于 Bun 与 Elysia 实现的 MCP 服务模板,通过 SSE 传输向 LLM 暴露资源、工具和提示词。适合希望在 Bun 运行时上使用 TypeScript 构建 MCP 服务的开发者。
主要功能
- 01基于 SSE 的传输实现
- 02支持资源、工具与提示词
- 03运行于 Bun 运行时
- 04提供 TypeScript 类型定义
- 05支持开发模式热重载与生产构建
适用场景
- 01在 Bun 与 Elysia 上搭建 MCP 服务
- 02使用 MCP Inspector 调试 SSE 连接的服务
MCP 相关
该项目是 MCP 服务实现,通过 SSE 传输向 MCP 客户端暴露资源、工具和提示词。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
暂未收录安装方式
我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
适用于 Bun 和 Elysia 的 MCP 服务
使用 Bun 和 Elysia Web 框架实现的 Model Context Protocol(MCP)服务。该项目让你能够创建高性能的 MCP 服务,通过标准化接口向大模型暴露资源、工具和提示词。
功能特性
- 面向 Bun 和 Elysia 的 Server-Sent Events(SSE)传输实现
- 完整的 MCP 协议支持,涵盖资源、工具和提示词
- 得益于 Bun 的 JavaScript 运行时,性能出色
- 支持 TypeScript,并提供完善的类型定义
- 易于使用的 API,用于创建兼容 MCP 的服务
前置条件
- 系统中已安装 Bun
- 对 TypeScript 和 Elysia 有基本了解
安装
# Clone the repository
git clone <your-repo-url>
cd mcp-server
# Install dependencies
bun install
用法
启动服务
# Start the server
bun start
# Start with hot reloading for development
bun dev
为生产环境构建
# Build for production
bun run build
这将在 dist 目录中生成一个压缩过的、兼容 Node.js 的构建产物。
开发
项目结构
src/index.ts- 服务的主入口点src/SSEElysiaTransport.ts- 面向 Bun 和 Elysia 的 SSE 传输实现
创建 MCP 服务
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");
});
调试
你可以使用 MCP Inspector 工具调试 MCP 服务,并通过 sse 连接
npx @modelcontextprotocol/inspector
这将打开一个 Web 界面,你可以在其中:
- 列出可用的资源、工具和提示词
- 测试调用工具和获取资源
- 检查客户端与服务之间的通信
贡献
欢迎贡献!请随时提交 Pull Request。
许可证
本项目基于 MIT 许可证授权 - 详情请参阅 LICENSE 文件。
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。