MCP Starter Template
A starter template for building Model Context Protocol (MCP) servers. This template provides the basic structure and boilerplate code needed to create custom MCP tools that can be integrated with AI assistants like Claude.
What is MCP?
The Model Context Protocol (MCP) allows AI assistants to interact with external tools and services. Using this template, you can build servers that expose custom functionality to AI models, enabling them to perform actions like:
- Fetching data from APIs
- Performing calculations
- Accessing databases
- Controlling external systems
- And much more!
Prerequisites
- Node.js (v18 or later recommended)
- npm or yarn
Getting Started
- Clone this repository to use as a starting point:
git clone https://github.com/lmarte17/mcp_starter_template.git
cd mcp_starter_template
- Delete the .git directory to start with a clean Git history for your project:
# On macOS/Linux
rm -rf .git
# On Windows (Command Prompt)
rmdir /s /q .git
- Initialize a new Git repository (optional):
git init
- Install dependencies:
npm install
# or
yarn install
- Build the TypeScript code:
npm run build
# or
yarn build
- Run the server:
npm start
# or
yarn start
Project Structure
src/index.ts- The main entry point for your MCP serversrc/- Directory for your server's source codebuild/- Output directory for compiled code (created after building)
Creating Your Own Tools
The template includes an example tool to help you get started. To create your own tools:
- Open
src/index.ts - Locate the tools section (marked with comments)
- Add your own tool definitions following the example pattern:
server.tool(
"your_tool_name",
"Description of what your tool does",
{
// Define parameters with zod schemas
param1: z.string().describe("Description of parameter 1"),
param2: z.number().describe("Description of parameter 2")
},
async ({ param1, param2 }) => {
// Implement your tool logic here
// Return results according to MCP protocol
return {
content: [
{
type: "text",
text: "Your result output here"
}
]
};
}
);
Building and Testing
After making changes to your code, you need to rebuild the project:
npm run build
# or
yarn build
This will compile the TypeScript code into JavaScript in the dist/ directory.
Connecting to AI Assistants
MCP servers can be used with compatible AI assistants. To connect your server:
- Run your server locally
- Set up the appropriate configuration in your AI assistant's interface
- Use the MCP protocol to communicate between the assistant and your server
Tips for Development
- Use TypeScript interfaces to define your API response types
- Leverage the
makeApiRequesthelper function for external API calls - Structure your tools to be reusable and composable
- Use proper error handling for robust operation
Resources
- MCP Documentation - Official MCP documentation
- Zod Documentation - For schema validation
- TypeScript Documentation - For TypeScript references
