MCP从零开始:快速数据
目的:学习通过将工具扩展到可重用的代理工作流(ADW也称为Prompts w/tools)来构建强大的模型上下文协议(MCP)服务器。
快速数据
Quick Data是一个MCP服务器,它为您的代理提供对.json和.csv文件的任意数据分析。 我们使用快速数据作为具体用例来具体实验MCP服务器元素:提示>工具>资源。 看 快速数据mcp 有关MCP服务器的详细信息
引导性问题
我们尝试了三个主要问题:
- 我们如何通过使用工具、资源和提示来最大化定制MCP服务器的价值?
- 构建MCP服务器的最佳代码库架构是什么?
- 我们能否构建一个可用于快速构建MCP服务器的代理工作流(带工具的提示)?
了解MCP组件
MCP服务器有三个主要的构建块,扩展了AI模型的功能:
工具
什么:AI模型可以调用的函数来执行操作。
何时使用:当你希望AI根据你的领域特定用例在中低原子级别上做一些事情时。
示例:
@mcp.tool()
async def create_task(title: str, description: str) -> dict:
"""Create a new task."""
# AI can call this to actually create tasks
return {"id": "123", "title": title, "status": "created"}资源
什么:AI模型可以读取和访问的数据。
何时使用:当你想让人工智能读取信息时——用户配置文件、配置、状态或任何数据源。
示例:
@mcp.resource("users://{user_id}/profile")
async def get_user_profile(user_id: str) -> dict:
"""Get user profile by ID."""
# AI can read this data to understand users
return {"id": user_id, "name": "John", "role": "developer"}鼓励
什么:启动特定类型讨论的预构建对话模板。
何时使用:当你想为特定领域的用例提供通用、可重复的工作流程的AI结构化起点时。
示例:
@mcp.prompt()
async def code_review(code: str) -> str:
"""Start a code review conversation."""
# AI gets a structured template for code reviews
return f"Review this code for security and performance:\n{code}"快速决策指南
- AI需要采取行动吗? → Use 工具
- 需要AI来读取数据吗? → Use 资源
- 需要可重用代理工作流(ADW)? → Use 鼓励
快速设置
要使用快速数据MCP服务器:
- 导航到MCP服务器目录:
cd quick-data-mcp/- 为您的MCP客户端进行配置:
# Copy the sample configuration
cp .mcp.json.sample .mcp.json
# Edit .mcp.json and update the --directory path to your absolute path
# Example: "/Users/yourusername/path/to/quick-data-mcp"- 测试服务器:
uv run python main.py看 快速数据mcp/README.md 获取完整的设置和使用文档。
资源
- MCP客户端:https://modelcontextprotocol.io/clients
- Claude代码资源支持Github问题:https://github.com/anthropics/claude-code/issuesç/545
精通AI编码
学习用AI编写基础代码 人工智能编码原理
跟随 IndyDevDan youtube频道 了解更多AI编码技巧和窍门。
使用最好的代理编码工具: 克劳德代码
