MCP Express Server
A TypeScript-based MCP server template using Express.js and Server-Sent Events, providing example tools for echoing messages, performing calculations, and retrieving server time.
README
MCP Express Server
A Model Context Protocol (MCP) server implementation using TypeScript, Express.js, and Server-Sent Events (SSE) for real-time communication.
Features
- MCP Protocol Support: Implements the Model Context Protocol specification
- SSE Transport: Real-time communication using Server-Sent Events
- TypeScript: Fully typed for better developer experience
- Express.js: Robust HTTP server framework
- Environment Configuration: Using dotenv for configuration management
Project Structure
src/
├── index.ts # Main entry point and Express server setup
├── server.ts # MCP protocol handling and SSE transport layer
├── tools.ts # Tool implementations and business logic
└── types.ts # TypeScript type definitions
Installation
npm install
Configuration
Create a .env file in the root directory:
cp .env.example .env
Edit .env with your configuration:
PORT=3000
HOST=0.0.0.0
SERVER_NAME=mcp-express-server
SERVER_VERSION=1.0.0
Development
Run in development mode with auto-reload:
npm run dev
Build
Compile TypeScript to JavaScript:
npm run build
Production
Run the compiled server:
npm start
API Endpoints
GET /
Server information and available endpoints
GET /health
Health check endpoint
- Returns server status and active connection count
GET /sse
Server-Sent Events endpoint
- Establishes a persistent connection for real-time notifications
- Clients should connect here to receive server updates
POST /message
MCP message endpoint
- Send JSON-RPC 2.0 formatted MCP requests
- Receives MCP responses
Available Tools
The server comes with three example tools:
- echo: Echoes back a message
- add: Adds two numbers together
- get_time: Returns the current server time
MCP Protocol Usage
Initialize Connection
curl -X POST http://localhost:3000/message \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}'
List Available Tools
curl -X POST http://localhost:3000/message \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}'
Call a Tool
curl -X POST http://localhost:3000/message \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "add",
"arguments": {
"a": 5,
"b": 3
}
}
}'
Adding New Tools
Edit src/tools.ts to add new tools:
export const availableTools: Tool[] = [
// ... existing tools
{
name: 'your_tool',
description: 'Description of your tool',
inputSchema: {
type: 'object',
properties: {
param1: {
type: 'string',
description: 'Parameter description'
}
},
required: ['param1']
}
}
];
// Add implementation in executeTool function
case 'your_tool':
return {
content: [{
type: 'text',
text: `Result: ${args.param1}`
}]
};
License
MIT
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.
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.
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.
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.