mcp-workflow.md•2.77 kB
# MCP Workflow Overview
The Model Context Protocol (MCP) enables AI-powered applications (like LLMs) to securely and dynamically interact with external tools and data sources. Below is a step-by-step workflow illustrating how MCP operates in practice.
---
## 1. Startup & Handshake
- **MCP Client** (embedded in the AI host, e.g., Claude Desktop, Cursor, or a web LLM) starts up.
- It reads its configuration (e.g., `mcp.json`) to discover which MCP Servers to connect to.
- The client establishes connections to each server, either:
- **Locally** via STDIO (for fast, secure, on-device communication), or
- **Remotely** via HTTP + SSE (for cloud or networked servers).
---
## 2. Capability Discovery
- The MCP Client sends a JSON-RPC request to each server to enumerate available **tools** (functions), **resources** (data access), and **prompts** (templates).
- Each MCP Server responds with a manifest describing:
- Tool names and descriptions
- Input/output schemas (for validation and UI generation)
- Any required permissions or user approvals
---
## 3. Registration
- The MCP Client registers all discovered capabilities with the host application.
- The host (and the LLM) now "knows" what tools and data are available for use.
---
## 4. User/LLM Initiates a Request
- When the LLM determines it needs external data or functionality (e.g., "get current weather"), it signals the MCP Client.
- The client may prompt the user for approval, depending on the tool's security settings.
---
## 5. Request Handling
- The MCP Client formats the request as a JSON-RPC 2.0 message and sends it to the appropriate MCP Server.
- Example request (simplified):
```json
{
"jsonrpc": "2.0",
"id": 1,
"method": "get_weather",
"params": { "location": "San Francisco" }
}
```
---
## 6. Authorization
- The MCP Server may require explicit user approval before executing sensitive actions.
- The client handles any necessary user prompts and relays approval status.
---
## 7. Execution
- The MCP Server performs the requested operation (e.g., calls an API, queries a database, fetches a file).
- It returns the result as a structured JSON-RPC response.
```json
{
"jsonrpc": "2.0",
"id": 1,
"result": { "temperature": "18°C", "condition": "Cloudy" }
}
```
---
## 8. Result Integration
- The MCP Client delivers the result back to the host application and LLM.
- The LLM incorporates the fresh data into its response to the user.
---
## 9. Extensibility & Security
- New MCP Servers can be added at any time to provide new tools or data sources.
- All tool invocations are subject to user/host approval for security.
- Hosts can connect to multiple servers; servers can support multiple hosts.
---