This project demonstrates a minimal Model Context Protocol (MCP) server implementation in TypeScript, using the official TypeScript SDK. It provides a simple API for tool invocation and resource access, and is compatible with the MCP Inspector for testing and exploration.
- Addition Tool: Add two numbers via the MCP protocol.
- Greeting Resource: Generate a dynamic greeting for any name.
- Streamable HTTP Transport: Uses the recommended HTTP transport for MCP.
- Express.js Integration: Easily extensible and familiar web server setup.
npm install @modelcontextprotocol/sdk express zod@3 npx -y tsx server.ts npx @modelcontextprotocol/inspector
npm install @modelcontextprotocol/sdk express zod@3npx -y tsx server.tsThe server will start on http://localhost:3000/mcp.
You can use the official MCP Inspector to interact with this server:
npx @modelcontextprotocol/inspectorInspector Settings:
- Transport Type: Streamable HTTP
- URL: http://localhost:3000/mcp
- Connection Type: Via Proxy
- add: Adds two numbers.
- Input:
{ "a": number, "b": number } - Output:
{ "result": number }
- Input:
- greeting://{name}: Returns a greeting for the given name.
- Example:
greeting://Alice→Hello, Alice!
- Example:
server.ts— Main server implementationpackage.json— Project dependenciesREADME.md— This documentation
- Ensure Node.js 18+ is installed.
- If you see port conflicts, change the port in
server.tsor set thePORTenvironment variable. - For MCP Inspector issues, see MCP Inspector documentation.
MIT (see LICENSE if present)