MCP Overview

Understand the problem MCP solves, its communication architecture and tool call flow, and how it relates to function calling and REST APIs.

🎯 Introduction

Suppose your company has a product management system that employees open to check stock. You want them to ask an AI application, “How many units of product P100 are in stock?” and have the AI query the system and answer.

Function calling, which we covered earlier, can already do this. But what if the same lookup tool needs to work in both your own AI application and other applications such as Cursor?

This article uses that example to explain why MCP exists, its communication architecture, and how a tool call works.


🧱 Why MCP?

Connect to a Business System with Function Calling

Suppose the product system already exposes a REST API: GET /products/:id. Requesting /products/P100 returns:

{
    "id": "P100",
    "name": "Mechanical Keyboard",
    "stock": 12
}

With function calling, giving an AI application the ability to check stock requires two things:

  1. Define a get_stock tool that tells the model it checks stock and takes a product ID, id.
  2. Write an execution function that requests the REST API for that ID and returns the stock data to the model.

Although the REST API provides product data, the AI application still needs a tool definition and its execution function. Connecting several AI applications can mean repeating this work.

We can package the definition and execution function as shared code for our own applications. However, another application might use a different language or framework, or be a third-party application whose source we cannot change, making that code unusable directly.

The issue is that AI applications lack a standard way to integrate tools, even when the product API itself is reusable.

Connect to a Business System with MCP

MCP (Model Context Protocol) is an open standard protocol that gives AI applications a consistent way to connect to external systems and discover and use their tools, reference material, and prompt templates.

We can write a program that follows MCP, called an MCP server, and register the get_stock definition and execution function in it. AI applications communicate with this server through an MCP-compatible client. The existing product REST API needs no changes.

Here is a comparison of the two approaches:

Without MCP

AI app A
AI app B
get_stockDefine and execute tools separately in each app
get_stockDefine and execute tools separately in each app
Product system API

With MCP

AI app A
AI app B
MCP
MCP Serverget_stock
Product system API

Why can both applications use the tool? The server and clients follow the same communication rules: the server exposes a tool list, and clients retrieve definitions and call tools according to the protocol.

Once a connection is configured and the necessary permissions are granted, applications that support MCP tools can use get_stock without knowing how the server requests the product API internally.

If you have one AI application and the lookup function is already inside it, function calling alone is sufficient. MCP is more useful when tools need to be reused across applications or when integrating tools provided by other developers.


🧱 MCP Communication Architecture

Using Cursor connected to a product MCP server as an example, MCP has three roles:

  • Host: Cursor itself is a host. It receives user questions, interacts with the model, manages MCP connections, and handles tool calls.
  • Client: A module inside the host dedicated to MCP communication. It connects to a server, sends requests, and receives results; it is not a separate AI application.
  • Server: For example, our Node.js program, which provides product lookup tools and executes their business logic when it receives call requests.

If Cursor also needs to read documentation, it can connect to a documentation MCP server. One host can manage multiple clients, each corresponding to one server connection.

The following diagram shows these relationships:

User
Language model
Host · Cursor
Interact with the model and coordinate tools
MCP Client A
MCP Client B
MCP
MCP
Product MCP server
Document MCP server

MCP governs communication between client and server. The host can continue using its existing model API to interact with the model.


🧱 How MCP Works

With the roles established, let's see how Cursor discovers the product lookup tool and uses it to answer a question.

Retrieve Tool Definitions

Before the user asks a question, Cursor can connect to the product MCP server. Once initialization completes, if the server supports Tools, Cursor's MCP client can request the tool list with tools/list.

For example, the client sends this request (MCP message examples in this section omit outer protocol fields such as the JSON-RPC version and message ID):

{
    "method": "tools/list"
}

The server returns its tool list. If get_stock is the only registered tool, the result portion looks like this:

{
    "tools": [
        {
            "name": "get_stock",
            "description": "Look up stock by product ID",
            "inputSchema": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string",
                        "description": "Product ID"
                    }
                },
                "required": ["id"]
            }
        }
    ]
}

Each entry is a tool definition. Its inputSchema describes the arguments needed to call the tool, much like the definitions used with function calling. The host can convert these definitions into the format required by the model API and include them in model requests.

Cursor now has the tool definitions, but no stock query has run. Tool discovery and execution are separate operations.

Call a Tool and Receive Its Result

Now the user asks Cursor, “How many units of product P100 are in stock?”

First, look at how the request and result travel between programs after tool discovery. In this diagram, the host includes the MCP client, and arrows in the theme color represent MCP communication.

Language model
HostIncludes an MCP client
MCP server
Question + tool definitions
Request get_stock(P100)
tools/call · get_stock(P100)
Run the tool
Query the product API
Tool result: 12
Send the tool result
Product P100 has 12 units in stock.
Colored arrows show MCP messages. Gray arrows show exchanges between the host and the model.

Next, let's examine the data exchanged at each step.

Step 1: The Model Selects a Tool

The host sends the user's question and tool definitions to the model. The model identifies get_stock as suitable and returns the tool name and arguments. Formats differ between model APIs; only the essential information is shown here:

{
    "name": "get_stock",
    "arguments": { "id": "P100" }
}

Step 2: The Client Sends a Call Request

The host takes the tool call information returned by the model and sends a request to the server through its MCP client. This time it sends tools/call, with params specifying the tool and arguments:

{
    "method": "tools/call",
    "params": {
        "name": "get_stock",
        "arguments": { "id": "P100" }
    }
}

The server finds the execution function by tool name and passes it {"id":"P100"}. The function requests GET /products/P100 and extracts the stock quantity. The model's first response only expresses an intention to call a tool; the actual lookup happens here.

Step 3: The Server Returns the Tool Result

The server wraps the stock quantity in an MCP tool result. Here is a common text-content response (result portion only):

{
    "content": [
        {
            "type": "text",
            "text": "12"
        }
    ]
}

The client receives the result and passes it back to the host. The tool call is complete, but the user has not yet received a natural-language answer.

Step 4: The Model Generates an Answer

Following the model API's requirements, the host sends the tool result and relevant conversation context to the model again. The model answers using the stock data, and the host displays: “Product P100 has 12 units in stock.”


🧰 What Can an MCP Server Provide?

The example uses Tools. MCP servers can also provide Resources and Prompts.

Tools

Tools execute specific functions, such as checking stock, creating orders, or calculating product prices. They can perform read-only queries or modify data.

Resources

Resources provide readable material to AI applications. For example, a product server can expose a refund policy at a resource URI such as policy://refund.

When a user asks about refunds, the application can read the content at that URI through MCP and provide it to the model as context.

Both Tools and Resources can supply data, but they are used differently: a tool calls a function with arguments to perform a query or operation, whereas a resource is read through its URI. Resources need not be static files; they can contain dynamically generated data.

Prompts

Prompts provide reusable prompt or message templates. For example, a server might expose a product introduction template:

Write a product introduction for “product name” aimed at “target audience.”

The user selects the template and fills in “Mechanical Keyboard” and “programmers.” The application can then retrieve this message from the server:

Write a product introduction for Mechanical Keyboard aimed at programmers.

The application sends that message to the model to generate the introduction. Retrieving a template does not execute a model request.

The three capabilities can be summarized as follows:

CapabilityUsageExample
ToolsCall a toolCheck product stock
ResourcesRead materialRead a refund policy
PromptsRetrieve a prompt templateRetrieve a product introduction template

Typically, models request tool calls, applications select resources to read, and users select prompts. These are common interaction patterns, not mandatory restrictions. Whether a tool runs also depends on the application's permissions and confirmation policy.

A server does not have to provide all three capabilities, and a host may not support all of them.


🧱 MCP Transports

We have seen clients send tools/list and tools/call requests to servers. How do these requests actually reach them?

MCP defines message formats and interaction rules. A transport determines how those messages move between client and server. This course covers two standard transports: stdio and Streamable HTTP.

Streamable HTTP

An MCP server can run independently like an ordinary Express backend, listening on a port and exposing an HTTP URL such as http://127.0.0.1:3200/mcp.

Once the AI application is configured with this URL, its client exchanges MCP messages with the server over HTTP. Tool discovery and calls use the same MCP endpoint; individual tools do not need separate routes. This works for both local development and remote deployment. For example, a company can centrally deploy its product MCP server so multiple authorized AI applications share its tools.

stdio

Suppose a local MCP server has an entry file named index.mjs. Configure a startup command such as node index.mjs in Cursor (the actual configuration must use an accessible file path).

When connecting, the client starts this Node.js child process. It writes MCP messages to the process's standard input (stdin) through operating-system pipes and receives responses from standard output (stdout). Since the pipes already connect the processes, no IP address or port is needed to locate the server. index.mjs is the program's entry file, not a communication address.

This approach suits local tools that an AI application starts and manages directly. It requires no separate HTTP service or port management.

The transport changes how MCP messages travel between client and server, not how tools are defined or called. For example, both transports use tools/list for discovery and tools/call for calls.

The rest of this course primarily uses Streamable HTTP so local development and remote deployment share a transport, with stdio covered as a supplement for local tools.


⚖️ MCP, REST APIs, and Function Calling

These technologies solve different problems:

TechnologyResponsibility
Function callingLets the model tell the application which tool to call and which arguments to use
MCPStandardizes how AI applications integrate external capabilities
REST APIProvides an interface for programs to access a business system

They complement one another. This example uses a REST API because the product system already exposes one. A server that queries a database, reads files, or calls local functions directly does not need an additional REST API request.

MCP is also different from an AI agent. It handles access to external capabilities, not task planning or decisions about when to call another tool or finish a task. Those topics appear later in the AI Agent course.

Reference: MCP documentation.


❓ Knowledge Check

Q1: Does developing an MCP server require calling a model?

No. An MCP server can simply be a Node.js program that provides tools and material. If the tools themselves do not depend on a model, no model API key is needed, and they can be tested independently.

Q2: Do you still need function calling with MCP?

In this stock lookup example, they work together: function calling lets the model express a tool call request, and MCP lets the application discover and call external tools. If an application already knows which tool it needs, it can call it directly through MCP without requesting a model first.


🧪 Exercise

Suppose your company already has an order lookup REST API. Consider these scenarios:

  1. The company has one internally developed AI application that needs to look up order status by order ID. Must it develop an MCP server?
  2. The company wants multiple MCP-compatible AI applications to query order status. How should the MCP server be designed? Which role actually requests the order REST API?

Check: The first scenario can use function calling directly. For the second, develop an MCP server with an order lookup tool and configure each application to connect to it. The server executes the tool and requests the order REST API.


🎉 You now understand MCP's purpose, communication architecture, and tool call flow. Next, you can start building your own MCP server.