A simple Model Context Protocol (MCP) server implementation built with TypeScript. This server demonstrates basic MCP functionality including resources, prompts, and tools.
- SSE and STDIO transport support
- Resource handling with static and dynamic resources
- Sample prompt implementation
- Example tool that echoes messages
- Debug tool for server introspection
- Node.js (v16 or higher)
- npm or yarn
npm installnpm run buildnpm run start:httpThis starts the server on http://localhost:3000 with:
- SSE endpoint at
/sse - Message endpoint at
/messages
npm run startThis runs the server in stdio mode for command-line integrations.
-
Start the HTTP server:
npm run start:http
-
In a terminal window, connect to the SSE endpoint:
curl -N http://localhost:3000/sse
You should see a response like:
event: endpoint data: /messages?sessionId=YOUR_SESSION_ID -
In another terminal window, send a request to invoke the echo tool:
curl -X POST \ "http://localhost:3000/messages?sessionId=YOUR_SESSION_ID" \ -H 'Content-Type: application/json' \ -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/invoke", "params": { "name": "echo", "parameters": { "message": "Testing the MCP server!" } } }'
-
You should see a response in the SSE terminal window:
event: message data: {"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"Hello Testing the MCP server!"}]}} -
Try the debug tool to see available server methods:
curl -X POST \ "http://localhost:3000/messages?sessionId=YOUR_SESSION_ID" \ -H 'Content-Type: application/json' \ -d '{ "jsonrpc": "2.0", "id": 2, "method": "tools/invoke", "params": { "name": "debug", "parameters": {} } }'
For a visual interface, you can use the MCP Inspector tool:
- Connect to http://localhost:3000/sse in the MCP Inspector
- Browse available resources and tools
- Invoke tools interactively
hello://world- A static hello world resourcegreeting://{name}- A dynamic greeting with a name parameter
echo- Echoes back a message with "Hello" prefixdebug- Lists all available tools and methods
helpful-assistant- A basic helpful assistant prompt
- If you get "Headers already sent" errors, make sure you're not manually setting headers
- Session ID handling is crucial for proper message routing
- Check the server console for debugging information
MIT

