This document provides instructions for AI agents working on the mcp-cli codebase.
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).
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.
- Go: The programming language used for the project.
- Cobra: A library for creating powerful modern CLI applications in Go.
- Bubble Tea: A framework for building terminal user interfaces. It follows The Elm Architecture (Model-View-Update).
- Lip Gloss: A library for styling terminal output, used for the TUI layout.
- Bubbles: A library of ready-to-use components for Bubble Tea applications (e.g.,
list,textinput,viewport).
-
Build: To build the executable, run:
go build
This will create an
mcp-clibinary in the root directory. -
Run: The application has three main commands:
mcp-cli stdio "<command>"mcp-cli sse <url>mcp-cli http <url>
-
Debugging: The
-vor--verboseflag enables logging to adebug.logfile. This is useful for debugging the TUI's behavior.
All the application logic is contained in main.go.
-
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. -
initialModel: This function initializes theAppModelwhen the application starts. -
Updatefunction: 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. -
Viewfunction: This function is responsible for rendering the TUI based on the current state of theAppModel. It useslipglossto create a two-column layout, with the main content on the left and the debug panel on the right. -
logffunction: A helper function onAppModelto 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.
The application has three main views, represented by the viewState enum:
toolSelectionView: The initial view that shows a list of available tools.argumentInputView: The view for entering arguments for a selected tool.resultView: The view for displaying the result of a tool call.
The debug panel is always visible on the right side of the screen.
- Understand the Request: Carefully read the user's request and identify the required changes.
- Explore the Code: Use
read_fileto examinemain.goand understand the current implementation. - Formulate a Plan: Create a clear, step-by-step plan to implement the changes.
- Implement Changes: Use
replace_with_git_merge_diffor other tools to modify the code. - Test: After making changes, run
go buildto ensure the code compiles. - Review and Submit: Use
request_code_reviewto get feedback on your changes before submitting.
- State Management: The
AppModelis the single source of truth for the application's state. All changes to the UI should be a result of changes to theAppModel. - Pointer Receivers: Methods on
AppModelthat modify its state (likeUpdateandlogf) must have a pointer receiver (*AppModel) to ensure the changes are applied to the original model. - Command Handling: The
Updatefunction returns atea.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. - Styling: Use
lipglossfor all TUI styling. - Dependencies: Use
go mod tidyto manage dependencies. .gitignore: Themcp-cliexecutable is ignored by.gitignore.