AI Agents Aren't Magic: Connecting Primitives, MCP, and Agent Skills
Building AI agents can feel overwhelming. Every week brings a new acronym, protocol, or framework: Function Calling, Model Context Protocol (MCP), Agent Skills, Subagents, and CLI wrappers.
It is easy to wonder:
- Do these tools solve the same problem?
- Should you build an MCP server, write an Agent Skill, or just call an API?
The short answer: They do not compete. They operate at completely different layers of the stack.
Once you see where each piece fits, building AI agents becomes much simpler. Here is the mental model to understand how it all connects.
The 3-Layer Mental Model
Every production AI agent comes down to three distinct layers:
- The Core Engine (LLM Primitives): The brain and nervous system that decides what to do next.
- The I/O Layer (MCP & CLI Tools): The hands that interact with external services, databases, and APIs.
- The Procedure Layer (Agent Skills): The standard operating procedure (SOP) that teaches the agent how to execute domain tasks properly.
Primitives give the agent reasoning. MCP and tools give it hands. Skills give it an operating manual.
1. The Core Engine: LLM Primitives & The Execution Loop
At its core, an AI agent is surprisingly simple: a language model wrapped inside a stateful while loop.
It relies on four primitives:
- System Prompt: Sets role, behavior, and boundaries.
- Short-Term Memory: An array of messages (
user,assistant,tool) passed on every API call. - Tool Schemas: JSON declarations describing available functions to the model.
- Execution Loop: When the model outputs a function call, your code executes it and feeds the result back into memory until the task is complete.
Why Primitives Alone Aren’t Enough
If you write hardcoded tool functions directly inside a single script, you hit bottlenecks fast:
- Every external database or API requires custom integration code in your agent codebase.
- Tools cannot be reused across different clients (e.g., Cursor, Claude Desktop, internal CLI tools).
- Hardcoded integrations mix business logic, credentials, and agent execution together.
To decouple tools from the agent engine, we use Model Context Protocol (MCP).
2. The I/O Layer: Model Context Protocol (MCP) & CLI Tools
Model Context Protocol (MCP)
MCP is an open standard (introduced by Anthropic) that standardizes how AI agents connect to external tools and data sources over JSON-RPC.
Think of MCP as USB-C for AI applications:
- Instead of building database query logic directly into your agent, you run an MCP Server (e.g., for PostgreSQL, GitHub, or Slack).
- Any MCP Client (Cursor, Claude Desktop, or your custom agent) can plug into that server and get instant access to its tools and resources.
- Security isolation: Database credentials and API keys stay inside the MCP server. The model only receives function definitions and never handles sensitive secrets directly.
The Pragmatic Shortcut: CLI Tools
You do not always need to build an MCP server.
Many developer tools already have mature, authenticated command-line interfaces: gh (GitHub), docker, aws, stripe, or kubectl.
Because modern LLMs understand shell commands exceptionally well, you can simply let your agent execute terminal commands through a safe bash runner. If gh is already logged in on your machine, your agent can inspect issues, review pull requests, or check CI runs with zero extra API wrapper code.
3. The Procedure Layer: Agent Skills
If MCP provides the agent with hands, Agent Skills provide the handbook.
Having access to a tool is not enough. An agent needs domain context, business rules, and multi-step procedures to use tools effectively.
An Agent Skill is a structured package (often anchored by a SKILL.md file) containing instructions, guidelines, and reference scripts. It teaches an agent how to execute a specific task reliably.
Why Skills Matter
Consider an agent with access to a create_pull_request tool:
- Without a skill, it might open a PR with no description, bypass tests, and ping the wrong reviewers.
- With an Agent Skill, it follows clear operational steps:
- Read the repository’s contributing guidelines.
- Verify that local tests and linter pass.
- Format the PR title using Conventional Commits (
feat(auth): ...). - Summarize changes and tag the relevant CODEOWNERS.
Skills can be loaded dynamically when a user requests that specific task, keeping the default context window lean and focused.
When to Use What
| Integration Pattern | Best For | Strengths | Trade-offs |
|---|---|---|---|
| Native Function Call | 1–2 internal helper functions | Fast to prototype, zero setup | Locked to one script, not reusable |
| MCP Server | Shared tools, databases, enterprise APIs | Reusable across Cursor, Claude, and custom agents; secure | Requires running an MCP server process |
| CLI Tool + Skill | Developer tooling (gh, docker, aws) | Uses existing local auth; zero wrapper code | Requires CLI installed on host machine |
| Agent Skill (SOP) | Multi-step workflows and business logic | Enforces quality standards, constraints, and SOPs | Consumes context tokens when loaded |
4 Engineering Realities for Production Agents
Prototypes break when moving to production because unconstrained LLM loops make unreliable guesses. Production agents rely on four fundamentals:
-
Structured Workflows over Free-Form Loops: Instead of letting the model wander in an infinite loop, structure execution using proven patterns:
- Prompt Chaining: Breaking complex tasks into deterministic sequential steps (Draft -> Review -> Format).
- Routing: Classifying intent first, then delegating to a specialized prompt or subagent.
- Evaluator-Optimizer: Having one model generate output and a separate prompt evaluate and refine it.
-
Context Management: Message history grows fast. Use sliding windows (dropping older messages) or periodic summarization so token usage remains predictable.
-
Guardrails & Human-in-the-Loop (HITL): Never let an agent perform high-risk actions autonomously. Always require explicit human confirmation before dropping tables, sending emails, or running destructive shell commands.
-
Observability & Evals: Track token costs, latency, and tool call traces (using tools like Langfuse or OpenTelemetry). Build a benchmark suite of 20–30 test prompts to catch regressions before updating prompts or models.
Takeaway
AI agents aren’t magic. They are modular software systems:
- LLM Primitives are the brain and execution loop.
- MCP & CLI are the hands and external connections.
- Agent Skills are the standard operating procedures.
- Workflow Patterns & Guardrails make them reliable in production.
When you separate capabilities from procedures, building agents becomes a straightforward engineering challenge rather than an overwhelming puzzle.