跳转到内容

MCP 概览

MCP (Model Context Protocol) 是一个将 AI 模型连接到外部工具和数据源的标准。Greentic 对 MCP 的实现支持:

  • 在沙箱化 WASM 环境中执行 tool
  • 安全访问外部 API
  • 数据库查询
  • 文件系统操作

WASM Sandboxing

MCP tools 在隔离的 WebAssembly 环境中运行,以保障安全。

Tool Discovery

自动完成 tool 注册和能力声明。

Type Safety

WIT interfaces 确保类型安全的 tool 调用。

Observability

内置 tracing 和 logging,用于观察 tool 执行情况。

LLM (with tool use)
▼ Tool Call Request
┌─────────────────────────────────┐
│ greentic-mcp │
│ (MCP Executor / WASI Bridge) │
└─────────────────────────────────┘
┌─────────────────────────────────┐
│ WASM Tool Component │
│ (Sandboxed execution) │
└─────────────────────────────────┘
▼ Tool Result
Back to LLM
tools/database-query.yaml
name: database_query
description: Query the customer database
parameters:
- name: query
type: string
description: SQL query to execute
required: true
- name: limit
type: integer
description: Maximum rows to return
default: 10
returns:
type: array
items:
type: object
- id: query_orders
type: mcp-tool
config:
tool: "database_query"
parameters:
query: "SELECT * FROM orders WHERE customer_id = '{{customer_id}}'"
limit: 5
output: orders_result
next: process_orders
- id: agent_step
type: llm
config:
model: "gpt-4"
system_prompt: "You are a helpful assistant with database access."
tools:
- database_query
- send_email
- create_ticket
tool_choice: "auto"
next: handle_response

Greentic 提供了多个内置 MCP tools:

Tool描述
http_request发起 HTTP 请求
database_query查询数据库
file_read读取文件(沙箱内)
file_write写入文件(沙箱内)
send_email发送邮件
create_ticket创建支持工单

所有 MCP tools 都在 WASM 沙箱中运行:

  • 不能直接访问文件系统
  • 除非显式授予,否则不能访问网络
  • 内存隔离
  • CPU 时间限制

tools 需要声明所需能力:

capabilities:
- network:outbound # Can make outbound requests
- filesystem:read # Can read files in sandbox