mcp-client-cli Documentation

repository·master·Indexed 20 days ago

https://github.com/adhikasp/mcp-client-cli

A lightweight command line interface for the Model Context Protocol (MCP) that enables interaction with LLMs (OpenAI, Groq, and local via llama.cpp) and MCP-compatible servers. It supports piping text and images, prompt templates, conversation continuation, and clipboard integration. Version 1.0.5.

Tokens
6.3K
Snippets
26
Records
30
Agent score
71%

What's inside mcp-client-cli

  1. Basic usage and piping input

    master

    Run prompts directly via the llm command. You can pass a string as an argument or pipe content from other commands or files.

    Warning: If your prompt contains shell special characters like &, |, or ;, wrap the prompt in quotes to prevent the shell from interpreting them.

    # Direct prompt
    llm "What is the capital city of North Sumatra?"
    
    # Piping from echo
    echo "What is the capital city of North Sumatra?" | llm
    
    # Piping from a file
    cat instructions.txt | llm "West Java"
  2. Configure LLM and MCP servers in config.json

    master

    Create a configuration file at ~/.llm/config.json or $PWD/.llm/config.json to define your LLM provider and MCP servers.

    Key configuration sections:

    • systemPrompt: A global system prompt for the AI.
    • llm: Configuration for the LLM provider (e.g., openai, groq, or local via llama). Includes provider, model, api_key, temperature, and base_url.
    • mcpServers: A dictionary of MCP servers. Each server entry requires a command and args.

    Additional server options:

    • requires_confirmation: A list of tool names that require explicit user approval before execution.
    • enabled: Boolean to enable/disable the server (defaults to true).
    • exclude_tools: A list of specific tool names to exclude from the server.
    • env: A dictionary of environment variables for the server process.

    Note: You can use // to comment within the JSON file. LLM API keys can also be provided via LLM_API_KEY or OPENAI_API_KEY environment variables.

    {
      "systemPrompt": "You are an AI assistant...",
      "llm": {
        "provider": "openai",
        "model": "gpt-4",
        "api_key": "your-openai-api-key",
        "temperature": 0.7,
        "base_url": "https://api.openai.com/v1"
      },
      "mcpServers": {
        "fetch": {
          "command": "uvx",
          "args": ["mcp-server-fetch"],
          "requires_confirmation": ["fetch"],
          "enabled": true,
          "exclude_tools": []
        },
        "brave-search": {
          "command": "npx",
          "args": ["-y", "@modelcontextprotocol/server-brave-search"],
          "env": {
            "BRAVE_API_KEY": "your-brave-api-key"
          },
          "requires_confirmation": ["brave_web_search"]
        }
      }
    }
  3. Use prompt templates

    master

    Access predefined prompt templates using the p prefix followed by the template name and optional arguments.

    • Use llm --list-prompts to see all available templates.
    • Syntax: llm p <template_name> [args]
    # List templates
    llm --list-prompts
    
    # Use templates
    llm p review
    llm p commit
    llm p yt url=https://youtube.com/...
  4. Use clipboard content

    master

    The cb command allows you to interact with text or images currently in your system clipboard.

    • llm cb: Processes the clipboard content directly.
    • llm cb "<question>": Analyzes the clipboard content using the provided question.
    • llm cb c "<question>": Combines clipboard usage with conversation continuation.

    Platform Requirements:

    • Windows: Uses PowerShell (built-in).
    • macOS: Uses pbpaste (built-in) for text; pngpaste (optional, brew install pngpaste) for images.
    • Linux: Requires xclip (sudo apt install xclip).
    • WSL: Accesses Windows clipboard via powershell.exe.
    # Process clipboard text
    llm cb
    
    # Ask a question about clipboard content
    llm cb "What language is this code written in?"
    
    # Continue conversation with clipboard content
    llm cb c "Tell me more about what you see"
  5. Triggering tools and managing confirmations

    master

    When an LLM decides to use an MCP tool, the CLI will display the tool call details.

    • Manual Confirmation: If a tool is listed in the requires_confirmation section of your config, you will be prompted with Confirm tool call? [y/n]:.
    • Bypass Confirmation: Use the --no-confirmations flag to automatically approve all tool calls.
    • Scripting Mode: Use the --no-intermediates flag in bash scripts to suppress intermediate tool/AI messages and only output the final response.
    # Standard tool call (may prompt for confirmation)
    llm "What is the top article on hackernews today?"
    
    # Bypass all confirmations
    llm --no-confirmations "What is the top article on hackernews today?"
    
    # Use in scripts (suppresses intermediate output)
    llm --no-intermediates "What is the time in Tokyo right now?"
  6. Locate the MCP Client CLI configuration file

    master

    The MCP Client CLI looks for its configuration in one of two locations:

    1. ~/.llm/config.json (in your user's home directory for global settings).
    2. mcp-server-config.json (in your current working directory for project-specific settings).

    The file uses JSON format and supports comments using the // syntax.

  7. Configure MCP Servers

    master

    The mcpServers object is a dictionary where each key is a unique server name. Each server entry defines how to launch and manage that specific MCP server.

    FieldTypeRequiredDefaultDescription
    commandstringYes-Command to run the server
    argsarrayNo[]Command-line arguments
    envobjectNo{}Environment variables
    enabledbooleanNotrueWhether the server is enabled
    exclude_toolsarrayNo[]Tool names to exclude
    requires_confirmationarrayNo[]Tools requiring user confirmation
    "mcpServers": {
      "fetch": {
        "command": "uvx",
        "args": ["mcp-server-fetch"]
      },
      "brave-search": {
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/server-brave-search"],
        "env": {
          "BRAVE_API_KEY": "your-brave-api-key-here"
        }
      }
    }
  8. How McpTool works as a LangChain tool

    master

    The McpTool class is a specialized BaseTool implementation that wraps an MCP tool. When called via its asynchronous _arun method, it executes the tool on the remote MCP server using the active ClientSession.

    Key Behaviors:

    • Automatic Session Management: If the session is not active when the tool is called, it attempts to start the session via the parent toolkit.
    • Error Handling: If the MCP server returns an error (result.isError), the tool raises a ToolException containing the error content.
    • Output: Returns the tool's result as a JSON-decoded string.
  9. Configure LLM settings

    master

    The llm object allows you to define the provider and model parameters. If api_key is omitted, the client will attempt to use the LLM_API_KEY or OPENAI_API_KEY environment variables.

    FieldTypeRequiredDefaultDescription
    providerstringNo"openai"LLM provider
    modelstringNo"gpt-4o"LLM model name
    api_keystringNoEnvironment varsAPI key for the LLM service
    temperaturefloatNo0Temperature for LLM responses
    base_urlstringNonullCustom API endpoint URL
    "llm": {
      "provider": "openai",
      "model": "gpt-4o-mini",
      "api_key": "your-api-key-here",
      "temperature": 0
    }
  10. How prompt templates work

    master

    Prompt templates allow you to reuse structured prompts. You can list available templates using llm --list-prompts. To use a template, use the p prefix followed by the template name and any required arguments.

    If a template contains placeholders like {arg}, you must provide the values in the order they appear in the template.

    # If 'review' template is: 'Review this: {text}'
    llm p review "my code snippet"