top of page

How MCP Works: A Deep Dive into Model Context Protocol Workflow

Writer: Chandan Rajpurohit
Chandan Rajpurohit
3 hours ago
5 min read

Large Language Models (LLMs) have become increasingly powerful. They can understand natural language, generate code, summarize documents, and solve complex problems. However, an AI model has one important limitation: it cannot independently interact with external applications, databases, APIs, or local files unless an application provides access to those capabilities.


For example, imagine asking an AI assistant:

  • Retrieve customer information from a database.

  • Find open issues in a GitHub repository.

  • Read a document from Google Drive.

  • Execute a Python script.

  • Fetch information from an external API.


How does the AI assistant communicate with these external systems?


This is where Model Context Protocol (MCP) comes into the picture.


MCP provides a standardized communication mechanism that allows AI applications to connect with external tools, resources, and services.


But how does MCP actually work behind the scenes?


In this article, we will understand how its components communicate, and walk through the complete lifecycle of an MCP request, from user input to tool execution and response generation.


How MCP Works


How MCP Communication Works


Now let's understand how MCP components communicate internally.


MCP uses JSON-RPC 2.0 as its message format.


JSON-RPC is a lightweight remote procedure call protocol that allows two systems to exchange structured requests, responses, and notifications.


An MCP message typically contains information such as:

  • JSON-RPC version.

  • Request ID.

  • Method name.

  • Parameters.

  • Result or error.


For example, an MCP request may look like this:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/list",
  "params": {}
}

Here:

  • jsonrpc identifies the JSON-RPC version.

  • id identifies the request.

  • method specifies the operation.

  • params contains the request parameters.


The MCP Server processes the request and returns a corresponding response.


Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "tools": [
      {
        "name": "get_customer",
        "description": "Retrieve customer information"
      }
    ]
  }
}

This response tells the client that a tool named get_customer is available.


The actual tool definition can contain additional information, including an input schema.


This structured communication allows MCP clients and servers to interact consistently.


MCP Transport Mechanisms


MCP defines how messages are exchanged between clients and servers.


Two important transport mechanisms are:


4.1 STDIO Transport


STDIO stands for Standard Input/Output. It is commonly used when an MCP Server runs as a local process.


The MCP Host launches the server as a subprocess and communicates through:

  • Standard Input (stdin).

  • Standard Output (stdout).


For example, a local filesystem MCP Server may run as a Python or Node.js process.


The Client sends protocol messages through stdin, and the Server returns responses through stdout.


STDIO is particularly useful for local development tools and desktop applications.


4.2 Streamable HTTP Transport


Streamable HTTP is used when the MCP Server runs remotely. It allows MCP clients to communicate with remote servers using HTTP.


It also supports streaming responses when required.


This is useful for:

  • Cloud-hosted MCP Servers.

  • Enterprise applications.

  • Remote database integrations.

  • Distributed AI systems.


Earlier MCP implementations also used HTTP with Server-Sent Events (SSE). Streamable HTTP is the modern HTTP transport mechanism.


Step-by-Step: How MCP Works Behind the Scenes


This is the most important part of understanding MCP.


Let's take a practical example.


Imagine asking an AI assistant:

"Find all open issues in my GitHub repository and summarize them."


The AI assistant needs to retrieve information from GitHub.


Here is how the complete process works.


Step 1: User Sends a Request

The user enters a natural-language request into the AI application.


For example:

"Find all open issues in my GitHub repository."


The MCP Host receives the request and sends it to the LLM for processing. The LLM determines that external GitHub information is required.


Step 2: MCP Client Establishes a Connection

The MCP Host has an MCP Client configured to communicate with a GitHub MCP Server. The Client establishes a connection using the configured transport mechanism.


Depending on the implementation, this may use STDIO or Streamable HTTP.


Step 3: Initialization

Once the connection is established, the Client and Server perform an initialization handshake. The Client sends an initialize request.


An example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "initialize",
  "params": {
    "protocolVersion": "2025-06-18",
    "capabilities": {},
    "clientInfo": {
      "name": "my-ai-client",
      "version": "1.0.0"
    }
  }
}

The Server responds with its supported protocol version, capabilities, and server information.


Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "protocolVersion": "2025-06-18",
    "capabilities": {
      "tools": {}
    },
    "serverInfo": {
      "name": "github-server",
      "version": "1.0.0"
    }
  }
}

The Client and Server can now establish which protocol features they support.


After initialization, the Client sends an initialized notification to indicate that initialization is complete.


Step 4: Tool Discovery

After initialization, the MCP Client can discover which tools the Server provides. It sends a tools/list request.


Example:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "tools/list",
  "params": {}
}

The Server returns a list of available tools.


For example:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "tools": [
      {
        "name": "search_issues",
        "description": "Search GitHub issues",
        "inputSchema": {
          "type": "object",
          "properties": {
            "repository": {
              "type": "string"
            },
            "state": {
              "type": "string",
              "enum": ["open", "closed", "all"]
            }
          },
          "required": ["repository"]
        }
      }
    ]
  }
}

Now the MCP Client knows that the GitHub Server provides a tool named search_issues.


It also knows what parameters the tool expects.


Step 5: LLM Selects the Appropriate Tool

The Host makes the discovered tool information available to the LLM through its tool-calling interface.


The LLM evaluates the user's request and determines that search_issues is the appropriate tool.

It generates the required arguments.


For example:

{
  "repository": "my-project",
  "state": "open"
}

The Host application coordinates the tool call through the MCP Client.


An important distinction: the LLM does not directly connect to the MCP Server. The Host and Client manage that communication.


Step 6: Tool Execution

The MCP Client sends a tools/call request to the MCP Server.


Example:

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "tools/call",
  "params": {
    "name": "search_issues",
    "arguments": {
      "repository": "my-project",
      "state": "open"
    }
  }
}

The MCP Server receives the request. It validates the arguments and executes the corresponding operation.


Behind the scenes, the Server might communicate with the GitHub API to retrieve the requested issues.


The MCP Server acts as an intermediary between the MCP Client and GitHub.


Step 7: MCP Server Returns the Result

After executing the operation, the MCP Server sends the result back to the MCP Client.


For example:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "content": [
      {
        "type": "text",
        "text": "Found 5 open issues in the repository."
      }
    ],
    "isError": false
  }
}

The Client receives the response and makes it available to the Host.


Step 8: LLM Generates the Final Response

The Host provides the tool result to the LLM as part of the ongoing interaction.


The LLM processes the returned information and generates a natural-language response.


For example:

"I found 5 open issues in your GitHub repository. Two are related to authentication, one concerns database performance, and two involve UI improvements."


The response is displayed to the user.


Complete MCP Workflow


The entire process can be summarized as:

  1. User sends a request.

  2. Host sends the request to the LLM.

  3. LLM identifies the need for an external tool.

  4. MCP Client communicates with the MCP Server.

  5. Client and Server initialize and negotiate capabilities.

  6. Client discovers available tools.

  7. Host makes tool information available to the LLM.

  8. LLM selects the appropriate tool.

  9. Host coordinates the tool call through the Client.

  10. MCP Server executes the operation.

  11. Server returns the result.

  12. LLM generates the final response.


This is how MCP connects AI reasoning with external application capabilities.

Conclusion


Model Context Protocol provides a standardized communication mechanism that allows AI applications to interact with external tools, resources, and services.


Its architecture separates responsibilities between the Host, Client, and Server.


The Client manages protocol communication, while the Server exposes external capabilities through standardized interfaces.


Through initialization, capability negotiation, tool discovery, tool execution, and response handling, MCP enables AI applications to interact with external systems without requiring every integration to be built from scratch.


Understanding the complete MCP workflow is essential for developers who want to build AI-powered applications, tool integrations, and agent-based systems.


MCP is not an AI model or an API replacement. It is the protocol layer that helps connect AI applications with the external capabilities they need.


References


bottom of page