KE

kerlos/elysia-mcp

开发工具

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

49 stars 5 forks 质量 60 趋势 17MIT

ElysiaJS 用于带有 HTTP 传输的模型上下文协议插件

概览

一个全面的 ElysiaJS 插件,用于实现支持 HTTP 传输的模型上下文协议(MCP)服务器。 - : 基于 HTTP 的完整 MCP 传输,支持可流式 HTTP - : 通过头部实现有状态会话处理 - : 采用 TypeScript 和 Zod 验证构建 - : Elysia 应用的简单插件架构 - : 工具、资源、提示和日志 - : 使用任意日志器(如 pino、winston、bunyan 等) - : 正确的 JSON-RPC 2.0 错误响应 - : 使用 Bun 测试运行工具实现完整单元测试覆盖 要快速开始预配置的Elysia MCP项目,您可以使用我们的入门模板: elysia-mcp-starter模板包括: - 预配置的 Elysia 设置,使用 MCP 插件 - TypeScript 配置 - 开发脚本 - 基本项目结构 - 示例 MCP 服务器实现 这个示例演示了如何在单个 Elysia 应用中创建多个 MCP 插件: - 加法 - 加两个数字 - 乘法 - 乘两个数 - 幂 - 计算指数的幂 -...

概述(AI 翻译)

一个全面的 ElysiaJS 插件用于实现 模型上下文协议(MCP)服务器 支持HTTP传输。

特色

  • HTTP 传输:基于 HTTP 的完整 MCP 传输,支持可流式 HTTP
  • 会话管理:通过头部进行有状态会话处理
  • 类型安全:采用TypeScript和Zod验证构建
  • 易于集成:Elysia应用的简单插件架构
  • 全面支持:工具、资源、提示和日志
  • 自定义记录器支持:使用任何记录器(pino、winston、bunyan等)
  • 错误处理:正确的JSON-RPC 2.0错误响应
  • 测试:使用Bun测试运行程序进行完整的单元测试覆盖

安装

入门模板

要快速开始预配置的Elysia MCP项目,您可以使用我们的入门模板:

elysia-mcp-starter模板包括:

  • 预配置的 Elysia 搭配 MCP 插件
  • TypeScript配置
  • 开发脚本
  • 基本项目结构
  • 示例MCP服务器实现

快速启动

用途

例行列

基本示例:

多服务器示例:

这个示例演示了如何在单个 Elysia 应用中创建多个 MCP 插件:

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

README

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

Elysia MCP Plugin

A comprehensive ElysiaJS plugin for implementing Model Context Protocol (MCP) servers with HTTP transport support.

Features

  • HTTP Transport: Full HTTP-based MCP transport with Streamable HTTP
  • Session Management: Stateful session handling via headers
  • Type-Safe: Built with TypeScript and Zod validation
  • Easy Integration: Simple plugin architecture for Elysia apps
  • Comprehensive Support: Tools, Resources, Prompts, and Logging
  • Custom Logger Support: Use any logger (pino, winston, bunyan, etc.)
  • Error Handling: Proper JSON-RPC 2.0 error responses
  • Testing: Full unit test coverage with Bun test runner

Installation

bun add elysia-mcp
# or
npm install elysia-mcp

Starter Template

To quickly get started with a pre-configured Elysia MCP project, you can use our starter template:

# Create a new project from the starter template
bun create https://github.com/kerlos/elysia-mcp-starter my-mcp-project

# Navigate to the project
cd my-mcp-project

# Install dependencies
bun install

# Start development server
bun run dev

The elysia-mcp-starter template includes:

  • Pre-configured Elysia setup with MCP plugin
  • TypeScript configuration
  • Development scripts
  • Basic project structure
  • Example MCP server implementation

Quick Start

import { Elysia } from 'elysia';
import { mcp } from 'elysia-mcp';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';

const app = new Elysia()
  .use(
    mcp({
      serverInfo: {
        name: 'my-mcp-server',
        version: '1.0.0',
      },
      capabilities: {
        tools: {},
        resources: {},
        prompts: {},
        logging: {},
      },
      setupServer: async (server: McpServer) => {
        // Register your MCP tools, resources, and prompts here
        server.registerTool(
          'echo',
          {
            description: 'Echoes back the provided text',
            inputSchema: {
              text: z.string().describe('Text to echo back'),
            },
          },
          async (args) => {
            return {
              content: [{ type: 'text', text: `Echo: ${args.text}` }],
            };
          }
        );
      },
    })
  )
  .listen(3000);

Usage

Running the Examples

Basic Example:

# Run the basic example server (port 3000)
bun run example

# Or with development mode (auto-restart)
bun run dev

Multiple Servers Example:

# Run the multiple MCP servers example (port 3000)
bun example:multi

This example demonstrates how to create multiple MCP plugins in a single Elysia application:

  • Math Operations Plugin (/math) - Basic arithmetic tools:

    • add - Add two numbers
    • multiply - Multiply two numbers
    • power - Calculate base to the power of exponent
在 GitHub 查看完整 README

安装

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