What is MCP and How to Debug It Locally with Claude Desktop

In this post, I will explain what MCP is and how to connect Claude Desktop to your local server for testing. I will keep the explanation simple, with pictures and diagrams to make it easy to follow.

In Part 2, we will see how to add OAuth 2.1 security so other users can connect safely over the internet.

What is MCP?

Model Context Protocol (MCP) is an open standard created by Anthropic. It lets AI models like Claude, ChatGPT, and Cursor talk to external tools, databases, and APIs in a clean and standard way.

Think of MCP like USB-C for AI. Before USB-C, every device had a different charging cable. With MCP, instead of every AI app creating its own custom plugin format, there is one common standard that every app can use to find and run your tools.

MCP defines three main concepts:

Concept What it is
Tools Functions the AI can run (for example: send_email, get_weather, create_expense)
Resources Data the AI can read (files, database rows, documents)
Prompts Reusable prompt templates that help the AI perform specific tasks

What Problem Does MCP Solve?

Imagine you have a toy robot.

This robot is very smart and can help you with many things. But to do real work, it needs to talk to other machines — like a light switch, a database, a weather app, and an online store. The problem is that every machine speaks a different language.

This is difficult because the robot has to learn 100 different languages.

MCP solves this problem. MCP is one common language that everyone agrees to use. The AI speaks MCP, and your server speaks MCP. Because they use the same protocol, they can talk without extra custom code.

What is a "Tool"?

A tool is simply a function that the AI can call. You write the function once in code, and the AI calls it when the user asks for it.

Tool Name What it does
send_email Sends an email to someone
search_web Searches the web and returns results
get_weather Gets current weather for a city
create_note Saves a new note in your app
delete_file Deletes a file from storage

For example, you can tell Claude:

"Send an email to john@example.com and tell him our meeting is at 3:00 PM tomorrow."

Claude sees the send_email tool in your server, fills in the email address and message, and calls the tool. The email gets sent. You do not need to write extra logic during the chat — Claude handles it automatically.

Writing Your First MCP Tool

Writing a tool is straightforward. Every tool has three simple parts:

  1. Name and Description: Helps Claude understand when to call the tool.
  2. Input Schema (Zod): Tells Claude what parameters are needed.
  3. Handler Function: The actual code that runs and talks to your API or database.

Step 1 - Create the Tool File

Here is an example of a simple tool that gets weather data using the MCP SDK and Zod:

// src/tools/get-weather.js import { z } from "zod"; export function registerGetWeatherTool(server, context) { server.registerTool( "get_weather", { title: "Get Weather", description: "Get real-time weather for any city. Use when the user asks about current weather or temperature.", inputSchema: { city: z.string().describe("The name of the city, for example 'London' or 'Tokyo'") } }, async ({ city }) => { // Use the API token from context const res = await fetch(`https://api.weather.com/v1/current?city=${encodeURIComponent(city)}`, { headers: { Authorization: `Bearer ${context.upstreamToken}` } }); if (!res.ok) { throw new Error(`Weather API error: ${res.statusText}`); } const data = await res.json(); return { content: [{ type: "text", text: `Current weather in ${city}: ${data.condition}, ${data.temp}°C` }] }; } ); }

Step 2 - Register Your Tool in the Server

Next, register this tool inside your main server file (createMcpServer). This ensures that both your local test server and your future production server can use the same tools:

// src/create-mcp-server.js import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; import { registerGetWeatherTool } from "./tools/get-weather.js"; export function createMcpServer(context) { const server = new McpServer({ name: "my-mcp-server", version: "1.0.0" }); // Register tools here registerGetWeatherTool(server, context); return server; }
Rule Why it helps
One tool = one job Keep each tool focused on one task so Claude chooses the right one easily.
Clear description Write clear descriptions for the AI so it knows exactly when to trigger the tool.
Throw errors on failure Always use throw new Error() when something fails so Claude knows there was an error.

Two Ways to Connect: stdio vs HTTP

There are two ways an AI client can talk to your MCP server:

Feature stdio (Local) HTTP (Remote)
Where it runs On your own computer only On a server over the internet
Setup Very easy Needs HTTPS and authentication setup
Security No auth needed (runs locally) Requires OAuth 2.1 tokens
Best for Fast local development and testing Production with real users
Speed Instant Depends on internet speed

Simple Rule:

Use stdio while you are coding and testing tools on your computer.

Use HTTP when you deploy your MCP server for production users.

How to Run Your Server

A typical MCP project has two main server files:

File Purpose
src/server.js Production HTTP server for web requests
src/stdio-server.js Local stdio server for Claude Desktop

Here is what the stdio server does when it starts up:

To test the server manually, open your terminal in the project directory (for example D:\MCP Server\MYMCPTEST) and run:

PS D:\MCP Server\MYMCPTEST> node build/index.js [MCP SERVER] Server started successfully and listening for JSON-RPC messages.

When the server starts successfully, you will see a confirmation message in your terminal:

Note: You do not need to run this command manually every time. Once Claude Desktop is configured, it will start the server automatically.

How to Connect to Claude Desktop

Claude Desktop makes it simple to connect your server. Follow these steps:

Step 1 - Open Claude Desktop and go to Settings

Open Claude Desktop, click the menu in the top left, and select Settings.

Step 2 - Click the Developer Tab

Inside Settings, click the Developer tab on the left sidebar.

Step 3 - Click "Edit Config"

Click the Edit Config button. This will open your claude_desktop_config.json file in your default text editor.

Step 4 - Add Your Server Configuration

Paste your server details inside mcpServers. Use the full path to your build file:

{ "mcpServers": { "my-mcp-server": { "command": "node", "args": ["D:/MCP Server/MYMCPTEST/build/index.js"], "env": { "API_URL": "http://localhost:8080/api/v1", "USERNAME": "admin", "PASSWORD": "your_password", "NODE_TLS_REJECT_UNAUTHORIZED": "0" } } } }
  • args: The absolute path to your built file (for example D:/MCP Server/MYMCPTEST/build/index.js).
  • env: The environment variables and credentials passed directly to your server.
  • NODE_TLS_REJECT_UNAUTHORIZED: "0": Useful if you are using local self-signed SSL certificates for testing.

Save the file after editing.

Step 5 - Close and Reopen Claude Desktop

You must fully close Claude Desktop so it loads the new configuration file:

  • Mac: Right-click Claude in your dock and select Quit.
  • Windows: Right-click Claude in the system tray (bottom right) and select Exit.

Then open Claude Desktop again.

Step 6 - Verify Your Connected Tools

Open Claude Desktop and go back to Settings → Developer. You will see your server listed and running:

Click on your server to see the full list of tools Claude loaded from it:

Once your tools are visible, your setup is complete and ready to test.

You can now ask Claude to run tasks using plain English in the chat:

"What is the weather in Tokyo?"

"Create a new expense: Office Rent, $500, paid by credit card today."

Claude will choose the right tool, validate the arguments, call your local server, and give you the final answer.


What's Next?

Now that your MCP server is running locally and connected to Claude Desktop, you can easily build and test custom tools on your machine.

In Part 2, we will take this setup to production. We will see how to host the MCP server over HTTP and secure it with OAuth 2.1 — including Dynamic Client Registration (RFC 7591), PKCE verification, and RS256 JWT tokens.

If you have questions or run into any problems while setting up your local server, feel free to leave a comment below.

Post a Comment

0 Comments