
Elysia MCP Plugin
A comprehensive ElysiaJS plugin for building Model Context Protocol (MCP) servers with HTTP transport, session management, and support for tools, resources, and prompts.
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
- 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, McpServer } from 'elysia-mcp';
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.tool(
'echo',
{
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 numbersmultiply
- Multiply two numberspower
- Calculate base to the power of exponent
-
Text Utilities Plugin (
/text
) - Text processing tools:uppercase
- Convert text to uppercaseword_count
- Count words in textreverse
- Reverse text charactersreplace
- Replace text with global matching
Testing with MCP Inspector
-
Install MCP Inspector:
npx @modelcontextprotocol/inspector
-
Connect to your server:
- Basic Example:
http://localhost:3000/mcp
- Multiple Servers Example:
- Math Plugin:
http://localhost:3000/math
- Text Plugin:
http://localhost:3000/text
- Math Plugin:
- Basic Example:
Configuration Options
serverInfo
: Server informationcapabilities
: MCP capabilities to advertiseenableLogging
: Enable debug logging (default: false)setupServer
: Callback to register tools, resources, and prompts
Session Management
The plugin automatically handles session management via the Mcp-Session-Id
header. Each session maintains its own state and can be terminated cleanly.
Modular Handler Architecture
The plugin supports a modular handler architecture that allows you to create specialized endpoints for different MCP capabilities:
import {
mcp,
ToolsHandler,
ResourcesHandler,
PromptsHandler,
} from 'elysia-mcp';
const app = new Elysia().use(
mcp({
/* config */
})
);
API Reference
Tools
Register tools using the MCP Server instance:
server.tool(
'tool-name',
{
param: z.string().describe('Parameter description'),
},
async (args) => {
// Tool implementation
return {
content: [{ type: 'text', text: 'Tool result' }],
};
}
);
Resources
Register resources for file or data access:
server.resource('Resource Name', 'resource://uri', async () => {
return {
contents: [
{
uri: 'resource://uri',
mimeType: 'text/plain',
text: 'Resource content',
},
],
};
});
Prompts
Register reusable prompt templates following MCP best practices:
server.prompt(
'prompt-name',
'Prompt description',
{
param: z.string().describe('Parameter description'),
},
async (args) => {
return {
description: 'Generated prompt',
messages: [
{
role: 'user',
content: {
type: 'text',
text: `Generated prompt with ${args.param}`,
},
},
],
};
}
);
Testing
Run the comprehensive test suite:
bun test
License
MIT - see LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Related
Plugin Configuration
Plugin Options
interface MCPPluginOptions {
serverInfo?: {
name: string;
version: string;
};
capabilities?: ServerCapabilities;
enableLogging?: boolean;
setupServer?: (server: McpServer) => void | Promise<void>;
}
Architecture
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ HTTP Client │───▶│ Elysia HTTP │───▶│ MCP Plugin │
│ │ │ Handler │ │ │
└─────────────────┘ └──────────────┘ └─────────────────┘
│
│
┌─────────────────┐
│ McpServer │
│ (Singleton) │
└─────────────────┘
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.