Skip to content

Tools, MCP và Gateway

Tầng tools định nghĩa AI app hoặc agent được phép làm gì bên ngoài model. Nó bao gồm gọi API, đọc file, query database, mở ticket, sửa code, gửi email và gọi internal systems.

Đây là nơi capability biến thành risk. Một model chỉ trả lời text thì bị giới hạn. Một model gọi được tools tạo ra giá trị lớn hơn, nhưng cần authorization, policy, audit và rollback boundaries.

MCP không thay thế LangChain, LangGraph, Hermes hay AI-DLC. MCP là protocol/tool integration layer. Các framework khác có thể sử dụng MCP.

Layer này sở hữu điều gì

Mối quan tâmKiểm soát điều gì
Tool schemaModel được sinh arguments nào
Tool discoveryTool nào visible với agent/user nào
AuthenticationIdentity nào được dùng để gọi tool
AuthorizationAction được request có được phép không
ApprovalCó cần human confirmation không
Rate limitTool usage được phép đến mức nào
AuditTool nào được gọi, bởi ai, input gì, vì sao
IsolationTool có thể ảnh hưởng local files, prod systems hoặc sensitive data không

Function calling vs MCP vs OpenAPI tools

MechanismÝ nghĩa
Function callingModel sinh structured tool arguments
OpenAPI toolTool schema đến từ HTTP API contract
MCPStandard protocol để expose tools/resources/prompts cho agents
Tool gatewayBoundary do tổ chức kiểm soát cho policy, auth, rate limit và audit

Function calling là hình dạng ở phía model. MCP là protocol để expose tool và context surfaces cho AI apps. OpenAPI là cách phổ biến để mô tả HTTP services có sẵn. Tool gateway là enterprise control plane khi nhiều agents và nhiều tools cần policy nhất quán.

Tool gateway pattern

mermaid
flowchart TB
    A[Agent hoặc AI app] --> B[Tool gateway]
    B --> C[MCP servers]
    B --> D[OpenAPI services]
    B --> E[Internal scripts]
    B --> F[Database tools]
    G[Policy engine] -. allow or deny .-> B
    H[Audit log] -. records .-> B
    I[Human approval] -. gates .-> B

Gateway hữu ích khi cần một nơi enforce:

  1. Tool nào available cho agent nào.
  2. Action nào cần approval.
  3. Data class nào được gửi đến tool nào.
  4. Call nào phải log.
  5. Credentials và scopes nào được dùng.
  6. Tool nào read-only, write-capable hoặc destructive.

Permission và approval model

Action classVí dụControl
Read-only low risksearch docs, read public metadataallow với logging
Read-only sensitiveread customer record, inspect incident logschỉ allow bằng scoped identity
Write low riskcreate draft ticket, update local branchallow với trace
Write medium riskupdate issue status, create pull requestapproval hoặc review gate
Destructive/high riskdelete resource, rotate secrets, deploy prodexplicit human approval và break-glass policy

Default đúng không phải là "agent không được dùng tools." Default đúng là "tools được scope theo risk."

Tool safety checklist

  • Mỗi tool có name rõ và description hẹp chưa?
  • Arguments có typed và validated không?
  • Tool có read-only by default không?
  • Credential đã scope minimum permission chưa?
  • User identity có được propagate khi cần không?
  • Destructive actions có bị block hoặc approval-gated không?
  • Tool inputs/outputs có được log và redact sensitive fields không?
  • Prompt có bị chặn việc tự bịa quyền tool không?
  • Retry có idempotent không?
  • Write actions có rollback hoặc compensation path không?

Hướng dẫn adoption step-by-step

  1. Inventory tools agent cần: filesystem, shell, Git, issue tracker, CRM, database, cloud APIs.
  2. Classify từng tool: read-only, write, destructive hoặc sensitive.
  3. Bắt đầu với read-only tools và local development tools.
  4. Bọc tool calls sau gateway hoặc policy layer trước khi expose production systems.
  5. Thêm approval gates cho write và destructive actions.
  6. Log tool call intent, arguments, actor, result và trace ID.
  7. Thêm eval cases cho unsafe tool requests.
  8. Review tool access trong mỗi rollout agent capability mới.

Failure modes

Failure modeDấu hiệuCách làm tốt hơn
Broad shell access trong productionagent có thể mutate systems ngoài ý muốntách dev harness tools khỏi prod app tools
Tool descriptions mơ hồmodel gọi sai toolnarrow schemas và examples
Không approval cho writestạo ticket/email/deploy nhầmapproval theo risk tier
Tool output leak secretslogs hoặc prompts chứa sensitive dataredaction và data classification
Xem MCP là governancecó protocol nhưng không policythêm gateway, RBAC, audit và approval
Không audit logkhông thể điều tra incidenttrace mọi tool call

References

Built as a static bilingual AI engineering stack guide.