Your First MCP Tool

Hands-on practice for this lecture. Work through the exercises and quizzes to reinforce what you've learned.

Interactive Workshop

Build Your First MCP Tool

Create an MCP server from scratch and register your first tool — an add function that sums two numbers.

1

Initialize a Node.js project with the MCP SDK and Zod for schema validation.

jsonpackage.json
1{
2  "name": "my-mcp-server",
3  "version": "1.0.0",
4  "type": "module",
5  "scripts": {
6    "build": "tsc",
7    "start": "node dist/index.js"
8  },
9  "dependencies": {
10    "@modelcontextprotocol/sdk": "^1.0.0",
11    "zod": "^3.22.0"
12  },
13  "devDependencies": {
14    "typescript": "^5.3.0",
15    "@types/node": "^20.0.0"
16  }
17}
1 / 4
MCP Client
stdio · connectedmy-mcp-server
add

Add two numbers together and return the sum

requirednumber
requirednumber

Test Your Understanding

Multiple choice — select an answer to see the explanation.

1 / 4

What is Zod used for in an MCP server?