docs/api-reference/protocol-overview.mdx
2024-11-20 12:24:08 -05:00

86 lines
No EOL
3.3 KiB
Text

---
title: "Protocol overview"
description: "Learn about the core concepts and architecture of the Model Context Protocol (MCP)"
---
The Model Context Protocol (MCP) is a standardized protocol that enables AI applications to securely access external data sources and tools. MCP follows a client-server architecture where AI applications act as clients that can connect to one or more MCP servers.
## Key features
<CardGroup cols={2}>
<Card title="Flexible integration" icon="puzzle-piece">
Connect AI models to any data source or tool through a unified protocol
</Card>
<Card title="Secure access" icon="shield-check">
Control what data and capabilities are exposed to AI systems
</Card>
<Card title="Composable design" icon="cubes">
Combine multiple servers together for enhanced functionality
</Card>
<Card title="Standard interface" icon="code">
Build integrations that work consistently across AI applications
</Card>
</CardGroup>
## Core concepts
MCP defines several key primitives that form the foundation of the protocol:
<CardGroup cols={2}>
<Card title="Resources" icon="book">
Data that can be loaded as context for the AI model. Resources have URIs and can contain text or binary data.
</Card>
<Card title="Tools" icon="screwdriver-wrench">
Functions that the AI can invoke to perform actions, like writing files or calling APIs.
</Card>
<Card title="Prompts" icon="message">
Pre-defined prompt templates that help guide AI interactions in specific ways.
</Card>
<Card title="Sampling" icon="rotate">
Allows servers to request completions from the AI model through the client.
</Card>
</CardGroup>
## Protocol flow
### Connection and initialization
When a client connects to an MCP server, they go through the following initialization sequence:
<Steps>
<Step title="Client connects">
The client establishes a connection to the server using one of the supported transports.
</Step>
<Step title="Initialize request">
The client sends an initialize request containing its capabilities and protocol version.
</Step>
<Step title="Server response">
The server responds with its own capabilities and supported protocol version.
</Step>
<Step title="Initialized notification">
The client sends an initialized notification to indicate setup is complete.
</Step>
</Steps>
After initialization, the client can begin using the server's resources, tools, and other capabilities.
### Transport options
MCP supports multiple transport mechanisms for client-server communication:
<AccordionGroup>
<Accordion title="Standard input/output (stdio)">
- Server process reads from stdin and writes to stdout
- Messages are newline-terminated JSON
- Client manages server process lifetime
- State is lost when process exits
</Accordion>
<Accordion title="WebSocket">
- Bidirectional communication over WebSocket protocol
- Client and server negotiate using 'mcp' subprotocol
- Can connect to remote servers
- State persists until disconnect
</Accordion>
<Accordion title="Server-Sent Events (SSE)">
- Server pushes messages via SSE
- Client sends messages via HTTP POST
- Supports cross-origin restrictions
- State persists until SSE connection closes
</Accordion>
</AccordionGroup>