DEV Community

Cover image for How LLM use MCPs?
Hitesh
Hitesh

Posted on

How LLM use MCPs?

To understand how a Large Language Model (LLM) knows what is in a Model Context Protocol (MCP) server, it helps to think of the LLM not as a person who "knows" things, but as a chef who is handed a menu right before they start cooking.

The LLM doesn't actually "know" the MCP exists until the moment you send a message. Here is the step-by-step breakdown of how that discovery happens:

1. The "Handshake" (Discovery)

When you start a session in an MCP-enabled application (like Claude Desktop or Cursor), the MCP Client (the app) talks to the MCP Server (the tool) behind the scenes using a standard request called tools/list.

  • The server replies with a list of every tool it has.
  • For each tool, it provides a Name, a Description, and a JSON Schema (the specific arguments it needs).

2. The Context Injection

This is the "aha!" moment. The MCP Client takes that list of tools and injects it directly into the LLM's prompt context (usually in the system instructions).

When the LLM receives your message, it also sees a hidden block of text that looks like this:

"You have access to the following tools:

  • get_weather: Get current weather. Parameters: location (string).
  • query_postgres: Run SQL on the DB. Parameters: query (string)."

3. Intent Matching

When you ask, "What's the weather in Tokyo?", the LLM doesn't "run" the tool. Instead, it looks at its instructions and realizes: "I don't know the weather, but I see a tool called get_weather that matches this intent."

Because the LLM is trained to follow "Tool Use" or "Function Calling" patterns, it stops generating regular text and instead outputs a structured snippet:
{ "call": "get_weather", "args": { "location": "Tokyo" } }

4. The Execution Loop

  1. The Client sees this snippet in the LLM's output.
  2. The Client pauses the LLM and sends that specific request to the MCP Server.
  3. The Server runs the actual code and sends the result back to the Client.
  4. The Client feeds that result back to the LLM.
  5. The LLM reads the result and finally gives you the answer: "The weather in Tokyo is 15°C and sunny."

Top comments (0)