К содержанию
Статья ещё не опубликована на языке Russian. Показана версия на English.

Model Context Protocol (MCP) Fundamentals: Hosts, Clients, Servers, Tools, and Security

2 мин на чтение

Before the Model Context Protocol (MCP), connecting M AI applications to N external data sources or SaaS tools required building M x N bespoke integrations. MCP introduces a clean client-server JSON-RPC protocol so any compliant AI host can discover and call tools exposed by any MCP server.

MCP Core Primitives

PrimitiveControlled ByPurposeExample
ToolsModel (with host policy)Executable functions with JSON Schema inputsearch_campaigns, create_draft_template
ResourcesApplication / UserRead-only structured context addressed by URIworkspace://metrics/monthly-summary
PromptsUserReusable parameterized workflow templatesaudit-ad-spend-efficiency

Transport Options

  • stdio: ideal for local CLI tools and developer workflows running as a child process on the user's machine.
  • Streamable HTTP: designed for remote, multi-tenant cloud MCP servers behind standard HTTPS load balancers with OAuth 2.1 bearer tokens.

Security Checklist for Production MCP Servers

  1. Authenticate every request with scoped OAuth tokens: never rely on unauthenticated query parameters or static shared keys for multi-tenant remote MCP servers.
  2. Enforce server-side tenant scoping: derive the active workspace from the verified token claims; reject any tool argument attempting to cross tenant boundaries.
  3. Separate read-only vs mutating capabilities: advertise read-only annotations and require explicit user confirmation before irreversible external writes.
  4. Bound response payload sizes: return concise summaries and pagination cursors rather than megabytes of raw logs that overflow the host model's context window.
ts
export interface McpToolResult {
  content: Array<{ type: "text"; text: string }>;
  isError?: boolean;
}

export function formatBoundedMcpResult(data: unknown, maxChars = 16_000): McpToolResult {
  const serialized = JSON.stringify(data, null, 2);
  if (serialized.length <= maxChars) {
    return { content: [{ type: "text", text: serialized }] };
  }
  return {
    content: [
      {
        type: "text",
        text: `${serialized.slice(0, maxChars)}\n... [truncated; pass narrower filters or smaller limit]`,
      },
    ],
  };
}

Next: learn when agents should pause and hand control to a person in Human-in-the-Loop (HITL) Patterns.

Было ли это полезно?