MCP Server

定义

MCP Server(Model Context Protocol Server)是遵循 MCP 协议的服务端实现,作为大语言模型与外部世界之间的桥梁。它封装了工具(Tools)、资源(Resources)和提示(Prompts)三大能力,使 AI Agent 能够调用外部服务、访问动态数据、执行特定操作。

核心功能

应用场景

MCP Server 广泛用于 AI Agent 开发场景:

示例

// MCP Server 示例 (Python)
from mcp.server import Server
from mcp.server.stdio import stdio_server

server = Server("example-database")

@server.list_tools()
async def list_tools():
    return [
        Tool(
            name="query_users",
            description="查询用户列表",
            inputSchema={"type": "object", "properties": {"limit": {"type": "number"}}}
        )
    ]

@server.call_tool()
async def call_tool(name: str, arguments: dict):
    if name == "query_users":
        return await db.query("SELECT * FROM users LIMIT ?", arguments["limit"])

相关术语

📚 推荐阅读

→ 首页 → 🛠️ 工具教程 → 📖 术语百科 → 📚 踩坑实录 → 🧠 Agent记忆系统 → ⚙️ Agent配置指南