---
title: "MCP Tutorial: Build AI Agents That Actually Do Things (2026 Guide)"
description: "Learn Model Context Protocol (MCP) - the \"USB-C for AI\" that OpenAI, Microsoft, and Anthropic all adopted. Step-by-step tutorial to build your first AI agent."
date: "2026-02-03"
tags: [ai, mcp, model-context-protocol, ai-agents, tutorial, anthropic, openai, claude]
---
**Tags:** ai, mcp, model-context-protocol, ai-agents, tutorial

If you've been following AI news, you've heard about **MCP (Model Context Protocol)** - the open standard that lets AI models connect to external tools, databases, and APIs.

Anthropic created it. OpenAI adopted it. Microsoft embraced it. It was just donated to the Linux Foundation's new Agentic AI Foundation.

MCP is being called **"USB-C for AI"** - a universal way for AI agents to plug into anything.

This tutorial shows you how to use it.

## What is MCP?

Before MCP, connecting an AI to external tools was a mess:
- Every AI provider had different APIs
- Every tool needed custom integration code
- Agents couldn't easily share capabilities

MCP standardizes this. One protocol, universal compatibility.

Think of it like this:
- **Before MCP:** Every phone needed a different charger
- **After MCP:** USB-C works with everything

## Why Should You Care?

MCP unlocks **agentic AI** - AI that doesn't just chat, but takes actions:

- Query your database and generate reports
- Create GitHub issues from bug descriptions
- Send Slack messages based on events
- Control smart home devices
- Execute code and return results

This is the difference between a chatbot and an AI assistant that actually *does* things.

## Prerequisites

You'll need:
- Node.js 18+ installed
- An Anthropic API key ([get one here](https://console.anthropic.com/))
- Basic JavaScript/TypeScript knowledge

## Step 1: Install the MCP SDK

```bash
mkdir my-mcp-agent
cd my-mcp-agent
npm init -y
npm install @anthropic-ai/sdk @modelcontextprotocol/sdk
```

## Step 2: Create a Simple MCP Server

MCP servers expose "tools" that AI can use. Let's create one that checks the weather:

```javascript
// weather-server.js
import { MCPServer } from '@modelcontextprotocol/sdk';

const server = new MCPServer({
  name: 'weather-server',
  version: '1.0.0'
});

// Define a tool the AI can use
server.addTool({
  name: 'get_weather',
  description: 'Get current weather for a city',
  parameters: {
    type: 'object',
    properties: {
      city: { type: 'string', description: 'City name' }
    },
    required: ['city']
  },
  handler: async ({ city }) => {
    // In production, call a real weather API
    const weather = {
      city,
      temp: Math.floor(Math.random() * 30) + 40,
      condition: ['sunny', 'cloudy', 'rainy'][Math.floor(Math.random() * 3)]
    };
    return JSON.stringify(weather);
  }
});

server.start();
console.log('Weather MCP server running...');
```

## Step 3: Connect Claude to Your Server

```javascript
// agent.js
import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic();

async function runAgent(userMessage) {
  const response = await client.messages.create({
    model: 'claude-sonnet-4-20250514',
    max_tokens: 1024,
    tools: [
      {
        name: 'get_weather',
        description: 'Get current weather for a city',
        input_schema: {
          type: 'object',
          properties: {
            city: { type: 'string', description: 'City name' }
          },
          required: ['city']
        }
      }
    ],
    messages: [{ role: 'user', content: userMessage }]
  });

  // Handle tool calls
  for (const block of response.content) {
    if (block.type === 'tool_use') {
      console.log(`AI wants to use: ${block.name}`);
      console.log(`With input: ${JSON.stringify(block.input)}`);
      // Call your MCP server here and return results
    }
  }

  return response;
}

// Test it
runAgent("What's the weather like in Denver?");
```

## Security Considerations

MCP gives AI real power. With that comes risk:

1. **Validate All Inputs** - Don't trust AI-generated queries blindly
2. **Use Read-Only Where Possible** - Don't give AI write access unless necessary
3. **Rate Limit Everything** - Prevent runaway costs and abuse
4. **Log All Tool Calls** - Maintain an audit trail

## Real-World MCP Servers

The community is building MCP servers for everything:

| Server | What It Does |
|--------|--------------|
| mcp-server-sqlite | Query SQLite databases |
| mcp-server-github | Full GitHub integration |
| mcp-server-slack | Send/read Slack messages |
| mcp-server-filesystem | Read/write files |
| mcp-server-puppeteer | Browser automation |

## Hosting Your MCP Agent

For production, a [$6/month DigitalOcean droplet](https://m.do.co/c/b0afdad57754) handles most MCP workloads:

```bash
git clone https://github.com/you/my-mcp-agent
cd my-mcp-agent
npm install
pm2 start agent.js --name mcp-agent
```

## What's Next?

MCP is still early but moving fast. The AI agents of 2026 won't just answer questions - they'll do your work. MCP is how they connect to everything.

---

## Resources

- [MCP Documentation](https://modelcontextprotocol.io)
- [Anthropic MCP Announcement](https://www.anthropic.com/news/model-context-protocol)
- [MCP GitHub Organization](https://github.com/modelcontextprotocol)

---

*Source: hereshecodes.app by Danielle Hoopes*
