MCP服务器模板

一个基于Elysia和Bun运行时的MCP服务器模板,用于构建与LLM客户端兼容的工具、提示和资源服务。

  • by kerlos
  • TypeScript
  • 本地部署
  • 8 星标
  • 更新于
在 GitHub 查看 kerlos/elysia-mcp-starter

使用说明

Elysia MCP起动器

使用Elysia和Bun运行时构建MCP(模型上下文协议)服务器的入门模板。

此入门模板基于 elysia mcp 插件,它为具有HTTP传输支持的模型上下文协议提供了全面的ElysiaJS集成。

目的

此存储库为创建可与Claude Desktop、Cody或其他MCP兼容应用程序等LLM客户端一起使用的MCP服务器提供了基础。它演示了如何实现:

  • 工具:LLM可以调用的函数(例如计算器)
  • 鼓励:可重复使用的提示模板
  • 资源:LLM可以访问的动态数据源

目录结构

elysia-mcp-starter/
├── src/
│   ├── index.ts          # Main application entry point
│   ├── tools/            # MCP tools (functions callable by LLMs)
│   │   └── calculate.ts  # Example calculator tool
│   ├── prompts/          # MCP prompt templates
│   │   └── hello.ts      # Example greeting prompt
│   └── resources/        # MCP resources (dynamic data sources)
│       └── news.ts       # Example news resource
├── package.json          # Project dependencies and scripts
├── tsconfig.json         # TypeScript configuration
└── README.md            # This file

入门指南

选项1:使用Bun Create(推荐)

# 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

选项2:克隆存储库

  1. 克隆或使用此模板:

    git clone https://github.com/kerlos/elysia-mcp-starter.git
    cd elysia-mcp-starter
    
  2. 安装依赖项:

    bun install
    
  3. 启动开发服务器:

    bun run dev
    

MCP服务器将在以下地点提供:

  • 服务器: http://localhost:3000
  • MCP端点: http://localhost:3000/mcp

发展

  • 开发服务器: bun run dev (自动重新加载)
  • 生产服务器: bun run start
  • 检查MCP服务器: bun run inspect (打开MCP检查器)

添加新组件

工具

在中添加新工具 src/tools/ 并将其注册到 src/index.ts:

import { registerYourTool } from './tools/your-tool';
// ... in setupServer:
registerYourTool(server);

鼓励

在中添加新提示 src/prompts/ 并将其注册到 src/index.ts:

import { registerYourPrompt } from './prompts/your-prompt';
// ... in setupServer:
registerYourPrompt(server);

资源

在中添加新资源 src/resources/ 并将其注册到 src/index.ts:

import { registerYourResource } from './resources/your-resource';
// ... in setupServer:
registerYourResource(server);

与LLM客户端一起使用

配置您的MCP兼容客户端以连接到 http://localhost:3000/mcp 访问此服务器提供的工具、提示和资源。

MCP客户端配置

将以下配置添加到MCP客户端的配置文件中:

适用于克劳德桌面(~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "elysia-mcp-starter": {
      "type": "http",
      "url": "http://localhost:3000/mcp"
    }
  }
}

对于光标(~/.cursor/mcp.json):

{
  "mcpServers": {
    "elysia-mcp-starter": {
      "type": "http",
      "url": "http://localhost:3000/mcp"
    }
  }
}

对于Cody(VS代码设置):

{
  "cody.experimental.mcp.servers": {
    "elysia-mcp-starter": {
      "type": "http",
      "url": "http://localhost:3000/mcp"
    }
  }
}

替换 "elysia-mcp-starter" 如果您在其他端口上运行,请使用您首选的服务器名称并更新URL。

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。