adamd9/mcp-reference
If you are the rightful owner of mcp-reference and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MCP Reference Server is a minimal, self-contained Model Context Protocol (MCP) HTTP server designed for easy integration into Node.js projects.
MCP Reference Server
A minimal, self-contained Model Context Protocol (MCP) HTTP server you can copy into other Node.js projects.
It exposes a single /mcp endpoint via Express and implements three reference tools:
ping— health check returning a timestamp.echo— echos a provided message.get_time— returns current time in UTC and optionally a specified IANA timezone.
Prerequisites
- Node.js 18+
Quick start
# From this folder
npm install
npm start
# Server starts on http://localhost:3002
Test with MCP Inspector (HTTP transport):
# GUI mode (may open a browser window)
npx @modelcontextprotocol/inspector --transport http --server-url http://localhost:3002/mcp
Project structure
mcp-reference/
├── package.json
├── README.md
├── .gitignore
├── mcp-inspector.config.json
└── src/
└── index.js
How it works
src/index.jscreates an Express app and an MCP server from@modelcontextprotocol/sdk.- The
/mcproute usesStreamableHTTPServerTransportto bridge HTTP requests to the MCP server and supportsPOST(JSON-RPC),GET(SSE), andDELETE(session close) per the Streamable HTTP transport. - Tools are registered via
server.registerTool(name, {title, description, inputSchema}, handler). - Tool handlers resolve to
{ content: [{ type: 'text', text: string }] }, which MCP clients will display.
Environment variables
PORT(optional): server port. Defaults to3002.MCP_AUTH_CODE(optional): if set, the server requiresmcp-auth-code: <code>on all/mcproutes.
Integrating into another project
- Copy the
src/index.jsandpackage.jsondependencies into your project. - Mount the
/mcproute in your existing Express server (or use this file as a separate service). - Register your own tools using the
registerToolpattern shown insrc/index.js.
Example tool registration
server.registerTool(
'hello_name',
{
title: 'Hello Name',
description: 'Returns a personalized greeting.',
inputSchema: { name: z.string().describe('Name to greet') }
},
async ({ name }) => ({
content: [{ type: 'text', text: JSON.stringify({ greeting: `Hello, ${name}!` }, null, 2) }]
})
);
Notes
- This reference intentionally avoids any databases, external APIs, or auth. Add those in your own project as needed.
- For full capabilities and protocol details, see the MCP SDK docs.
Troubleshooting MCP Inspector
-
If Inspector tries to start a demo STDIO server (e.g.,
mcp-server-everything) or connects to the wrong port (e.g.,3001), force HTTP transport and URL:npx @modelcontextprotocol/inspector --transport http --server-url http://localhost:3002/mcp -
If you get a proxy/UI port conflict like
Proxy Server PORT IS IN USE at port 6277, close any previous Inspector instances. On macOS, you can find and kill the process:lsof -i :6277 kill -9 <PID>Note: The Inspector CLI currently expects stdio transport for local commands, so prefer the GUI with
--transport httpand--server-urlwhen testing HTTP servers.
Enabling basic auth for the MCP server
You can enable a simple shared-secret check on the MCP routes by setting an environment variable. When enabled, requests to POST /mcp, GET /mcp (SSE), and DELETE /mcp must include this header with the exact secret value:
mcp-auth-code: <your-secret>
Set the secret and start the server:
export MCP_AUTH_CODE="my-secret-123"
npm start
Test with curl:
# Initialize (example JSON-RPC payload), passing the header
curl -sS \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-H "mcp-auth-code: my-secret-123" \
-d '{"jsonrpc":"2.0","id":"1","method":"initialize","params":{"protocolVersion":"2025-03-26"}}' \
http://localhost:3002/mcp
Run MCP Inspector with the header:
# Option 1: pass the header inline
npx @modelcontextprotocol/inspector \
--transport http \
--server-url http://localhost:3002/mcp \
--header "mcp-auth-code: my-secret-123"
# Option 2: use env var with the npm script
export MCP_AUTH_CODE="my-secret-123"
npm run mcp:debug:auth