All articles

API, MCP Server, or AI Agent? Part 3: AI Agents and Complete Architecture

In Parts 1 and 2, we explored REST APIs (stateless, client-driven interfaces) and MCP Servers (AI-native interfaces with discovery and structured tools). Now we'll complete the picture with AI Agents—the autonomous decision layer that orchestrates everything.


Back to Part 2


AI Agents: The Autonomous Decision Layer

An AI agent is fundamentally different from both REST APIs and MCP servers. While those are service interfaces, an agent is an autonomous system that reasons, plans, and acts. In the MCP ecosystem, agents are hosts or clients that consume services—but they're much more than simple API consumers.

Core Characteristics of AI Agents

Autonomous Decision-Making: Agents interpret user intent, decide what actions to take, select appropriate tools, and execute plans without step-by-step human guidance.

Goal-Oriented Behavior: Given a high-level objective ("Plan a weekend trip to Seattle"), an agent breaks it down into subtasks, gathers necessary information, and synthesizes a solution.

Context-Aware Reasoning: Agents maintain conversation history, remember previous decisions, and use context to inform current actions. They understand that "check the weather there" refers to a previously mentioned location.

Tool Orchestration: Agents don't just call one API—they coordinate multiple tools, handle errors, retry with different strategies, and combine results from disparate sources.


🔹 AI Agent (in MCP context) - Detailed Breakdown

An AI Agent in this context is typically an MCP Client or Host that connects to MCP Servers to:

  • Retrieve contextual data
  • Execute tools/functions
  • Use prompts to guide interactions
  • Make decisions and act autonomously

Characteristics:

  • Goal-oriented: Solves tasks using context and tools
  • Agentic behavior: May include recursive reasoning, planning, and tool use
  • Context-aware: Uses MCP to enrich its understanding
  • Flexible: Can connect to multiple MCP servers

Example: AI Agent Using MCP Weather Server

Here's an AI agent that uses our MCP weather server:

from anthropic import Anthropic
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
import asyncio

class TravelPlannerAgent:
    def __init__(self, api_key: str):
        self.client = Anthropic(api_key=api_key)
        self.mcp_session = None
        self.conversation_history = []
        
    async def connect_mcp_servers(self):
        """Connect to MCP weather server"""
        server_params = StdioServerParameters(
            command="python",
            args=["weather_mcp_server.py"]
        )
        
        self.mcp_session = await stdio_client(server_params)
        self.available_tools = await self.mcp_session.list_tools()
        print(f"Connected with {len(self.available_tools)} tools")
        
    async def process_user_request(self, user_message: str):
        """Process user request with autonomous tool selection"""
        self.conversation_history.append({
            "role": "user",
            "content": user_message
        })
        
        # Agent reasoning loop
        while True:
            response = self.client.messages.create(
                model="claude-sonnet-4-20250514",
                max_tokens=4096,
                messages=self.conversation_history,
                tools=[
                    {
                        "name": tool.name,
                        "description": tool.description,
                        "input_schema": tool.inputSchema
                    }
                    for tool in self.available_tools
                ]
            )
            
            # Check if agent wants to use a tool
            if response.stop_reason == "tool_use":
                tool_use = next(
                    block for block in response.content 
                    if block.type == "tool_use"
                )
                
                print(f"Agent calling: {tool_use.name}")
                
                # Execute tool via MCP
                tool_result = await self.mcp_session.call_tool(
                    tool_use.name,
                    tool_use.input
                )
                
                # Add to history and continue reasoning
                self.conversation_history.append({
                    "role": "assistant",
                    "content": response.content
                })
                self.conversation_history.append({
                    "role": "user",
                    "content": [{
                        "type": "tool_result",
                        "tool_use_id": tool_use.id,
                        "content": tool_result[0].text
                    }]
                })
                continue
            else:
                # Agent has final answer
                self.conversation_history.append({
                    "role": "assistant",
                    "content": response.content
                })
                
                final_response = next(
                    block.text for block in response.content 
                    if hasattr(block, "text")
                )
                return final_response

# Usage
async def main():
    agent = TravelPlannerAgent(api_key="your-api-key")
    await agent.connect_mcp_servers()
    
    response = await agent.process_user_request(
        "I'm planning a weekend trip to Seattle. What should I pack?"
    )
    print(f"Agent: {response}")

asyncio.run(main())

What Makes This "Agentic"

When a user says "I'm planning a weekend trip to Seattle. What should I pack?":

  1. Intent Understanding: Agent interprets this as needing weather information
  2. Tool Selection: Agent examines available tools and decides to call get_forecast with city="Seattle", days=2
  3. Tool Execution: Agent calls the tool via MCP
  4. Synthesis: Agent reasons about results (55°F, rainy) and generates recommendations: "Pack layers, waterproof jacket, umbrella"
  5. Context Retention: For follow-up "How does the weather compare to Miami?", agent remembers Seattle context

None of the decision logic was explicitly programmed. The agent autonomously decided which tools to call, determined parameters, handled sequencing, and synthesized information. The tool schemas, execution scaffolding, and stop conditions were defined, but the reasoning about when and why to use tools emerged from the model's capabilities.


The Three-Way Comparison

FeatureREST APIMCP ServerAI Agent
RoleExposes data/operationsProvides structured resources/toolsMakes decisions and executes tasks
ProtocolHTTP/RESTJSON-RPC 2.0Varies (often multiple)
StateStatelessStateful (persistent connection)Stateful (maintains context)
DiscoveryOpenAPI/SwaggerCapability negotiationDynamic tool learning
AutonomyNone (client decides)None (responds to requests)High (decides what to do)
Target ConsumerApplications, developersAI systems, agentsEnd users, other agents
CommunicationClient makes HTTP requestsClient makes JSON-RPC callsInitiates calls to tools/servers
SecurityAPI keys, OAuthUser consent + tool safetyPolicy enforcement + oversight
ComposabilityVia API gatewaysVia MCP ecosystemVia tool/server connections
ReusabilityService-specificHighly reusable across agentsTask-specific
ExamplesWeather API, Order APIGitHub MCP, Slack MCPClaude, chatbot, assistant

Similarities

  • Both MCP and Agents use JSON-RPC for communication
  • Both support modular, composable integration
  • Both are designed to enhance LLM capabilities with external context
  • All three can coexist in the same architecture

When to Use What

Use REST API when:

  • You need traditional web services for human-facing apps
  • Clients are non-AI (mobile apps, web frontends)
  • You need broad HTTP tooling compatibility

Use MCP Server when:

  • You want to expose structured data/tools to AI agents
  • You need standardized, secure AI integration
  • Multiple AI agents will consume your service
  • Discovery and capability negotiation are important

Use AI Agent when:

  • You need intelligent behavior (reasoning, planning, interaction)
  • Users provide high-level goals without step-by-step instructions
  • Multi-tool orchestration is required
  • Natural language interface is desired

Architecture: How They Work Together

┌─────────────────────────────────────────────────┐
│              End User                           │
│         (Natural Language)                      │
└────────────────┬────────────────────────────────┘
                 │
                 ▼
┌─────────────────────────────────────────────────┐
│           AI Agent (Host)                       │
│   • Reasoning & Planning                        │
│   • Context Management                          │
│   • Tool Selection                              │
│   • Response Synthesis                          │
└────────────────┬────────────────────────────────┘
                 │
                 │ MCP Protocol (JSON-RPC 2.0)
                 │
      ┌──────────┴──────────┬──────────┬──────────┐
      │                     │          │          │
┌─────▼────────┐  ┌────────▼────┐  ┌──▼────┐  ┌──▼────────┐
│  MCP Server  │  │ MCP Server  │  │  MCP  │  │    MCP    │
│   (Weather)  │  │  (Calendar) │  │ Server│  │   Server  │
│  Resources   │  │  Tools      │  │ Tools │  │ Resources │
│  Tools       │  │  Resources  │  │       │  │           │
└─────┬────────┘  └────────┬────┘  └───┬───┘  └─────┬─────┘
      │                    │            │            │
      ▼                    ▼            ▼            ▼
┌──────────┐        ┌───────────┐  ┌────────┐  ┌─────────┐
│ REST API │        │  Database │  │  File  │  │ Search  │
│(External)│        │           │  │ System │  │  API    │
└──────────┘        └───────────┘  └────────┘  └─────────┘

In this architecture:

  1. Users interact with AI Agent using natural language
  2. AI Agent decides which MCP Servers to query
  3. MCP Servers expose structured interfaces
  4. Underlying Systems (REST APIs, databases, etc.) power MCP servers
  5. MCP Servers act as adaptation layers

Common Misconceptions

Misconception 1: "MCP Server = AI Agent"

Reality: MCP servers are passive providers; AI agents are active consumers. Servers wait for requests; agents initiate and decide.

Misconception 2: "MCP Replaces REST APIs"

Reality: They're complementary. MCP often wraps REST APIs. Both can coexist—REST for traditional clients, MCP for AI agents.

Misconception 3: "Any Service Using GPT Is Agentic"

Reality: Using an LLM for text generation doesn't make a system agentic. Agentic requires autonomous decision-making and tool orchestration.

Misconception 4: "MCP Is Only for Claude"

Reality: MCP is an open protocol. Any AI system can implement MCP clients or servers.


Real-World Example: Customer Support

Scenario: Automated customer support with order lookup, shipping tracking, and issue resolution.

Architecture:

  • User: "Where's my order? It's been 5 days"
  • AI Agent: Understands intent, needs order history
  • Orders MCP Server: Provides order_lookup tool
  • Agent: Calls tool, discovers order delayed
  • Shipping MCP Server: Provides track_shipment tool
  • Agent: Calls tool, gets tracking info
  • Agent: Synthesizes response with proactive compensation offer

Components:

  • REST APIs: Existing order/shipping backends (unchanged)
  • MCP Servers: Wrap REST APIs for AI consumption
  • AI Agent: Orchestrates multiple services autonomously
  • User: Gets sophisticated support without human agent

Mental Model Summary

Here's the essential mental model to retain:

REST APIs expose capabilities - They say "here are operations you can perform"

MCP Servers describe how capabilities can be used by AI - They say "here's what these operations mean, when to use them, and how they fit together"

AI Agents decide when and why to use them - They reason "given the user's goal, I should call these tools in this order"

The progression is: capability → semantic description → autonomous reasoning.


Conclusion

The distinction between REST APIs, MCP servers, and AI agents isn't academic—it's fundamental to building effective AI-powered systems.

REST APIs are the foundation layer for web services and traditional applications.

MCP Servers are the adaptation layer that makes services accessible to AI agents with discovery, structure, and safety.

AI Agents are the intelligence layer that reasons, plans, and acts autonomously to achieve goals.

The future isn't choosing one over the others—it's understanding how they work together. Build REST APIs for core services. Wrap them in MCP servers for AI consumption. Create AI agents that orchestrate those servers.

As AI systems become more capable, these patterns will become standard practice. Understanding these distinctions today provides a foundation for building effective AI-powered systems.


References

  1. Anthropic. (2025). "Model Context Protocol Specification." https://modelcontextprotocol.io/specification/2025-03-26
  2. Anthropic. (2025). "MCP Python SDK Documentation." https://github.com/anthropics/anthropic-sdk-python
  3. Fielding, R. T. (2000). "Architectural Styles and the Design of Network-based Software Architectures."
  4. OpenAPI Initiative. (2024). "OpenAPI Specification v3.1.0." https://spec.openapis.org/oas/latest.html

Back to Part 2


Shaped in collaboration with Claude, an AI assistant by Anthropic, during rainy Pacific Northwest afternoons where engineering problems meet philosophical questions.

Continue Reading

← Back to Part 2

The MCP layer that agents call into.

← Back to Part 1

The REST baseline this series evolves from.

AI, Agents, and the Art of Orchestration

Production agent architecture: skills vs monolithic agents, context window management, multi-model routing, and why verification beats prompt engineering.

Agentic AI Is Distributed Systems — Part 2

Agents will sometimes get it wrong, and your monitoring won't catch it. Four engineering patterns for making semantic failures visible and recoverable.