Example tool that demonstrates the basic structure of an MCP tool
The MCP Server Template provides a streamlined foundation for building custom Model Context Protocol (MCP) servers using the FastMCP framework. It offers dual transport support for both stdio and HTTP communication, allowing developers to create tools that can be used locally or shared across a team. With TypeScript integration and a well-structured codebase, this template simplifies the process of extending AI capabilities with custom tools, resources, and prompts.
The MCP Server Template is a CLI tool designed to help you quickly set up and build your own Model Context Protocol (MCP) server using the FastMCP framework. This template provides everything you need to create custom AI tools that can be integrated with Cursor and other MCP-compatible clients.
You can create a new MCP server project using one of the following methods:
# Using npx
npx @mcpdotdirect/create-mcp-server
# Using npm
npm init @mcpdotdirect/mcp-server
After creating your project, install the dependencies:
# Using npm
npm install
# Using yarn
yarn
# Using pnpm
pnpm install
# Using bun
bun install
The template supports two transport methods:
This mode runs on your local machine and communicates via stdout:
# Start the stdio server
npm start
# Development mode with auto-reload
npm run dev
This mode runs as an HTTP server that can be accessed locally or remotely:
# Start the HTTP server
npm run start:http
# Development mode with auto-reload
npm run dev:http
By default, the HTTP server runs on port 3001. You can change this by setting the PORT environment variable:
PORT=8080 npm run start:http
command
npm start
url
http://localhost:3001/sse
For a more portable configuration, create an .cursor/mcp.json
file in your project:
{
"mcpServers": {
"my-mcp-stdio": {
"command": "npm",
"args": ["start"],
"env": {
"NODE_ENV": "development"
}
},
"my-mcp-sse": {
"url": "http://localhost:3001/sse"
}
}
}
You can also create a global configuration at ~/.cursor/mcp.json
to make your MCP servers available in all workspaces.
The template provides a structured way to add custom tools, resources, and prompts:
Edit the server configuration to add your own tools:
server.addTool({
name: "hello_world",
description: "A simple hello world tool",
parameters: z.object({
name: z.string().describe("Name to greet")
}),
execute: async (params) => {
return `Hello, ${params.name}!`;
}
});
server.addResourceTemplate({
uriTemplate: "example://{id}",
name: "Example Resource",
mimeType: "text/plain",
arguments: [
{
name: "id",
description: "Resource ID",
required: true,
},
],
async load({ id }) {
return {
text: `This is an example resource with ID: ${id}`
};
}
});
server.addPrompt({
name: "greeting",
description: "A simple greeting prompt",
arguments: [
{
name: "name",
description: "Name to greet",
required: true,
},
],
template: "Hello, {{name}}! How can I assist you today?"
});
FastMCP provides built-in tools for testing:
# Test with mcp-cli
npx fastmcp dev server.js
# Inspect with MCP Inspector
npx fastmcp inspect server.ts