Create Your First MCP Server

Now let's add a tool to your MCP server.

What You'll Learn

  • How to register a tool
  • Input and output schemas with Zod
  • Returning results from tools

Tool Anatomy

Every MCP tool has:

1server.registerTool(
2    'tool-name',           // Unique identifier
3    {
4        title: 'Display Name',
5        description: 'What this tool does',
6        inputSchema: { /* parameters */ },
7        outputSchema: { /* return type */ }
8    },
9    async (inputs) => {
10        // Tool logic here
11        return { content: [...], structuredContent: {...} };
12    }
13);

Choose Your Track

  • Engineers: Follow ENGINEER for detailed explanations
  • Non-Engineers: Follow NON-ENGINEER for a ready-to-use prompt

The Tool We'll Build

A simple greet tool that:

  • Takes a name parameter (string)
  • Returns a greeting message

Example:

  • Input: { name: "Alice" }
  • Output: "Hello, Alice! Welcome to MCP."