Understanding LLMs, MCP, and AI Agents: Roles, Boundaries, and Collaboration
This article clarifies how large language models, the Model Context Protocol (MCP), and AI agents work together. It explains why real-time external context should not be hard-coded into prompts, defines the responsibilities of each layer, walks through a typical weather-query call flow, and provides practical guidance for designing MCP tools, enforcing security, adding observability, testing behavior, and rolling out agentic systems safely.
1. Where the Problem Comes From
Large language models are good at language understanding, planning, and generation. However, once training is complete, their parameters do not automatically gain access to the “current” external world. Weather forecasts, inventory levels, ticket status, and internal knowledge-base search results are all examples of context that changes over time.
If this kind of data is hard-coded into prompts, two problems appear. First, freshness cannot be guaranteed. Second, it becomes difficult to audit who accessed what data under which conditions.
Engineering therefore needs a clear boundary: the model handles reasoning, external capabilities handle data retrieval and execution, and the agent breaks multi-turn goals into executable steps. The Model Context Protocol, commonly abbreviated as MCP, is a general convention on this boundary. Its core goal is to let large models connect to external tools, data sources, and interfaces in a safe and controllable way, rather than allowing the model to directly hold credentials or make arbitrary network requests.
2. What Each Layer Is Responsible For
The collaboration can be viewed as three layers, not three interchangeable components.
2.1 Model: The Reasoning and Decision Core
The model receives system instructions, user goals, conversation history, and tool results returned through the protocol. It then outputs natural language or a structured next action.
The model does not store real-time data, and it should not be assumed to “know” interface addresses, authentication methods, or field meanings on its own. Its strengths are understanding intent, selecting tools, and explaining results. Its limitations include knowledge cutoff, hallucination, and a lack of natural constraints on side-effect operations.
Therefore, prompts are suitable for defining the role, the allowed tool scope, output formats, and refusal conditions. They are not suitable for storing expiring credentials or entire datasets.
2.2 MCP: The Protocol for Accessing Context and Tools
MCP describes how a model discovers and invokes external capabilities at runtime. A typical interaction includes:
- Listing available tools and their parameter schemas.
- Allowing the host to decide whether to approve a call.
- Passing the call request to the tool implementation.
- Writing the structured result back into the model context.
The protocol focuses on discovery, invocation, result return, and permission boundaries. It is not tied to a specific programming language or interface.
In plain terms, MCP lets the model “see” authorized real-time data, but the way it sees that data is through explicit calls one at a time, not through implicit crawling or unlimited context concatenation. Tool descriptions should include the name, purpose, inputs, outputs, and error semantics so that the model can make reasonable choices without fully understanding implementation details.
2.3 Agent: The Goal-Driven Orchestrator
An agent is not simply a larger model. It is a runtime built around the model. It maintains task state, decides when to ask the user for clarification, when to call tools, when to stop, and how to combine multiple tool results into a final answer.
An agent may include planning, memory, retries, and human confirmation. These strategies belong to application logic, not to the protocol itself.
The relationship can be summarized as follows: the agent states what needs to be accomplished, the model decides what to call next and with which parameters, MCP safely delivers that call to external capabilities and returns the result, and the agent then continues or concludes based on the result.
If any layer is missing, the system becomes distorted. Without a protocol, tool integration turns into private glue code. Without agent orchestration, the model can only answer one turn at a time. Without a model, the protocol is just ordinary remote invocation.
3. How a Call Flows Through the Chain
Consider the example: “Query the weather for a city over the next few hours and provide travel advice.” The flow is usually as follows:
- The user states the goal and constraints in natural language, such as the city, time range, and whether rain or wind is a concern.
- The agent passes the goal, existing context, and the list of available tools to the model. The tool list comes from capability declarations made by the MCP service at the start of the session or refreshed on demand.
- If the model lacks sufficient information, it should first generate a clarifying question. If it has enough information, it generates a tool call, such as a city name, coordinates, or administrative region code, along with the required elements such as temperature, precipitation, and wind speed.
- The host or agent runtime performs policy checks: whether the tool is on the allowlist, whether parameters are out of bounds, whether the call frequency exceeds limits, and whether sensitive location data is involved. Only after passing these checks is the call actually executed.
- The tool implementation requests data from the weather data source, handles timeouts, retries, and field validation, and returns structured results rather than stuffing an entire raw webpage or unfiltered response into the context.
- The model reads the result, generates advice, and clearly states uncertainty when data is missing or the source time is unclear.
- The agent records an input summary, result summary, latency, and error code for the call, supporting troubleshooting and evaluation, rather than keeping only the final paragraph.
This sequence reflects “the model proposes, the runtime approves, the tool executes, and the model explains.” Placing approval authority in the runtime is the key to safety and control. Approval authority should not be fully delegated to the model’s own claims.
4. How to Design a Weather MCP Tool
The weather scenario is suitable as a first tool because it is read-heavy, results are verifiable, and failure modes are clear. The following principles are recommended.
Inputs should be small and explicit. Prefer standardized place names or latitude/longitude coordinates, and limit the query time window. Ambiguous inputs should return recoverable errors, such as “city is not unique,” and the agent can decide whether to ask the user or use more precise parameters. The tool should not silently guess and report success.
Outputs should be structured and citable. They should include the observation or forecast time, time zone, temperature, precipitation probability, weather phenomena, wind speed and direction, and data update time. When generating advice, the model must be able to indicate which forecast time it is based on. Do not return only a prewritten marketing-style sentence, because the model cannot verify it and tests cannot assert against it.
Errors should be distinguishable. Network timeouts, upstream rate limiting, invalid parameters, and no data should use different error types. The agent can retry transient errors a limited number of times, while parameter errors should lead to clarification rather than infinite retries of the same request.
Permissions should be minimal by default. A weather tool usually only needs outbound read access to a specified data source. Credentials should be placed in the tool process or a secret management facility and injected through environment variables or short-lived credentials. They should not enter prompts or appear in model-visible tool descriptions. If the system later expands to “write to a calendar” or “send notifications,” that should be split into another tool and require separate human confirmation.
The following is an illustrative tool description and return structure. It only explains field responsibilities and is not a fixed interface from a particular vendor:
Tool name: get_weatherPurpose: Query a forecast summary for a location within a specified time rangeInputs:location: city or latitude/longitude stringhours: integer, recommended 1 to 48Outputs:location_resolved: resolved locationissued_at: data issue timeitems: array; each item contains time, temp_c, precip_prob, wind_speed, summaryErrors:AMBIGUOUS_LOCATION, INVALID_ARGUMENT, UPSTREAM_TIMEOUT, NO_DATA
System constraints on the agent side can be written as follows: only registered tools may be called; the model must not fabricate issued_at; if NO_DATA occurs or the location is ambiguous, confirm with the user first; advice must cite the time and elements returned by the tool; and the model must not add warning levels not provided by the tool.
5. How This Differs From Putting APIs Directly Into Prompts
Directly concatenating API documentation can work for a demo, but it is hard to scale. When the documentation changes, all prompts must be updated. The model may omit authentication headers or fabricate query parameters. Logs may not distinguish whether a number was invented by the model or returned by the upstream service.
MCP separates capability declaration, parameter validation, and execution. The model only sees the schemas it is allowed to see, while the runtime handles real requests. Tools can be upgraded, rate-limited, and replaced with different data sources independently, as long as the external schema remains compatible. In that case, the agent prompt does not need to be rewritten.
Another difference is testability. Tools can use fixed fixtures to return sunny, rainy, and timeout results, and tests can assert whether the model gives time-aware advice, asks for clarification, or stops retrying. This separates “language quality” from “tool contracts,” which is more stable than evaluating only a final natural-language paragraph.
6. Security, Observability, and Engineering Practices
For security, deny undeclared tools and extra parameters by default. Mask potentially sensitive inputs such as locations in logs. Limit the number of calls per session and upstream concurrency. Validate model-generated tool parameters against schemas before execution to avoid directly concatenating free text into queries. Separate read-only tools from side-effect tools by permission. Side effects must be auditable, revocable, or at least subject to human confirmation.
For observability, record at least the tool name, parameter summary, latency, result size, error type, and associated session identifier. Do not record full credentials or overly long raw responses. When a user complains that “the forecast is inaccurate,” it should be possible to replay the issued_at and items from that time to determine whether the issue came from the data source, parsing, or excessive model elaboration.
For evaluation, prepare three types of cases: sufficient information with a successful upstream response; ambiguous location; and upstream failure. Check whether the correct tool is called, whether there is unauthorized invocation, and whether the model fabricates weather when it fails. Tool results can be fixed as regression fixtures to avoid treating live weather fluctuations as model regression.
For deployment, decoupling the MCP service from the model service is clearer. Tool processes can be scaled and configured for outbound policies separately. The agent only depends on the capability list and call results. Cloud platforms such as Baidu AI Cloud can provide containers, logging, and monitoring for runtime and observability, but protocol semantics, tool contracts, and agent policies should still be defined and tested by the application.
7. Common Mistakes
Treating MCP as the model itself. The protocol does not increase the model’s intelligence; it only expands the context the model can obtain under controlled conditions. If tool results are poor, the model will also give poor advice.
Allowing the model to execute commands directly or hold long-lived credentials. This bypasses approval and auditing. If a prompt is manipulated, the impact is far greater than a single weather query.
Making one tool do too much. If querying, interpretation, database writes, and message sending are coupled together, permissions cannot be separated and failures cannot be localized. Interpretation should be left to the model, while state changes should be handled by independent tools that require confirmation.
Ignoring time and units. If temperature, wind speed, and time zone are not explicitly included in results, the model can easily mix units or present old forecasts as current conditions.
8. Recommended Rollout Order
Start with a read-only scenario whose results are verifiable, such as weather, exchange rates, or public schedules. Write the tool contract and error table, and complete contract tests with fixtures. Then register the tool with the agent and add system constraints: when a tool must be called, when clarification is required, and when to stop. After that, add approval, rate limiting, masked logging, and timeouts. Only then expand to write-capable features.
Following this order, the team does not end up with a single demo conversation, but with a regression-testable chain: the model makes judgments, MCP safely delivers real-time data into the context, and the agent advances the goal to a deliverable result. Once the division of responsibilities is clear, changing the model, changing the data source, or adding a new tool will not require rebuilding the entire system.
