Understanding MCP Servers: A Complete Beginner's Guide
Understanding MCP Servers: A Complete Beginner's Guide By a Developer Who Remembers Being Lost Too
Introduction: Let Me Tell You a Story
Ten years ago, I sat in front of my computer, staring at lines of code that might as well have been hieroglyphics. I felt overwhelmed, frustrated, and convinced that "programming just wasn't for me." But I kept going. And today, I'm going to walk you through building something I wish had existed when I started: a bridge between AI and the real world.
If you're reading this and thinking "I don't know anything about programming," that's perfect. You're exactly who I wrote this for. Grab a coffee, get comfortable, and let's build something amazing together.
What is MCP? (And Why Should You Care?)
The Restaurant Analogy
Imagine you've just hired the most brilliant assistant in the world. Let's call her Sarah. Sarah can answer any question, solve complex problems, and give incredible advice. There's just one problem: Sarah is sitting in a locked room with no phone, no computer, and no way to interact with anything outside that room.
Sure, you can talk to Sarah through the door, and she'll give you great advice. But she can't:
- Access your files
- Check your calendar
- Look up real-time information
- Send emails on your behalf
- Create documents
She's brilliant but isolated. Frustrating, right?
Now imagine you install a series of special intercoms in Sarah's room:
- The File Intercom: connects to your filing cabinet
- The Database Intercom: connects to your company's database
- The Weather Intercom: connects to the weather station
- The Email Intercom: connects to your email system
Suddenly, Sarah transforms from a great conversationalist into a genuinely useful assistant who can actually DO things for you.
That's exactly what MCP (Model Context Protocol) does for AI assistants like Claude.
MCP is a standardized way for AI assistants to safely connect to and interact with the outside world. It's like giving your AI assistant a set of tools and a phone book.
Why This Matters to You
Before MCP existed, if you wanted AI to help you with real tasks, you'd need:
- Custom code for every single integration
- Deep technical knowledge
- Hours or days of development work
- Maintenance for each connection
With MCP, you write one server, and any MCP-compatible AI can use it. It's like USB ports for AI: one standard that works everywhere.
The Three Superpowers MCP Gives to AI
MCP servers can provide three types of capabilities. Think of them as three different ways to help the AI be useful:
1. Resources: The Library Card
Resources are like giving the AI a library card. They can browse and read information, but they can't change anything.
Real-world examples:
- A list of your project files
- Database records
- API endpoints
- Documentation
Think of it like: A museum guide who can show you around and explain things, but can't touch the exhibits.
2. Tools: The Toolkit
Tools are actions the AI can perform. This is where things get powerful.
Real-world examples:
- Create a file
- Send an email
- Calculate complex math
- Resize an image
- Query a database
Think of it like: A Swiss Army knife. Each tool does something specific and useful.
3. Prompts: The Recipe Book
Prompts are pre-written workflows or templates that make complex tasks easier.
Real-world examples:
- "Analyze this code for bugs"
- "Summarize this document in bullet points"
- "Convert this data into a chart"
Think of it like: Having your grandmother's recipe cards. Instead of figuring out how to make cookies from scratch, you have step-by-step instructions.
Let's Build Your First MCP Server
Okay, enough theory. Let's get our hands dirty. We're going to build a simple calculator server that AI can use. By the end of this section, you'll have a working project you can show off.
What You'll Need
1. Node.js
Node.js is a program that lets you run JavaScript code on your computer (not just in web browsers). It's free and easy to install.
How to get it:
- Go to nodejs.org
- Click the big green button that says "LTS" (Long Term Support)
- Download and install it like any other program
To verify it worked, open your terminal and type: `node --version`
If you see something like "v20.11.0", you're ready!
What's a terminal?
- On Windows: It's called "Command Prompt" or "PowerShell"
- On Mac: It's called "Terminal"
- It's just a way to talk to your computer with text commands instead of clicking
2. A Text Editor
I recommend Visual Studio Code (VS Code). It's free, powerful, and most professional developers use it. Download it from code.visualstudio.com.
Step 1: Setting Up Your Project
Open your terminal and let's create a home for your project:
# Create a new folder
mkdir my-first-mcp-server
# Go inside that folder
cd my-first-mcp-server
# Initialize a Node.js project
npm init -y
# Install the MCP tools
npm install @modelcontextprotocol/sdkWhat just happened?
Let me break this down in plain English:
- `mkdir` = "make directory" (create a folder)
- `cd` = "change directory" (go into that folder)
- `npm init -y` = Start a new Node.js project (the `-y` says "yes" to all setup questions)
- `npm install` = Download the MCP toolkit we need
Think of `npm` as an app store for JavaScript code. Instead of downloading apps, you're downloading code libraries that other programmers built.
Step 2: Writing Your First Server
Open VS Code and create a new file called `server.js` in your project folder. Now, let's write some code together. I'll explain every single line:
#!/usr/bin/env node
// This first line tells your computer: "Hey, run this file with Node.js"
// STEP 1: Import the tools we need
// Think of this like taking tools out of a toolbox before starting a project
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import {
CallToolRequestSchema,
ListToolsRequestSchema,
} from "@modelcontextprotocol/sdk/types.js";
// STEP 2: Create our MCP server
// This is like opening a restaurant - we're giving it a name and saying what we do
const server = new Server(
{
name: "calculator-server", // The name of our server
version: "1.0.0", // Version number (standard practice)
},
{
capabilities: {
tools: {}, // We're telling MCP: "This server provides tools"
},
}
);
// STEP 3: Tell AI what tools we have available
// This is like putting up a menu in our restaurant
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [
{
name: "add",
description: "Add two numbers together",
inputSchema: {
type: "object",
properties: {
a: {
type: "number",
description: "First number"
},
b: {
type: "number",
description: "Second number"
},
},
required: ["a", "b"], // Both numbers are required
},
},
{
name: "multiply",
description: "Multiply two numbers",
inputSchema: {
type: "object",
properties: {
a: { type: "number", description: "First number" },
b: { type: "number", description: "Second number" },
},
required: ["a", "b"],
},
},
],
};
});
// STEP 4: Actually perform the calculations
// This is like a chef cooking the food someone ordered
server.setRequestHandler(CallToolRequestSchema, async (request) => {
// Get the tool name and the numbers from the request
const { name, arguments: args } = request.params;
// If they want to add numbers
if (name === "add") {
const result = args.a + args.b;
return {
content: [
{
type: "text",
text: `The sum of ${args.a} and ${args.b} is ${result}`,
},
],
};
}
// If they want to multiply numbers
if (name === "multiply") {
const result = args.a * args.b;
return {
content: [
{
type: "text",
text: `The product of ${args.a} and ${args.b} is ${result}`,
},
],
};
}
// If they asked for a tool we don't have
throw new Error(`Unknown tool: ${name}`);
});
// STEP 5: Start the server
async function main() {
// Set up communication (this is how the server talks to AI)
const transport = new StdioServerTransport();
await server.connect(transport);
// Let us know it's running (this appears in logs, not to users)
console.error("✅ Calculator MCP Server is running!");
}
// Run the main function and handle any errors
main().catch((error) => {
console.error("❌ Fatal error:", error);
process.exit(1);
});Understanding the Code: The Mental Model
Let me give you a mental model for how this works:
1. The Restaurant Opens (Creating the Server)
`const server = new Server({ name: "calculator-server", version: "1.0.0" })`
You're opening a restaurant called "Calculator Server."
2. You Print the Menu (Listing Tools)
`server.setRequestHandler(ListToolsRequestSchema, async () => { ... })`
When customers walk in and ask "What do you serve?", you hand them a menu. The menu says: "We can add numbers or multiply numbers."
3. Customers Order (AI Requests a Tool)
The AI looks at your menu and says: "I'd like the 'add' please, with 5 and 3."
4. You Cook the Food (Executing the Tool)
`server.setRequestHandler(CallToolRequestSchema, async (request) => { ... })`
You take their order, do the math, and serve back the result: "Here you go: 8!"
5. Communication System (Transport)
`const transport = new StdioServerTransport();`
This is the delivery system. It's how orders come in and food goes out. In technical terms, it uses "standard input/output" (stdio) to communicate.
Step 3: Configure Your Package
Edit your `package.json` file to look like this:
{
"name": "my-first-mcp-server",
"version": "1.0.0",
"type": "module",
"bin": {
"calculator-server": "./server.js"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^0.5.0"
}
}The critical line: `"type": "module"` tells Node.js we're using modern JavaScript `import` syntax.
Step 4: Test Your Server
Before connecting it to Claude, let's make sure it runs:
node server.jsIf you see "✅ Calculator MCP Server is running!", congratulations! Your server works.
Press `Ctrl+C` to stop it.
Chapter 4: Connecting Your Server to Claude Desktop
Now comes the magic part. Letting Claude use your calculator!
Step 1: Find Your Claude Config File
Claude Desktop has a configuration file that tells it which MCP servers to connect to.
On Mac:
`~/Library/Application Support/Claude/claude_desktop_config.json`
On Windows:
`%APPDATA%\Claude\claude_desktop_config.json`
Can't find it?
- Mac: Press `Cmd+Shift+G` in Finder, paste the path, and hit Enter
- Windows: Press `Win+R`, type the path, and hit Enter
Step 2: Edit the Config File
Open that file in your text editor. If it's empty or doesn't exist, create it with this content:
{
"mcpServers": {
"calculator": {
"command": "node",
"args": ["/FULL/PATH/TO/YOUR/server.js"]
}
}
}⚠️ CRITICAL: Replace `/FULL/PATH/TO/YOUR/server.js` with the actual full path to your file.
How to find the full path:
On Mac/Linux, in your project folder:
pwdOn Windows:
cdExample config:
{
"mcpServers": {
"calculator": {
"command": "node",
"args": ["/Users/john/my-first-mcp-server/server.js"]
}
}
}Step 3: Restart Claude Desktop
Completely quit Claude Desktop and reopen it.
Step 4: Test It!
Open Claude and try asking:
"Can you add 25 and 17 for me using your tools?"
If everything worked, Claude will use YOUR calculator to solve it!
---
I want to be honest with you: There were times when I wanted to quit programming. Times when I felt like everyone else "got it" and I didn't. Times when a bug made me want to throw my computer out the window.
But I kept going. And I'm so glad I did.
Programming gave me:
- A career I love
- The ability to build things that matter
- A way to solve problems creatively
- A community of brilliant, helpful people
- Financial security
- And most importantly: The confidence that I can figure out hard things
You can have all of that too. Not because you're special (though you are), but because you're willing to learn and persist. Hope you have learnt something new.