Quick Start
Build your first MCP server with mcpcraft-sdk in under 5 minutes.
Quick Start
Create your first MCP server in under 5 minutes.
1. Install
Create a new project and install mcpcraft-sdk:
mkdir my-mcp-server
cd my-mcp-server
npm init -y
npm install mcpcraft-sdk zod2. Write your server
Create server.ts:
import { createServer, tool } from "mcpcraft-sdk"
const server = createServer({ name: "my-first-server" })
server.add(tool({
name: "greet",
description: "Greets a user by name",
input: {
name: { type: "string", description: "The user's name" }
},
run: async ({ name }) => {
return { message: `Hello, ${name}!` }
}
}))
server.start()input: { name: { type: "string" } } looks like a simple object, but behind the scenes mcpcraft-sdk generates a JSON Schema for the MCP protocol and a Zod validator for runtime checks — both automatically.
3. Run it
npx ts-node server.tsThe server starts and listens on stdio. It won't print anything — it's waiting for an MCP client to connect.
4. Test it
Install the MCP Inspector to test your server locally:
npx @modelcontextprotocol/inspector node -- dist/server.jsOr, if you're using Claude Desktop, add this to your claude_desktop_config.json:
{
"mcpServers": {
"my-first-server": {
"command": "node",
"args": ["dist/server.js"]
}
}
}What just happened?
Let's walk through the code line by line:
| Code | What it does |
|---|---|
createServer({ name }) | Initializes an MCP server instance with stdio transport |
tool({ name, description, input, run }) | Defines a callable function — name tells the LLM what it does, description helps the LLM decide when to use it |
input: { name: { type: "string" } } | Declares parameters → mcpcraft-sdk auto-generates JSON Schema + Zod validator |
run: async ({ name }) => { ... } | The handler that executes when the LLM calls this tool — receives typed, validated arguments |
server.add(tool(...)) | Registers the tool with the MCP protocol so the client can discover it via tools/list |
server.start() | Launches the stdio transport and begins listening for JSON-RPC messages |
What the LLM sees
When a user asks "Greet me as Alice", this is what happens behind the scenes:
- Claude sees your
greettool in the MCP tool list - It reads the description: "Greets a user by name"
- It sees it needs a
nameparameter (string) - It calls
greet({ name: "Alice" }) - Your handler runs and returns
{ message: "Hello, Alice!" } - Claude reads the result and responds: "Hello, Alice! How can I help you today?"
Next Steps
- Deployment — Deploy to Vercel or Docker
- API Reference: createServer
- Defining Tools
- Examples: API Fetch