|
| 1 | +# MCP Client |
| 2 | + |
| 3 | +A minimal client for testing Model Context Protocol (MCP) servers, featuring AI integration. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **MCP server integration**: Connect to any MCP server |
| 8 | +- **Server introspection**: List available tools, prompts, and resources with the `--members` option |
| 9 | +- **TUI AI-powered chat**: Interactive chat with AI-powered tool execution using the `--chat` option |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +1. Download the sample code |
| 14 | + |
| 15 | +2. Install dependencies: |
| 16 | +```console |
| 17 | +$ uv sync |
| 18 | +``` |
| 19 | + |
| 20 | +3. Set up your OpenAI API key: |
| 21 | +```console |
| 22 | +$ export OPENAI_API_KEY="your-openai-api-key" |
| 23 | +``` |
| 24 | + |
| 25 | +## Usage |
| 26 | + |
| 27 | +### List Server Members |
| 28 | + |
| 29 | +Inspect what tools, prompts, and resources are available on an MCP server: |
| 30 | + |
| 31 | +```console |
| 32 | +$ uv run python -m mcp_client /path/to/mcp_server.py --members |
| 33 | +``` |
| 34 | + |
| 35 | +This command will display the following: |
| 36 | + |
| 37 | +- Tools and their descriptions |
| 38 | +- Prompts and their purposes |
| 39 | +- Resources and their types |
| 40 | + |
| 41 | +### Interactive Chat Mode |
| 42 | + |
| 43 | +Start an interactive chat session using the MCP server tools: |
| 44 | + |
| 45 | +```console |
| 46 | +$ uv run python -m mcp_client <path/to/mcp/server.py> --chat |
| 47 | +``` |
| 48 | + |
| 49 | +- Example - Ask questions and get AI-powered responses: |
| 50 | +```console |
| 51 | +$ uv run python -m mcp_client mcp_server/mcp_server.py --chat |
| 52 | + |
| 53 | +MCP Client Started! |
| 54 | +Type your queries or 'quit' to exit. |
| 55 | + |
| 56 | +You: Greet Pythonista |
| 57 | + |
| 58 | +Assistant: [Used echo({'message': "Hello, Pythonista! 🐍 How's your coding journey going today?"})] |
| 59 | +Hello, Pythonista! 🐍 How's your coding journey going today? |
| 60 | + |
| 61 | +You: |
| 62 | +``` |
| 63 | + |
| 64 | +- The AI will automatically use available MCP tools when needed |
| 65 | +- Type `quit` to exit |
| 66 | + |
| 67 | +## Example MCP Server |
| 68 | + |
| 69 | +The project includes, `mcp_server.py`, which is a minimal MCP server that provides: |
| 70 | + |
| 71 | +- A sample tool that says hello |
| 72 | +- Sample prompts and resources |
| 73 | + |
| 74 | +You can use this server to test the client's functionalities. |
| 75 | + |
| 76 | +## Requirements |
| 77 | + |
| 78 | +- Python >= 3.13 |
| 79 | +- The MCP Python SDK and OpenAI Python SDK |
| 80 | +- An OpenAI API key |
| 81 | +- An MCP server to connect to |
0 commit comments