A TypeScript template for building MCP servers using Streamable HTTP transport.
This template provides a foundation for creating MCP servers that can communicate with AI assistants and other MCP clients. It includes a simple HTTP server implementation with example tools, resource & prompts to help you get started building your own MCP integrations.
- Node.js 22+ (see
.nvmrc
for exact version)
- Clone the repository:
git clone <repository-url>
cd mcp-server-template
- Install dependencies:
npm install
- Create environment file:
cp .env.example .env
Start the development server with hot-reload:
npm run dev
The server will start on http://localhost:3000
and automatically restart when you make changes to the source code.
Build the project for production:
npm run build
The compiled JavaScript will be output to the dist/
directory.
Use the MCP inspector tool to test your server:
npm run inspector
POST /mcp
- Main MCP communication endpointGET /mcp
- Returns "Method not allowed" (405)DELETE /mcp
- Returns "Method not allowed" (405)
To add a new tool, modify src/server.ts
:
server.tool(
"tool-name",
"Tool description",
{
// Define your parameters using Zod schemas
param: z.string().describe("Parameter description"),
},
async ({ param }): Promise<CallToolResult> => {
// Your tool implementation
return {
content: [
{
type: "text",
text: `Result: ${param}`,
},
],
};
},
);
To add a new prompt template, modify src/server.ts
:
server.prompt(
"prompt-name",
"Prompt description",
{
// Define your parameters using Zod schemas
param: z.string().describe("Parameter description"),
},
async ({ param }): Promise<GetPromptResult> => {
return {
messages: [
{
role: "user",
content: {
type: "text",
text: `Your prompt content with ${param}`,
},
},
],
};
},
);