MCP Tools

repository·master·Indexed 23 days ago

https://github.com/f/mcptools

A CLI 'Swiss Army Knife' for interacting with Model Context Protocol (MCP) servers. It provides capabilities for discovering and calling tools, resources, and prompts via stdio, HTTP SSE, and Streamable HTTP transports. Key features include an interactive shell, a web interface, project scaffolding for TypeScript, mock server creation, proxy mode for turning scripts into tools, and a guard mode for restricting server access. It also includes a configuration management system for macOS to sync MCP settings across apps like VS Code, Cursor, and Claude Desktop.

Tokens
12.3K
Snippets
37
Records
79
Agent score
81%

What's inside mcptools

  1. Overview of MCP Tools capabilities

    master

    MCP Tools is a command-line interface designed for interacting with Model Context Protocol (MCP) servers. It supports multiple transport methods (HTTP, stdio) and provides several key capabilities:

    • Discovery & Execution: Discover and call tools, access resources, and utilize prompts.
    • Testing & Extensibility: Create mock servers for client testing and proxy MCP requests to shell scripts.
    • Exploration: Use an interactive shell to explore server capabilities.
    • Development: Scaffold new MCP projects with TypeScript support.
    • Security: Guard and restrict access to specific tools and resources.
    • Output Management: Format output as JSON, pretty-printed text, or tables.
  2. Configure MCP Transport Options

    master

    MCP Tools supports three transport methods for communicating with MCP servers:

    1. Stdio Transport: Uses stdin/stdout via JSON-RPC 2.0. Ideal for local command-line tools. Example: mcp tools <command_to_run_server>

    2. HTTP SSE Transport: Uses HTTP and Server-Sent Events (SSE). Used for remote servers. Transport is automatically detected if the URL ends in /sse. Note: Supports only MCP protocol version 2024-11-05.

    3. Streamable HTTP Transport (Recommended): The modern default for HTTP/HTTPS URLs. Supports stateful sessions, resumability, and both streaming and direct JSON responses.

    When providing a server command or URL, MCP Tools determines the transport automatically.

  3. Create a Mock MCP Server

    master

    Mock server mode allows you to simulate an MCP server for testing clients without writing a full implementation. It supports the full initialization handshake, tool listing, tool calling, resource listing, and prompt retrieval.

    Features:

    • Tooling: Define tools with names and descriptions.
    • Prompts: Define prompts with argument substitution using {{double_braces}} syntax.
    • Resources: Define mock resources.
    • Logging: Detailed logs are written to ~/.mcpt/logs/mock.log.

    Prompt Templates: Any text inside {{variable_name}} is treated as an argument that the client can provide.

  4. Secure MCP servers with Guard Mode

    master

    Guard mode acts as a security proxy between an MCP client and an MCP server. It intercepts requests to tools/list, prompts/list, and resources/list to restrict access based on pattern matching.

    Note: Guard mode currently only supports STDIO transport (not HTTP).

    Pattern Matching: Uses simple glob syntax (*) to match entity names:

    • tools:read_* matches all tools starting with read_.
    • tools:*file* matches any tool with file in the name.
    • prompts:system_* matches all prompts starting with system_.

    Usage Patterns:

    • Allow-list only: Use --allow 'pattern' to permit only specific entities. If no allow patterns are provided, all are allowed by default (except those explicitly denied).
    • Deny-list: Use --deny 'pattern' to block specific entities.
    • Combined: You can restrict by both tool type and prompt type.

    Integration: To secure a server in an application config (like Claude Desktop), wrap the command with mcp guard:

    "command": "mcp",
    "args": [
      "guard", "--deny", "tools:write_*,create_*,delete_*",
      "npx", "-y", "@modelcontextprotocol/server-filesystem", "/path/to/dir"
    ]

    Logging: All filtering decisions are logged to ~/.mcpt/logs/guard.log.

  5. Install MCP Tools from source (Windows and GNU/Linux)

    master

    On Windows or GNU/Linux, you can install MCP Tools using go install. The binary is installed as mcptools, though you may choose to alias it to mcpt for convenience.

    go install github.com/f/mcptools/cmd/mcptools@latest
  6. Use streamable HTTP (SSE) servers

    master

    You can connect to MCP servers running over HTTP using Server-Sent Events (SSE) transport.

    Creating a local SSE server

    1. Scaffold a new server: mcp new tool:<name> --transport=sse.
    2. Build and start the server using your project's build tools (e.g., npm install && npm run build && npm start).

    Connecting to an SSE server

    Use mcp tools <URL> to list tools or mcp call <tool_name> --params '<JSON>' <URL> to call a tool on the remote server. The CLI can auto-detect SSE transport from the /sse path.

    # Create a new MCP server with SSE transport
    mcp new tool:example_tool --transport=sse
    
    # Connect to local SSE server
    mcp tools http://localhost:3000/sse
    
    # Call a tool on the local server
    mcp call example_tool --params '{"input": "test"}' http://localhost:3000/sse
    
    # Connect to a remote MCP server
    mcp tools https://api.example.com/mcp
    
    # Use SSE transport for legacy servers (auto-detected from /sse path)
    mcp tools http://legacy-server.com/sse
  7. Manage LLM App MCP configurations

    master

    MCP Tools provides a configuration management system for managing MCP server settings across multiple applications (VS Code, Windsurf, Cursor, Claude Desktop, etc.).

    Note: This feature currently only works on macOS.

    Configurations are stored in a central registry at $HOME/.mcpt/configs.json. Supported aliases include vscode, vscode-insiders, windsurf, cursor, and claude-desktop.

    Common tasks:

    • Scan for existing configurations: mcp configs scan
    • List all configurations: mcp configs ls
    • View a specific config: mcp configs view <alias>
    • Set/Update a server: mcp configs set <alias> <name> <command> [args...]
    • Remove a server: mcp configs remove <alias> <name>
    • Sync/Merge configs: mcp configs sync <alias1> <alias2> --output <alias> --default interactive
    • Convert to JSON: Use mcp configs as-json <command_or_url> to generate the JSON structure required by MCP servers.
    # Scan for MCP server configurations
    mcp configs scan
    
    # Add a server to VS Code
    mcp configs set vscode my-server npm run mcp-server
    
    # Add a server to multiple apps at once
    mcp configs set vscode,cursor,claude-desktop my-server npm run mcp-server
    
    # Convert a command to MCP JSON format
    mcp configs as-json mcp proxy start
  8. Get started with MCP Tools

    master

    You can interact with an MCP server by providing the command used to run that server as arguments to the mcp CLI. Common tasks include listing tools, calling specific tools with parameters, and entering an interactive shell.

    # List all available tools from a filesystem server
    mcp tools npx -y @modelcontextprotocol/server-filesystem ~
    
    # Call a specific tool
    mcp call read_file --params '{"path":"README.md"}' npx -y @modelcontextprotocol/server-filesystem ~
    
    # Open an interactive shell
    mcp shell npx -y @modelcontextprotocol/server-filesystem ~
  9. Launch the MCP Web Interface

    master

    The mcp web command starts a browser-based UI for interacting with MCP servers. It provides form-based parameter editing, automatically generated forms from tool schemas, and formatted response views.

    Usage:

    • Default port is 41999.
    • You can specify a custom port with --port.
    • Supports Stdio, SSE, and Streamable HTTP.

    Access the interface at http://localhost:<port> after running the command.

  10. Use the Interactive MCP Shell

    master

    The mcp shell command starts an interactive session where you can run multiple commands without re-specifying the server.

    Capabilities:

    • Run tools, resources, or prompts to list entities.
    • Call tools directly by typing the tool name followed by JSON parameters (e.g., tool_name {"param":"value"}).
    • Use /h or /help for shell help.
    • Use /q or /quit to exit.
    • Use format [json|pretty|table] to change the output format within the session.
    mcp shell npx -y @modelcontextprotocol/server-filesystem ~
    
    # Inside the shell:
    mcp > tools
    mcp > read_file {"path":"README.md"}
    mcp > /q
  11. Install MCP Project Templates

    master
    To use templates from your home directory, install them using the make templates command. The mcp CLI will automatically look for templates in ./templates/, ~/.mcpt/templates/, or the directory next to the executable.
    make templates
  12. Register and use shell scripts as MCP tools via Proxy Mode

    master

    The mcp proxy allows you to wrap existing shell scripts as MCP tools.

    1. Register: Use mcp proxy tool <name> "<description>" "<parameter_schema>" <path_to_script> to register a script. The parameter schema follows a name:type format (e.g., a:int,b:int).
    2. Start: Run mcp proxy start to begin the proxy server.
    3. Call: Use mcp call <name> --params '<JSON>' to execute the script through the proxy.
    # 1. Create a simple shell script for addition
    cat > add.sh << 'EOF'
    #!/bin/bash
    if [ -z "$a" ] || [ -z "$b" ]; then
      echo "Error: Missing required parameters 'a' or 'b'"
      exit 1
    fi
    result=$(($a + $b))
    echo "The sum of $a and $b is $result"
    EOF
    
    # 2. Make it executable
    chmod +x add.sh
    
    # 3. Register it as an MCP tool
    mcp proxy tool add_numbers "Adds two numbers" "a:int,b:int" ./add.sh
    
    # 4. In one terminal, start the proxy server
    mcp proxy start
    
    # 5. In another terminal, you can call it as an MCP tool
    mcp call add_numbers --params '{"a":5,"b":3}' --format pretty