|
| 1 | +# MCP Agents Example |
| 2 | + |
| 3 | +This example demonstrates an agent-based architecture using MCP (Model Context Protocol). The example consists of three components: |
| 4 | + |
| 5 | +1. **Project Analyst Agent** - An MCP server that provides tools for analyzing project issues and priorities |
| 6 | +2. **Personal Assistant Agent** - An MCP server that acts as a client to other agents while providing its own tools |
| 7 | +3. **Chat CLI** - A command-line interface that connects to the Personal Assistant agent |
| 8 | + |
| 9 | +## Architecture |
| 10 | + |
| 11 | +This example demonstrates a layered architecture of MCP agents where each component can act as both a client and a server. |
| 12 | + |
| 13 | +```mermaid |
| 14 | +graph LR |
| 15 | + User[User] -->|Interacts with| CLI[Chat CLI] |
| 16 | + CLI -->|Connects to| PA[Personal Assistant Agent] |
| 17 | + PA -->|Connects to| PRA[Project Analyst Agent] |
| 18 | + |
| 19 | + classDef component fill:#f9f,stroke:#333,stroke-width:2px; |
| 20 | + classDef user fill:#bbf,stroke:#333,stroke-width:2px; |
| 21 | + |
| 22 | + class CLI,PA,PRA component; |
| 23 | + class User user; |
| 24 | +``` |
| 25 | + |
| 26 | +### Elicitation Flow |
| 27 | + |
| 28 | +When a tool needs additional information from the user, the elicitation request flows through the chain: |
| 29 | + |
| 30 | +```mermaid |
| 31 | +sequenceDiagram |
| 32 | + participant User |
| 33 | + participant CLI as Chat CLI |
| 34 | + participant PA as Personal Assistant |
| 35 | + participant PRA as Project Analyst |
| 36 | + |
| 37 | + User->>CLI: "Help prioritize project issues" |
| 38 | + CLI->>PA: call_tool("chat", {message}) |
| 39 | + |
| 40 | + PA-->>CLI: ElicitRequest(message, schema) |
| 41 | + Note right of PA: Need project name from user |
| 42 | + |
| 43 | + CLI-->>User: Display prompt & collect input |
| 44 | + User-->>CLI: Provide project name |
| 45 | + |
| 46 | + CLI-->>PA: ElicitResult(response) |
| 47 | + |
| 48 | + PA->>PRA: call_tool("analyze_issues", {project}) |
| 49 | + |
| 50 | + PRA-->>PA: ElicitRequest(message, schema) |
| 51 | + Note right of PRA: Ask if okay to proceed |
| 52 | + |
| 53 | + Note over PA: Handle internally: auto-confirm |
| 54 | + |
| 55 | + PA-->>PRA: ElicitResult({proceed: true}) |
| 56 | + |
| 57 | + PRA-->>PA: ToolResult(content) |
| 58 | + PA-->>CLI: ToolResult(content) |
| 59 | + CLI-->>User: Display result |
| 60 | +``` |
| 61 | + |
| 62 | +## Installation and Usage |
| 63 | + |
| 64 | +### 1. Set up the Project Analyst Agent |
| 65 | + |
| 66 | +```bash |
| 67 | +# From the project-analyst directory |
| 68 | +cd project-analyst |
| 69 | +uv venv .venv |
| 70 | +source .venv/bin/activate # On Windows: .venv\Scripts\activate |
| 71 | +uv add --dev -e . |
| 72 | +# No need to run it directly - it will be started by the Personal Assistant |
| 73 | +``` |
| 74 | + |
| 75 | +### 2. Set up the Personal Assistant Agent |
| 76 | + |
| 77 | +```bash |
| 78 | +# From the personal-assistant directory |
| 79 | +cd personal-assistant |
| 80 | +uv venv .venv |
| 81 | +source .venv/bin/activate # On Windows: .venv\Scripts\activate |
| 82 | +uv add --dev -e . |
| 83 | +# No need to run it directly - it will be started by the Chat CLI |
| 84 | +``` |
| 85 | + |
| 86 | +### 3. Run the Chat CLI |
| 87 | + |
| 88 | +```bash |
| 89 | +# From the chat-cli directory |
| 90 | +cd chat-cli |
| 91 | +uv venv .venv |
| 92 | +source .venv/bin/activate # On Windows: .venv\Scripts\activate |
| 93 | +uv add --dev -e . |
| 94 | +uv run mcp-chat-cli |
| 95 | +``` |
| 96 | + |
| 97 | +This will start the entire agent chain. The Chat CLI will launch the Personal Assistant, which will in turn launch the Project Analyst. |
| 98 | + |
| 99 | +## Example Conversation |
| 100 | + |
| 101 | +``` |
| 102 | +You: Hello |
| 103 | +Assistant: Hello! I'm your personal assistant. How can I help you today? |
| 104 | +
|
| 105 | +You: What can you do? |
| 106 | +Assistant: I can help you with various tasks: |
| 107 | +1. Analyze projects and their issues (try: "Analyze the issues for the Python SDK project") |
| 108 | +2. Review priorities for projects |
| 109 | +3. Provide information and assistance |
| 110 | +4. Answer questions |
| 111 | +
|
| 112 | +What would you like help with? |
| 113 | +
|
| 114 | +You: Analyze the Python SDK project |
| 115 | +Assistant: Here's my analysis of project 'Python': |
| 116 | +
|
| 117 | +# Project Issues Analysis for Python |
| 118 | +
|
| 119 | +## Summary |
| 120 | +- Total issues analyzed: 5 |
| 121 | +- Open issues: 4 |
| 122 | +- Closed issues: 1 |
| 123 | +
|
| 124 | +## Issues by Priority |
| 125 | +- high: 2 |
| 126 | +- medium: 2 |
| 127 | +- low: 1 |
| 128 | +
|
| 129 | +## Issues by Type |
| 130 | +- bug: 2 |
| 131 | +- feature: 1 |
| 132 | +- improvement: 1 |
| 133 | +- task: 1 |
| 134 | +
|
| 135 | +## Top Open Issues |
| 136 | +- #1: Bug for Python component 3 (Priority: high) |
| 137 | +- #2: Feature for Python component 2 (Priority: medium) |
| 138 | +- #3: Improvement for Python component 1 (Priority: high) |
| 139 | +- #5: Task for Python component 4 (Priority: low) |
| 140 | +
|
| 141 | +## Recommended Next Steps |
| 142 | +1. Address high priority issues first |
| 143 | +2. Review issues with dependencies |
| 144 | +3. Re-estimate effort for any issues that have been open for a long time |
| 145 | +``` |
| 146 | + |
| 147 | +## Features Demonstrated |
| 148 | + |
| 149 | +This example demonstrates several key MCP features: |
| 150 | + |
| 151 | +1. **Elicitation** - Agents can request information from users (or other agents) during tool execution |
| 152 | +2. **Progress Reporting** - Agents can report progress during long-running operations |
| 153 | +3. **Layered Architecture** - Agents can be both MCP servers and clients |
| 154 | +4. **Tool Delegation** - Agents can delegate tasks to other specialized agents |
| 155 | + |
| 156 | +## Implementation Details |
| 157 | + |
| 158 | +Each component is implemented using Python with the MCP SDK: |
| 159 | + |
| 160 | +- **Project Analyst Agent**: Implements a tool that analyzes project issues and can request specific details through elicitation |
| 161 | +- **Personal Assistant Agent**: Acts as both a client (to the Project Analyst) and a server (to the Chat CLI) |
| 162 | +- **Chat CLI**: Provides a simple text interface and handles elicitation requests by prompting the user |
| 163 | + |
| 164 | +All communication happens using the MCP protocol over stdio transport, demonstrating how agents can be composed into more complex systems. |
0 commit comments