|
| 1 | +# Agent Instructions for mcp-cli |
| 2 | + |
| 3 | +This document provides instructions for AI agents working on the `mcp-cli` codebase. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +`mcp-cli` is a command-line tool for testing Model Context Protocol (MCP) servers. It's written in Go and uses `cobra` for the command-line interface and `bubbletea` for the terminal user interface (TUI). |
| 8 | + |
| 9 | +The primary goal of this tool is to provide a user-friendly way to interact with MCP servers, select tools, provide arguments, and view results, all within the terminal. |
| 10 | + |
| 11 | +## Tech Stack |
| 12 | + |
| 13 | +- **Go:** The programming language used for the project. |
| 14 | +- **Cobra:** A library for creating powerful modern CLI applications in Go. |
| 15 | +- **Bubble Tea:** A framework for building terminal user interfaces. It follows The Elm Architecture (Model-View-Update). |
| 16 | +- **Lip Gloss:** A library for styling terminal output, used for the TUI layout. |
| 17 | +- **Bubbles:** A library of ready-to-use components for Bubble Tea applications (e.g., `list`, `textinput`, `viewport`). |
| 18 | + |
| 19 | +## How to Build and Run |
| 20 | + |
| 21 | +- **Build:** To build the executable, run: |
| 22 | + ```sh |
| 23 | + go build |
| 24 | + ``` |
| 25 | + This will create an `mcp-cli` binary in the root directory. |
| 26 | + |
| 27 | +- **Run:** The application has three main commands: |
| 28 | + - `mcp-cli stdio "<command>"` |
| 29 | + - `mcp-cli sse <url>` |
| 30 | + - `mcp-cli http <url>` |
| 31 | + |
| 32 | +- **Debugging:** The `-v` or `--verbose` flag enables logging to a `debug.log` file. This is useful for debugging the TUI's behavior. |
| 33 | +
|
| 34 | +## Code Structure |
| 35 | +
|
| 36 | +All the application logic is contained in `main.go`. |
| 37 | +
|
| 38 | +### Key Components |
| 39 | +
|
| 40 | +- **`AppModel`:** This is the main struct that holds the state of the application. It includes the current view, the list of tools, the input fields, the debug log, and the viewport for the debug panel. |
| 41 | +
|
| 42 | +- **`initialModel`:** This function initializes the `AppModel` when the application starts. |
| 43 | +
|
| 44 | +- **`Update` function:** This is the heart of the Bubble Tea application. It handles all incoming messages (key presses, window resize events, tool results) and updates the model accordingly. It follows a switch-case structure to handle different message types and application states. |
| 45 | +
|
| 46 | +- **`View` function:** This function is responsible for rendering the TUI based on the current state of the `AppModel`. It uses `lipgloss` to create a two-column layout, with the main content on the left and the debug panel on the right. |
| 47 | +
|
| 48 | +- **`logf` function:** A helper function on `AppModel` to append messages to the debug log and update the debug viewport. Use this function for all logging that should be visible in the debug panel. |
| 49 | +
|
| 50 | +### TUI Views |
| 51 | +
|
| 52 | +The application has three main views, represented by the `viewState` enum: |
| 53 | +
|
| 54 | +1. `toolSelectionView`: The initial view that shows a list of available tools. |
| 55 | +2. `argumentInputView`: The view for entering arguments for a selected tool. |
| 56 | +3. `resultView`: The view for displaying the result of a tool call. |
| 57 | +
|
| 58 | +The debug panel is always visible on the right side of the screen. |
| 59 | +
|
| 60 | +## Development Workflow |
| 61 | +
|
| 62 | +1. **Understand the Request:** Carefully read the user's request and identify the required changes. |
| 63 | +2. **Explore the Code:** Use `read_file` to examine `main.go` and understand the current implementation. |
| 64 | +3. **Formulate a Plan:** Create a clear, step-by-step plan to implement the changes. |
| 65 | +4. **Implement Changes:** Use `replace_with_git_merge_diff` or other tools to modify the code. |
| 66 | +5. **Test:** After making changes, run `go build` to ensure the code compiles. |
| 67 | +6. **Review and Submit:** Use `request_code_review` to get feedback on your changes before submitting. |
| 68 | + |
| 69 | +## Important Considerations |
| 70 | + |
| 71 | +- **State Management:** The `AppModel` is the single source of truth for the application's state. All changes to the UI should be a result of changes to the `AppModel`. |
| 72 | +- **Pointer Receivers:** Methods on `AppModel` that modify its state (like `Update` and `logf`) must have a pointer receiver (`*AppModel`) to ensure the changes are applied to the original model. |
| 73 | +- **Command Handling:** The `Update` function returns a `tea.Cmd`, which represents a command to be executed by the Bubble Tea runtime (e.g., waiting for a tool result). Be sure to handle and batch commands correctly. |
| 74 | +- **Styling:** Use `lipgloss` for all TUI styling. |
| 75 | +- **Dependencies:** Use `go mod tidy` to manage dependencies. |
| 76 | +- **`.gitignore`:** The `mcp-cli` executable is ignored by `.gitignore`. |
0 commit comments