Мақала Kazakh тілінде әлі жарияланбаған. 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
| Primitive | Controlled By | Purpose | Example |
|---|---|---|---|
| Tools | Model (with host policy) | Executable functions with JSON Schema input | search_campaigns, create_draft_template |
| Resources | Application / User | Read-only structured context addressed by URI | workspace://metrics/monthly-summary |
| Prompts | User | Reusable parameterized workflow templates | audit-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
- Authenticate every request with scoped OAuth tokens: never rely on unauthenticated query parameters or static shared keys for multi-tenant remote MCP servers.
- Enforce server-side tenant scoping: derive the active workspace from the verified token claims; reject any tool argument attempting to cross tenant boundaries.
- Separate read-only vs mutating capabilities: advertise read-only annotations and require explicit user confirmation before irreversible external writes.
- 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.
Бұл пайдалы болды ма?