A Node.js implementation of a remote Model Context Protocol (MCP) server, providing both SSE and streamable HTTP transports for MCP clients.
- Express-based API: RESTful endpoints for MCP communication
- SSE and Streamable HTTP: Supports both Server-Sent Events and streamable HTTP transports
- TypeScript: Written in TypeScript for type safety
- Environment Configuration: Uses
.env
for configuration
src/constant.ts
– Project constants (server/tool names, descriptions, error messages)src/index.ts
– Main entry point, sets up Express server and MCP transportssrc/server.ts
– Defines the MCP server and toolspackage.json
– Project metadata, scripts, dependenciestsconfig.json
– TypeScript configuration.env
– Environment variables (e.g.,PORT
)
- Node.js (v14 or higher recommended)
- npm or yarn
Clone the repository and install dependencies:
git clone <your-repo-url>
cd remote-mcp-server-nodejs
npm install
Create a .env
file in the root directory (see .env.example
if available):
PORT=3000
npm run build
npm start
The server will start on the port specified in .env
(default: 3000).
GET /sse
– Establishes an SSE connection for MCPPOST /messages?sessionId=...
– Sends a message to an SSE sessionALL /mcp
– Handles MCP requests via streamable HTTPGET /
– Health check (returns welcome message)
The server registers a tool named say-greeting
that returns a greeting message for the provided input.
You can connect to this MCP server using any MCP-compatible client. For example, with VS Code's Model Context Protocol extension, configure .vscode/mcp.json
as follows:
After configuration, you can invoke the say-greeting
tool by sending a request with an input string. Example request:
{
"jsonrpc": "2.0",
"method": "say-greeting",
"params": { "input": "World" },
"id": 1
}
Example response:
{
"jsonrpc": "2.0",
"result": {
"content": [
{ "type": "text", "text": "Hello, World!" }
]
},
"id": 1
}
You can use tools like curl
, Postman, or any MCP client to interact with the server.
npm run build
– Compile TypeScript to JavaScriptnpm run start
– Start the servernpm run watch
– Watch files and rebuild on changes
TypeScript source is in the src/
directory. Compiled output is in dist/
.
MIT