Podcast Title

Author Name

0:00
0:00
Album Art

MCP Server Explained: Your Guide to Building AI-Powered Tools

By 10xdev team August 16, 2025

In this article, we will explore how to build our own MCP server and, more importantly, understand what an MCP server is and how it works. In today's modern AI world, where everything is changing so rapidly, developers need to figure out how they can add value. We often hear that AI will replace us, but after reading this article, you will understand that in the world of AI, there could be even more new job opportunities for us, and that's where the MCP server can play a vital role.

For developers, it's very important to have an understanding of how to build an MCP server and how it works. By using this technology, we can create many beautiful agentic workflows and integrate various interesting features into our existing AI applications. This article is especially important for those who have a basic understanding of web development but are new to the AI space. We will walk through building an MCP server using the official TypeScript SDK to provide a complete picture.

What is MCP? A Simple Breakdown

Let's start from the very beginning. MCP stands for Model Context Protocol. If we break it down word by word—Model, Context, and Protocol—it becomes quite easy to understand.

A quick background: the Model Context Protocol was developed by Anthropic, the company that built Claude, the popular AI assistant. Now, let's explore what MCP really means by understanding each word in the phrase.

The "Protocol": A Set of Rules

Let's start with the last word: Protocol. What does a protocol mean? It's a set of rules. As developers, we work with protocols all the time. For example, when we work with the HTTP protocol, it's not just random communication; there's a set of rules we follow. When we build REST APIs, we use specific methods like GET, POST, PUT, PATCH, or DELETE. We transfer data in specific formats like JSON or XML. All of this is structured communication following a protocol.

In a similar way, AI agents or AI-based applications also need to follow a structured approach when exchanging information. For now, just remember: a protocol is simply a set of rules.

The "Models": Language Experts

Next, let's talk about Models. The term "model" is something we are already quite familiar with. We all use models in one way or another, especially Large Language Models (LLMs) like GPT from OpenAI, Gemini from Google, and Claude from Anthropic.

But have you ever wondered how these LLMs actually work? Most people think that when you ask a model something, it searches the internet for answers, but that's not how it works. What a model actually does is predict the next word in a sentence. That's it. They are language experts; they don't know facts in real-time or pull live data from the web. Instead, they have been trained with a huge amount of information beforehand (pre-trained). When you ask something, they try to figure out what word most likely comes next. That's why the reply appears word-by-word, as if it's typing. That's not a fancy front-end animation; it's just how LLMs work. They predict one word at a time.

The "Context": The Missing Piece

Now, let's move to Context. In English, context means the subject or background of something. When you talk to a model like ChatGPT or Claude, the input you provide becomes the context.

Here's the thing: the model's response entirely depends on the context you provide. If the model already knows what you are referring to, it will give you an accurate answer. But if you don't provide enough context, it can't help you properly, even if it's a powerful LLM.

For example, if you ask Claude, "Who am I?" it won't be able to answer. But if you had previously told it, "Hey, I am Ahmed," and then later ask, "Who am I?" it will say, "You are Ahmed." Why? Because now it has context.

So, when we say Model Context Protocol, we are talking about a set of rules that define how to feed context into a model. This context could be any kind of external information—something outside the model's default knowledge. Models don't magically know about your calendar, your emails, or your database. That's where MCP comes in. It lets us feed these external pieces of information into a model in a structured and standardized way.

Why MCP is a Game-Changer for Developers

Now that we understand what MCP is, let's talk about why we need it. Consider a powerful, AI-equipped code editor like Cursor. You can chat with it while coding to explain something, generate code, or refactor logic.

Now, let's say you ask Cursor something that depends on data from your local machine, like a large email database. Can Cursor access that data by default? No, it can't. But what if you connect a custom-made component—an MCP server—to Cursor?

Cursor still can't access your files directly, but now when you ask it a question, it will turn to this MCP server and say, "Hey, do you know anything about this?" The MCP server, which you built to connect with your files, will fetch the relevant information, turn it into context, and feed that back to the model. Now the model has the necessary background to generate a smart, informed reply. And the best part? You can connect multiple MCP servers to your application.

Let's walk through a real example. Say you ask your editor, "Do I have any meetings today?" To answer that, the AI needs to access your schedule. If you use Google Calendar, neither Cursor nor ChatGPT can access it directly. To make this work universally, no matter which AI application you ask from, we need a universal way to connect. That's exactly what an MCP server enables.

If you create an MCP server that follows the protocol and hooks into your calendar, any AI application that supports MCP can connect to it and get the right context. This isn't something regular users can build; you need coding skills. So, AI will not replace us; it will create new opportunities.

Without MCP, you would have to build everything into your client. Every AI assistant would need to carry the burden of logic, context building, and data retrieval. If anything changed—your GitHub repo structure, your schedule format, or your database schema—you would have to update every single client individually. That's a nightmare.

Imagine if GitHub themselves just released their own MCP server. Then, all you would need to do is plug it into your editor, and it just works. You don't write any integration code. That's the magic of MCP.

MCP: The "USBC Port" for AI Applications

The official MCP documentation offers a brilliant analogy: think of MCP like a USBC port for AI applications.

Remember how things were before USBC? Your computer had tons of different ports: HDMI, VGA, USB-A, an audio jack, and more. You had to manage different cables for everything. It was a mess. But now, everything uses USBC—one universal connector for data, power, audio, and video.

That's exactly what MCP is for AI applications. Instead of building separate integrations for each AI tool, you now build one standardized MCP server, and any AI tool that supports MCP can connect to it.

How an MCP Server Works Under the Hood

Let's go one step deeper. An MCP server primarily works through standard input and output (stdin/stdout). When websites communicate with APIs, they use REST over HTTP. But with MCP servers, especially when used locally, we don't use HTTP. Instead of network calls, it uses direct system-level communication.

Let's visualize a conversation between an AI assistant and your MCP server:

  1. You ask a question: "Do I have a meeting today?"
  2. The AI discovers tools: It checks all connected MCP servers to see what they can do and figures out it should call a calendar-related method.
  3. The AI sends a request: It writes a structured input into your MCP server's standard input. Conceptually, it looks like this: json { "method": "calendar", "params": { "date": "2025-08-16" } }
  4. The MCP server runs logic: It receives the input, pulls data from your Google Calendar, and prepares a response.
  5. The server sends a response: It writes a JSON object to its standard output. json { "result": { "meetings": [ { "title": "Team Sync", "time": "4 PM" } ] } }
  6. The AI translates the response: The AI assistant reads this raw data, runs its natural language model, and finally says, "Yes, you have a team sync meeting today at 4 p.m."

To the user, it feels like magic, but behind the scenes, a structured conversation just happened.

The MCP Architecture: Host, Client, and Server

The MCP architecture consists of several key components:

  • MCP Host: This is the AI application, like Claude, Cursor, or your own custom AI interface. It's the main brain that runs the show.
  • MCP Client: This is the internal part of the host that connects to MCP servers. In Cursor, the "MCP Tools" section in the settings is the client.
  • MCP Server: This is the tool you build that knows how to fetch or generate context from files, APIs, or calendars. You can make it with Node, Python, Java—anything you like, as long as it follows the protocol.
  • Data Sources: This is where your MCP server pulls data from—a local database, your file system, an external API like Google Calendar, or anything else that holds relevant context.

To recap: the MCP host is your AI application. The MCP client is the bridge inside the host. The MCP server is what you build to deliver context. And the data sources are your backend services.

Let's Build: An MCP Server with the TypeScript SDK

For this walkthrough, we'll use the official TypeScript SDK. Don't worry, this won't be super technical. You are going to build a back-end service just like you have done hundreds of times before. The only difference is that now your application will be part of the MCP ecosystem.

You are not switching careers; you are still writing logic, structuring data, and managing APIs. The only shift is where you are plugging that code in. Instead of just serving HTTP requests, your code will be used to feed context into LLMs. You are becoming an AI-enabling developer.

I believe companies all over the world are going to start building and publishing their own MCP servers, just like how everyone now builds APIs. Soon, users will ask a question inside ChatGPT or Cursor, like "What are the pricing plans for Logic Based Labs?" and get a response, not because the model was trained on the website, but because you built an MCP server that gives them real-time, personalized data.

Step-by-Step Code Implementation

Here's how you can build a simple MCP server to fetch calendar data.

1. Project Setup First, initialize a Node.js project and install the necessary packages.

npm init -y
npm install mcp.js zod googleapis dotenv

In your package.json, add "type": "module" to use ES module syntax.

2. Creating the Server Create a server.js file. The first step is to import MCPServer and create an instance.

import { MCPServer, StdioServerTransport } from 'mcp.js';

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

3. Adding a Tool A "tool" is just a function you attach to the server. The name is critical because the AI uses it to understand the tool's purpose.

import { z } from 'zod';

server.tool(
  'getMyCalendarDataByDate',
  // ... see next steps
);

4. Defining Input with Zod Define the expected input and its structure using a validation library like Zod.

// Inside server.tool()
{
  input: z.object({
    date: z.string().date(),
  }),
},

5. The Callback Function This is the async function containing your core logic. It takes the validated input, fetches data, and returns the context in a specific format.

// Inside server.tool()
async (input) => {
  const data = await getMyCalendarDataByDate(input.date);
  return {
    content: [{
      type: 'text',
      text: JSON.stringify(data),
    }],
  };
}

6. The Controller Logic This is the heart of your server. This function connects to the external data source (in this case, the Google Calendar API), fetches the data, and handles any errors.

async function getMyCalendarDataByDate(dateString) {
  // ... logic to connect to Google Calendar API ...
  // ... fetch events for the given date ...
  // ... map events to a clean array of strings ...
  // ... return { meetings: [...] } or { error: '...' } ...
}

7. Setting up Transport For local communication, you need to tell the server to use standard I/O.

const transport = new StdioServerTransport();
server.connect(transport);

Your project is now ready to run!

Integrating with an AI Application (Cursor)

To connect your new server to an application like Cursor, you navigate to its MCP settings and add a custom server. You'll provide a JSON configuration that tells the application how to run your server.

{
  "name": "My Calendar Data",
  "command": "node",
  "arguments": ["/full/path/to/your/server.js"],
  "env": {
    "GOOGLE_API_KEY": "YOUR_API_KEY",
    "CALENDAR_ID": "YOUR_CALENDAR_ID"
  }
}

Once enabled, you can open the chat window and ask, "Do I have any meetings today?" The AI will intelligently call your MCP server, pass the current date, and receive the list of meetings. It will then translate the structured JSON response into a natural sentence like, "Yes, you have one meeting today: Meeting with Elon Musk at 4 p.m."

If you ask about a day with no meetings, it will receive an empty array and intelligently respond, "No, you do not have any meetings scheduled for tomorrow."

The Future is Composable AI

The MCP server is not a black box; it's a simple yet powerful standard. It allows developers to create reusable, composable components that bridge the gap between the vast world of data and the intelligence of LLMs.

For developers, this represents a significant opportunity to add value in the AI era, ensuring our skills remain relevant and in high demand. By applying the knowledge you already have, you can build amazing MCP servers for your company or your own products.

Join the 10xdev Community

Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.

Recommended For You

Up Next