LangChain/Advanced
Advanced12 min

Model Context Protocol (MCP)

MCP is an open protocol for exposing tools, resources, and prompts to LLMs. Use langchain-mcp-adapters to connect any MCP server to a LangChain agent.

Quick Reference

  • pip install langchain-mcp-adapters fastmcp
  • MultiServerMCPClient — connect to multiple MCP servers (stdio or HTTP)
  • client.get_tools() → pass directly to create_agent
  • Interceptors = middleware for MCP tool calls (inject context, retry, gate access)
  • Stateless by default — use client.session() for stateful (server maintains context across calls)

What Is MCP

Model Context Protocol (MCP) is an open protocol that standardizes how applications expose tools, resources, and prompts to LLMs. Instead of writing custom integrations for every external service, you wrap it in an MCP server once and any MCP-compatible agent can use it. LangChain agents use MCP tools via the langchain-mcp-adapters library.

MCP PrimitiveWhat It ProvidesLangChain Converts To
ToolsExecutable functions (query DB, call API, etc.)LangChain tools — usable in any agent
ResourcesData sources (files, DB records, API responses)Blob objects with text/binary content
PromptsReusable prompt templates with argumentsLangChain message lists