A TypeScript starter template for building Model Context Protocol (MCP) servers.
- Node.js 18+
- npm or yarn
npm installnpm run buildnpm run dev- src/index.ts - Main server file with tool definitions
- tsconfig.json - TypeScript configuration
- package.json - Dependencies and scripts
Edit src/index.ts to add new tools:
- Define a Zod schema for input validation
- Add the tool to the
toolsarray with name, description, and inputSchema - Handle the tool in the CallToolRequestSchema handler
Example:
const MyToolSchema = z.object({
param1: z.string().describe("Description"),
});
const tools: Tool[] = [
{
name: "my_tool",
description: "What this tool does",
inputSchema: {
type: "object",
properties: {
param1: {
type: "string",
description: "Description",
},
},
required: ["param1"],
},
},
];
server.setRequestHandler(CallToolRequestSchema, async (request) => {
const { name, arguments: args } = request;
if (name === "my_tool") {
const parsed = MyToolSchema.parse(args);
return {
content: [
{
type: "text",
text: `Result: ${parsed.param1}`,
},
],
};
}
});Use the MCP Inspector to test your server:
npx @modelcontextprotocol/inspector node build/index.js- Add your first custom tool
- Connect to an external API
- Test with MCP Inspector
- Deploy to production