liveBook · Manning

Chapter 3: Actions with Model Context Protocol for AI agents

What you will learn in chapter 3 of AI Agents in Action, Second Edition

The introduction presents MCP as a standard way to connect agents with tools and describes how agent workflows can themselves be offered as reusable tools.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction presents MCP as a standard way to connect agents with tools and describes how agent workflows can themselves be offered as reusable tools.

Key terms: Model Context Protocol (MCP), standard protocol, agent tools, consumable MCP servers, agentic workflows, tools, reused like components

3.1 Understanding MCP fundamentals for agent development

Introduces MCP as an open standard for connecting AI systems to external services.

Key terms: MCP, open standard, JSON-RPC 2.0, external services

3.1.1 The standardization problem MCP solves

This section explains why fragmented integrations made agents brittle and how MCP addresses that problem by standardizing interactions with external systems.

Key terms: fragmented tool integration, JSON schema, tool-call envelope, inconsistent data access, complex agent orchestration, access controls, monitoring, MCP, unified protocol, standardized components

3.1.2 MCP architecture: Clients, servers, and services

This section explains how MCP standardizes an agent’s connection to external services and identifies the client, server, and service roles in that connection.

Key terms: MCP, MCP server, service, per-provider schema and call-format work, MCP client, JSON-RPC 2.0, discovery, tools, resources, prompts

3.1.3 Core components: Tools, resources, and prompts

This section distinguishes MCP tools, resources, and prompts by their purposes and who typically chooses when to use them, then explains why some clients expose only tools.

Key terms: tools, resources, prompts, discoverable endpoints, list_tools, model-controlled, user-controlled, application-controlled, MCP client, OpenAI Agents SDK

3.1.4 MCP deployment patterns for agents

This section compares local and remote MCP server deployments and explains that a hybrid setup means an agent uses a mix of servers, not that an individual server is hybrid.

Key terms: local deployment, STDIO transport, remote deployment, SSE transport, hybrid deployments, local servers, remote servers, protocol level

3.1.5 MCP powers the functional agent layers

This section shows that MCP can connect agents to capabilities across multiple functional layers, not only to tools for taking actions.

Key terms: MCP, functional agent layers, connection pattern, tools and actions, reasoning and planning, knowledge and memory, evaluation and feedback, sequential thinking server

3.2 Getting started with MCP servers

Introduces Claude Desktop as a way to connect to MCP servers and explains why the same basic pattern applies across MCP clients.

Key terms: Claude Desktop, MCP servers, tools, prompts, resources, MCP, clients, configuration surface, capability primitives, configuration file

3.2.1 Coding up an MCP server for Claude

This section shows how to expose an existing Python tool through an MCP server and try it in Claude Desktop.

Key terms: @mcp.tool(), tool schema, signature, docstring, return type annotations, MCP CLI tools, Claude Desktop, Developer, get_research_sources, permission

3.2.2 Using the MCP inspector

This section shows how to inspect and debug an MCP server, then clarifies why the example server uses STDIO transport.

Key terms: MCP inspector, tool list, decorator-generated schema, JSON-RPC traffic, initialization errors, absolute path, Tools page, Run Tool, get_research_sources, history of operations

3.2.3 Understanding MCP transport types

The section identifies MCP’s two transport types and explains why the distinction matters when building or consuming MCP clients and servers.

Key terms: MCP, STDIO, SSE, transport types

3.2.4 From desktop to agents: The key differences

This section distinguishes an MCP-using assistant from an agent by the agent’s autonomous, multi-step loop, then explains the risks that autonomy creates and the safeguards it calls for.

Key terms: assistant, agent, autonomy, loop, permission prompts, tool selection, destructive actions, data exfiltration, cost runaways, prompt injection through tool outputs

3.3 Using MCP servers for agents

This section defines agent actions, outlines ways agents connect to MCP servers, and explains when MCP is worth its overhead.

Key terms: MCP servers, agent actions, tool, resource, MCP server, STDIO, SSE over HTTP, subprocess, separation of concerns, in-process function calls

3.3.1 Using agents with local MCP servers over STDIO

This section explains how an agent can run a local MCP server over STDIO and why MCP lets agents and servers written in different languages work together.

Key terms: STDIO, MCP server, subprocess, get_research_sources, language agnostic, MCP protocol, portable integration layer

3.3.2 Using local MCP servers over SSE with agents

This section explains why an agent might connect to a separately running MCP server over SSE and what changes from an in-process STDIO connection.

Key terms: MCP server, HTTP server, SSE, STDIO, FastMCP, URL, command, server implementation

3.3.3 Connecting to the standard MCP servers

This section shows how to use a standard MCP Filesystem server and why its file access must be handled carefully.

Key terms: shared servers, MCPServerStdio, MCP Filesystem server, npx, isolate the folder, validate and verify, MCP tools

3.4 Building MCP servers for agents

The section uses a time-tracker agent to show how journal tools preserve information across fresh invocations, while noting the limits of its in-memory implementation.

Key terms: record_event, load_journal, journal, temporary or scratchpad memory, fresh invocation, context overload, module-level in-memory list, shared state, single process

3.4.1 Converting tools to an MCP server

The section moves the time-travel tracker’s journal tools into an MCP server and explains how the resulting interface separates the agent from tool implementations.

Key terms: MCP server, MCP decorator, tool discovery, separation of concerns, interface contract, tool schema, implementation

3.4.2 Consuming MCP servers locally or remotely

This section shows how an agent consumes journaling tools from an MCP server over STDIO or SSE, and explains the practical difference between the two connections.

Key terms: MCP server, STDIO, SSE, with clause, journaling tools, in-memory journal, duplicate journal results, MCP servers, encapsulating tools, code reuse

3.5 Exercises

Five exercises practice inspecting an MCP server, connecting agents over STDIO and SSE, restricting exposed tools, and making an agent available as an MCP tool.

3.6 Summary

Summarizes how MCP standardizes agent capabilities, supports different connection and deployment patterns, and enables composable agent systems.

Where this is used later

Concepts explained in this chapter

← Chapter 2: Core components: Large language models, prompting, and agents Chapter 4: Architecting and building multi-agent systems →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.