A streamlined template for quickly creating Model Context Protocol (MCP) servers using TypeScript.
This template provides a foundation for building MCP servers that expose data and functionality to LLM applications in a standardized way. MCP servers can:
- Expose data through Resources (like GET endpoints)
- Provide functionality through Tools (like POST endpoints)
- Define interaction patterns through Prompts (reusable templates)
- Enable Dynamic Prompting using tools to extract structured data from natural language input before generating a tailored prompt (see
meeting-agenda-generator
example insrc/index.ts
).
- Node.js (v16+)
- npm or yarn
# Clone this template
git clone https://github.com/yourusername/mcp-template.git my-mcp-server
cd my-mcp-server
# Install dependencies
npm install
- Use the Cursor Rule: When developing tools, prompts, or resources for this server, reference the
@mcp-general.mdc
Cursor rule. It contains detailed instructions, conventions, and code examples tailored for MCP server development. This will help ensure consistency and guide the AI assistant in generating correct code. - Build Before Running: Always run
npm run build
after making changes to your TypeScript code. The server runs the compiled JavaScript code from thebuild
directory, not the source.ts
files. - Test Thoroughly: Test each tool, prompt, and resource individually before relying on them in your AI interactions. Verify inputs, outputs, and error handling.
Before implementation, consider:
- What problem does your MCP server solve?
- What APIs or services will it use?
- What authentication requirements exist?
- Standard API key
- OAuth
- Other credentials
# Build the project
npm run build
# Run the server locally for testing
node build/index.js
You need to configure your AI assistant (like Claude Desktop or Cursor) to use this MCP server.
- Open Claude Desktop.
- Navigate to the settings.
- Click on
developer
, thenedit config
- Then add the below code snippet into the json file.
{
"mcpServers": {
"my-server": { // You can choose any name for your server
"command": "node",
"args": ["/path/to/your/project/mcp-template/build/index.js"], // Replace with the ABSOLUTE path to the built index.js file
"env": {
"EXA_API_KEY": "your-exa-api-key" // Add your Exa API key here (See note below)
},
"disabled": false,
"autoApprove": [] // Optionally list tools to auto-approve
}
}
}
- Locate your Cursor MCP configuration file (
mcp.json
). This is typically found in Cursor > settings. - Click on
Add a new global MCP server
- Add in the entry for your server:
{
// ... other configurations ...
"mcp-template": { // Use a descriptive name for your server
"command": "node",
"args": ["/path/to/your/project/mcp-template/build/index.js"], // Replace with the ABSOLUTE path to the built index.js file
"env": {
"EXA_API_KEY": "your-exa-api-key" // Add your Exa API key here (See note below)
}
}
// ... other configurations ...
}
Getting your Exa API Key:
- This template uses the Exa AI search API. You need an API key to use the search functionality.
- Go to the Exa dashboard: https://dashboard.exa.ai/api-keys
- Sign up for an account if you don't have one.
- Once logged in, navigate to the API Keys section to find or generate your key.
- Copy the key and replace
"your-exa-api-key"
in the configuration above.
Important: For both Claude Desktop and Cursor, the path in "args"
must be the absolute path to the compiled index.js
file located inside the build
directory. After running npm run build
, you can usually get this path by:
- Navigating to the
build
folder in your file explorer or IDE. - Right-clicking on the
index.js
file. - Selecting "Copy Path" or "Copy Absolute Path".
- Save the configuration file.
- Restart Claude Desktop or Cursor for the changes to take effect.
- Your MCP server should now be available to your AI assistant.
- Test each tool with valid inputs
- Verify output format is correct
- Document test results
- ✓ Use MCP SDK
- ✓ Implement comprehensive logging. Note to use
console.error
instead ofconsole.log
for logging. - ✓ Add type definitions
- ✓ Handle errors gracefully
- ✓ Test each component individually
MIT