MCP Protocol (Model Context Protocol)

MCP (Model Context Protocol) is an open standard protocol that defines how AI models communicate with external tools, data sources, and applications.

MCP is a standardized communication protocol that allows AI applications to discover, call, and use external capabilities through MCP Servers.

MCP Architecture Overview

Three Core Primitives (Resources/Tools/Prompts)

Comparison of MCP and REST API

A2A Protocol (Agent-to-Agent)

MCP Python SDK: Server initialization

MCP Python SDK: @app.tool() decorator (装饰器)

MCP Python SDK: @app.resource()

Claude Desktop Connection

Databricks MCP Server

MCP ecosystems: Public MCP Server Directory

Three Core Primitives

The Model Context Protocol (MCP) defines three core primitives that servers can expose to clients: Tools, Resources, and Prompts. These are the fundamental building blocks that enable rich interactions between clients, servers, and language models.

CN: 模型上下文协议(MCP)定义了三个核心原语,服务器可以通过它们向客户端暴露能力:Tools(工具)、Resources(资源)和 Prompts(提示)。这些是支持客户端、服务器和语言模型之间进行丰富交互的基本构建块

MCP servers expose three types of primitives to AI applications:

PrimitiveENCNControl
PromptsPre-defined templates or instructions that guide language model interactions预定义的模板或指令,用于引导语言模型的交互User-controlled (用户控制)
ResourcesStructured data or content that provides additional context to the model结构化的数据或内容,为模型提供额外的上下文Application-controlled (应用控制)
ToolsExecutable functions that allow models to perform actions or retrieve information可执行的函数,允许模型执行操作或检索信息Model-controlled (模型控制)

4.1 Tools

工具—— “执行者 / The Doers”

Tools are executable functions that perform actions or computations. They are callable functions that the AI agent invokes to take an action or retrieve data. The agent reads the tool’s name and description and decides when to call it based on the user’s request.

CN: Tools(工具)是执行动作或计算的可执行函数。它们是 AI 代理调用的可调用函数,用于执行操作或检索数据。代理读取工具的名称和描述,并根据用户的请求决定何时调用它

Core Characteristics

FeatureDescription
Model-controlledThe LLM decides when and whether to call the tool
Typed parametersAccept typed, named parameters
Can write dataCan have side effects — write, update, delete
Has descriptionDescription guides agent behavior
Counts as a tool callConsumes tool-call budget
Best forActions, queries with parameters, dynamic operations

CN:

特征说明
模型控制LLM 决定何时以及是否调用
类型化参数接受带类型、带名称的参数
可写入数据可以有副作用 —— 写入、更新、删除
有描述描述引导代理的行为
算作一次工具调用消耗工具调用预算
最适合动作、带参数的查询、动态操作

When to Use Tools?

  • The agent needs to decide when and whether to call it
  • The operation requires parameters beyond a simple identifier
  • The capability involves writes, state changes, or dynamic queries
  • You want the tool description to guide agent behavior

CN:

  • 代理需要决定何时以及是否调用它
  • 操作需要的参数不仅仅是简单的标识符
  • 能力涉及写入、状态变更或动态查询
  • 你希望工具描述来引导代理的行为

4.2 Resources

资源—— “知识库 / The Knowledge Stores”

Resources are read-only data endpoints identified by a URI. They are structured data or content that provides additional context to the model. Resources expose stable reference data that the agent or client can fetch without any decision-making.

CN: Resources(资源)是由 URI 标识的只读数据端点。它们是为模型提供额外上下文的结构化数据或内容。Resources 暴露稳定的参考数据,代理或客户端无需任何决策即可获取

Core Characteristics

FeatureDescription
Application-controlledClient manages what data to attach
Read-onlyCannot write data — no side effects
URI-identifiedAccessed via a stable, predictable URI
No descriptionNo description to guide agent; just data
No tool-call costDoes NOT count as a tool call
Best forReference lookups, pre-loaded context

CN:

特征说明
应用程序控制客户端管理要附加哪些数据
只读不能写入数据 —— 无副作用
URI 标识通过稳定、可预测的 URI 访问
无描述没有描述来引导代理;只是数据
无工具调用成本不算作工具调用
最适合参考查找、预加载的上下文

When to Use Resources

  • The data is read-only and identified by a stable, predictable URI
  • The information is needed frequently and does not change mid-session
  • You want the client or agent to load context without consuming tool-call budget
  • The dataset is small enough to fit in context

CN:

  • 数据是只读的,由稳定、可预测的 URI 标识
  • 信息被频繁需要,且在会话期间不会变化
  • 你希望客户端或代理加载上下文而不消耗工具调用预算
  • 数据集足够小,可以放入上下文中

Common Examples

  • db://tables → list of all table names
  • db://schemas → schema definitions
  • file://config.json → configuration file content
  • git://history → git commit history
  • Company handbooks, policy documents
  • Product catalogs, customer records

CN:

  • db://tables → 所有表名的列表
  • db://schemas → 模式定义
  • file://config.json → 配置文件内容
  • git://history → git 提交历史
  • 公司手册、政策文件
  • 产品目录、客户记录

4.3 Prompts

提示—— “行为模板 / The Behavior Templates”

Prompts are pre-defined templates or instructions that guide language model interactions. They are named instruction templates that define the AI’s behavior in a specific domain. Prompts explain how to combine tools for real-world tasks and provide guidance on how to approach problems.

CN: Prompts(提示)是指导语言模型交互的预定义模板或指令。它们是命名的指令模板,定义 AI 在特定领域的行为。Prompts 解释如何组合工具来完成实际任务,并提供如何处理问题的指导

Core Characteristics

FeatureDescription
User-controlledUser explicitly selects which prompt to use
Read-onlyCannot write data — no side effects
Has descriptionDescription guides agent behavior
No tool-call costDoes NOT count as a tool call
Best forSystem instructions, workflow recipes

CN:

特征说明
用户控制用户明确选择使用哪个提示
只读不能写入数据 —— 无副作用
有描述描述引导代理的行为
无工具调用成本不算作工具调用
最适合系统指令、工作流配方

When to Use Prompts

  • You want to provide step-by-step sequences for common tasks
  • You want to explain domain-specific concepts
  • You want to mention available resources and when to use them
  • You want to set tone, style, and persona for the AI

CN:

  • 你想为常见任务提供分步序列
  • 你想解释领域特定的概念
  • 你想提及可用的资源以及何时使用它们
  • 你想为 AI 设定语气、风格和人格

Common Examples

  • System messages to set global tone and constraints
  • Task-specific instructions embedded in context
  • Reusable templates for summarization, extraction, or translation
  • Pre-built directives enforcing format, safety, and validation rules
  • Slash commands in Claude Code: /mcp__my-server__analyze-customer

CN:

  • 设置全局语气和约束的系统消息
  • 嵌入上下文的任务特定指令
  • 用于摘要、提取或翻译的可重用模板
  • 强制执行格式、安全和验证规则的预构建指令
  • Claude Code 中的斜杠命令:/mcp__my-server__analyze-customer

Key Takeaways

要点 (Key Point)ENCN
三类原语MCP defines three primitives: Tools, Resources, and PromptsMCP 定义三个原语:Tools、Resources 和 Prompts
Tools = 执行者Tools are executable functions that perform actionsTools 是执行动作的可执行函数
Resources = 知识库Resources are read-only data endpoints providing contextResources 是提供上下文的只读数据端点
Prompts = 行为模板Prompts are instruction templates guiding AI behaviorPrompts 是指导 AI 行为的指令模板
控制层次Prompts=User-controlled, Resources=App-controlled, Tools=Model-controlledPrompts=用户控制,Resources=应用控制,Tools=模型控制
Tools 有副作用Tools can write data and have side effectsTools 可以写入数据,有副作用
Resources 只读Resources are read-only, no side effectsResources 是只读的,无副作用
Resources 不消耗工具调用Resources do NOT count as tool callsResources 不算作工具调用
Prompts 不消耗工具调用Prompts do NOT count as tool callsPrompts 不算作工具调用
装饰器模式Use @server.list_tools() and @server.call_tool() to define tools使用 @server.list_tools() 和 @server.call_tool() 定义工具
资源 URI 标识Resources are identified by URIs (e.g., db://tables)Resources 由 URI 标识(如 db://tables)
提示带参数Prompts can accept arguments for dynamic templatingPrompts 可以接受参数进行动态模板化
三者协同Resources provide data, Prompts provide guidance, Tools do the workResources 提供数据,Prompts 提供指导,Tools 执行工作