How LLM use MCPs?
Source: Dev.to
Overview
To understand how a Large Language Model (LLM) knows what is in a Model Context Protocol (MCP) server, think of the LLM not as a person who “knows” things, but as a chef who is handed a menu right before cooking. The LLM doesn’t actually “know” the MCP exists until you send a message.
Step‑by‑step process
-
Start a session
In an MCP‑enabled application (e.g., Claude Desktop or Cursor), the MCP client (the app) contacts the MCP server (the tool) using the standard requesttools/list. -
Server response
The server returns a list of every tool it provides. For each tool it supplies:- Name
- Description
- JSON Schema (the arguments the tool requires)
-
Inject tool list into the prompt
The MCP client inserts this list directly into the LLM’s prompt context, typically as part of the system instructions. -
Hidden instruction block
When the LLM receives your message, it also sees a hidden block of text such as: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). -
User query
You ask, for example, “What’s the weather in Tokyo?” -
Tool selection
The LLM recognizes that it doesn’t know the weather but sees a tool (get_weather) that matches the intent. -
Structured tool call
Following its training on “Tool Use” or “Function Calling” patterns, the LLM stops generating regular text and outputs a structured snippet:{ "call": "get_weather", "args": { "location": "Tokyo" } } -
Client processes the call
- The client detects the snippet in the LLM’s output.
- It pauses the LLM and sends the specified request to the MCP server.
- The server runs the actual code and returns the result to the client.
-
Result fed back to the LLM
The client feeds the result back into the LLM’s context. -
Final answer
The LLM reads the result and replies, e.g., “The weather in Tokyo is 15 °C and sunny.”