MCP CLI - Model Context Protocol Command Line Interface | MCP Client #3384
Replies: 1 comment
|
hh |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
MCP CLI - Model Context Protocol Command Line Interface | MCP Client
MCP CLI - Model Context Protocol Command Line Interface
A powerful, feature-rich command-line interface for interacting with Model Context Protocol servers. This client enables seamless communication with LLMs through integration with the CHUK-MCP protocol library which is a pyodide compatible pure python protocol implementation of MCP, supporting tool usage, conversation management, and multiple operational modes.
🔄 Protocol Implementation
The core protocol implementation has been moved to a separate package at:
https://github.com/chrishayuk/chuk-mcp
This CLI is built on top of the protocol library, focusing on providing a rich user experience while the protocol library handles the communication layer.
🌟 Features
Multiple Operational Modes:
Multi-Provider Support:
gpt-4o-mini,gpt-4o,gpt-4-turbo, etc.)llama3.2,qwen2.5-coder, etc.)claude-3-opus,claude-3-sonnet, etc.)Provider and Model Management:
Robust Tool System:
Advanced Conversation Management:
Rich User Experience:
Resilient Resource Management:
📋 Prerequisites
OPENAI_API_KEYenvironment variableANTHROPIC_API_KEYenvironment variableserver_config.json)🚀 Installation
Install from Source
git clone https://github.com/chrishayuk/mcp-cli cd mcp-clipip install -e ".[cli,dev]"Using UV (Alternative Installation)
If you prefer using UV for dependency management:
🧰 Global Command-line Arguments
Global options available for all modes and commands:
--server: Specify the server(s) to connect to (comma-separated for multiple)--config-file: Path to server configuration file (default:server_config.json)--provider: LLM provider to use (openai,anthropic,ollama, default:openai)--model: Specific model to use (provider-dependent defaults)--disable-filesystem: Disable filesystem access (default: true)CLI Argument Format Issue
You might encounter a "Missing argument 'KWARGS'" error when running various commands. This is due to how the CLI parser is configured. To resolve this, use one of these approaches:
Use the equals sign format for all arguments:
Add a double-dash (
--) after the command and before arguments:When using uv and multiple extra parameters, follow the 2nd step but add an empty string at the end:
These format issues apply to all commands (chat, interactive, tools, etc.) and are due to how the argument parser interprets positional vs. named arguments.
🌐 Available Modes
1. Chat Mode
Chat mode provides a natural language interface for interacting with LLMs, where the model can automatically use available tools:
2. Interactive Mode
Interactive mode provides a command-driven shell interface for direct server operations:
3. Command Mode (Cmd)
Command mode provides a Unix-friendly interface for automation and pipeline integration:
4. Direct Commands
Run individual commands without entering an interactive mode:
🤖 Using Chat Mode
Chat mode provides a conversational interface with the LLM, automatically using available tools when needed.
Starting Chat Mode
Chat Commands
In chat mode, use these slash commands:
General Commands
/help: Show available commands/help <command>: Show detailed help for a specific command/quickhelpor/qh: Display a quick reference of common commandsexitorquit: Exit chat modeProvider and Model Commands
/provideror/p: Display or manage LLM providers/provider: Show current provider and model/provider list: List all configured providers/provider config: Show detailed provider configuration/provider set <name> <key> <value>: Set a provider configuration value/provider <name>: Switch to a different provider/modelor/m: Display or change the current model/model: Show current model/model <name>: Switch to a different modelTool Commands
/tools: Display all available tools with their server information/tools --all: Show detailed tool information including parameters/tools --raw: Show raw tool definitions/toolhistoryor/th: Show history of tool calls in the current session/th <N>: Show details for a specific tool call/th -n 5: Show only the last 5 tool calls/th --json: Show tool calls in JSON formatConversation Commands
/conversationor/ch: Show the conversation history/ch <N>: Show a specific message from history/ch -n 5: Show only the last 5 messages/ch <N> --json: Show a specific message in JSON format/ch --json: View the entire conversation history in raw JSON format/save <filename>: Save conversation history to a JSON file/compact: Condense conversation history into a summaryDisplay Commands
/cls: Clear the screen while keeping conversation history/clear: Clear both the screen and conversation history/verboseor/v: Toggle between verbose and compact tool display modesControl Commands
/interrupt,/stop, or/cancel: Interrupt running tool execution/servers: List connected servers and their status🖥️ Using Interactive Mode
Interactive mode provides a command-driven shell interface for direct server interaction.
Starting Interactive Mode
# Using {} to satisfy KWARGS requirement mcp-cli interactive {} --server sqliteInteractive Commands
In interactive mode, use these commands:
help: Show available commandsexitorquitorq: Exit interactive modeclearorcls: Clear the terminal screenserversorsrv: List connected servers with their statusproviderorp: Manage LLM providersprovider: Show current provider and modelprovider list: List all configured providersprovider config: Show detailed provider configurationprovider set <name> <key> <value>: Set a provider configuration valueprovider <name>: Switch to a different providermodelorm: Display or change the current modelmodel: Show current modelmodel <name>: Switch to a different modeltoolsort: List available tools or call one interactivelytools --all: Show detailed tool informationtools --raw: Show raw JSON definitionstools call: Launch the interactive tool-call UIresourcesorres: List available resources from all serverspromptsorp: List available prompts from all serversping: Ping connected servers (optionally filter by index/name)📄 Using Command Mode (Cmd)
Command mode provides a Unix-friendly interface for automation and pipeline integration.
Starting Command Mode
# Using {} to satisfy KWARGS requirement mcp-cli cmd {} --server sqlite [options]Command Mode Options
--input: Input file path (use-for stdin)--output: Output file path (use-for stdout, default)--prompt: Prompt template (use{{input}}as placeholder for input)--raw: Output raw text without formatting--tool: Directly call a specific tool--tool-args: JSON arguments for tool call--system-prompt: Custom system prompt--verbose: Enable verbose logging--provider: Specify LLM provider--model: Specify model to useCommand Mode Examples
Process content with LLM:
Call tools directly:
Batch processing:
🔧 Direct CLI Commands
Run individual commands without entering interactive mode:
Provider Commands
Tools Commands
Resources and Prompts Commands
Server Commands
📂 Server Configuration
Create a
server_config.jsonfile with your server configurations:{ "mcpServers": { "sqlite": { "command": "python", "args": ["-m", "mcp_server.sqlite_server"], "env": { "DATABASE_PATH": "your_database.db" } }, "another-server": { "command": "python", "args": ["-m", "another_server_module"], "env": {} } } }🔐 Provider Configuration
Provider configurations are stored with these key settings:
api_key: API key for authenticationapi_base: Base URL for API requestsdefault_model: Default model to use with this providerEnvironment Variables
You can also set the default provider and model using environment variables:
Configuration Example
The provider configuration is typically stored in a JSON file and looks like:
{ "openai": { "api_key": "sk-...", "api_base": "https://api.openai.com/v1", "default_model": "gpt-4o-mini" }, "anthropic": { "api_key": "sk-...", "api_base": "https://api.anthropic.com", "default_model": "claude-3-opus" }, "ollama": { "api_base": "http://localhost:11434", "default_model": "llama3.2" } }📈 Advanced Usage Examples
Provider and Model Selection
You can change providers or models during a session:
Working with Tools in Chat Mode
In chat mode, simply ask questions that require tool usage, and the LLM will automatically call the appropriate tools:
Using Conversation Management
The MCP CLI provides powerful conversation history management:
🛠️ Implementation Details
The provider configuration is managed by the
ProviderConfigclass, which:The LLM client is created using the
get_llm_clientfunction, which instantiates the appropriate client based on the provider and model settings.📦 Dependencies
The CLI is organized with optional dependency groups:
Install with specific extras using:
🤝 Contributing
Contributions are welcome! Please follow these steps:
git checkout -b feature/amazing-feature)git commit -m 'Add some amazing feature')git push origin feature/amazing-feature)📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
https://mcp.so/clients/mcp-cli
All reactions