技能库 / mcp-cli

mcp-cli

Use MCP servers on-demand via the mcp CLI tool - discover tools, resources, and prompts without polluting context with pre-loaded MCP integrations

v1.0.0

安装方式

CLI 安装(推荐)

claw install oss-mcp-cli

需要安装 CLAW CLI

手动下载安装

下载 ZIP 文件后解压到技能目录

下载 ZIP (oss-mcp-cli-v1.0.0.zip)

触发指令

/mcp-cli

使用指南

MCP CLI: On-Demand MCP Server Usage

Use the mcp CLI tool to dynamically discover and invoke MCP server capabilities without pre-configuring them as permanent 集成s.

When to Use This Skill

Use this skill when you need to:

  • Explore an MCP server's capabilities before deciding to use it
  • Make one-off calls to an MCP server without permanent 集成
  • Access MCP 函数ality without polluting the context window
  • Test or debug MCP servers
  • Use MCP servers that aren't pre-configured

前提条件

The mcp CLI must be installed at ~/.local/bin/mcp. If not present:

# Clone and build
cd /tmp && git clone --depth 1 https://github.com/f/mcptools.git
cd mcptools && CGO_ENABLED=0 go build -o ~/.local/bin/mcp ./cmd/mcptools

Always ensure PATH includes the binary:

export PATH="$HOME/.local/bin:$PATH"

Discovery 工作流

Step 1: Discover Available Tools

mcp tools <server-command>

示例s:

# File系统 server
mcp tools npx -y @modelcontext协议/server-file系统 /path/to/allow

# Memory/knowledge graph server
mcp tools npx -y @modelcontext协议/server-memory

# GitHub server (requires 代币)
mcp tools docker run -i --rm -e GITHUB_PERSONAL_ACCESS_代币 ghcr.io/github/github-mcp-server

# HTTP-based server
mcp tools https://示例.com/mcp

Step 2: Discover Resources (if supported)

mcp resources <server-command>

Resources are data sources the server exposes (files, 数据库 entries, etc.).

Step 3: Discover Prompts (if supported)

mcp prompts <server-command>

Prompts are pre-defined prompt 模板s the server provides.

Step 4: Get Detailed Info (JSON format)

# For full schema details 包括 参数 types
mcp tools --format json <server-command>
mcp tools --format pretty <server-command>

Making Tool Calls

Basic Syntax

mcp call <tool_name> --params '<json>' <server-command>

示例

Read a file:

mcp call read_file --params '{"path": "/tmp/示例.txt"}' \
  npx -y @modelcontext协议/server-file系统 /tmp

Write a file:

mcp call write_file --params '{"path": "/tmp/test.txt", "content": "Hello world"}' \
  npx -y @modelcontext协议/server-file系统 /tmp

List directory:

mcp call list_directory --params '{"path": "/tmp"}' \
  npx -y @modelcontext协议/server-file系统 /tmp

Create entities (memory server):

mcp call create_entities --params '{"entities": [{"name": "Project", "entityType": "Software", "observations": ["Uses TypeScript"]}]}' \
  npx -y @modelcontext协议/server-memory

Search (memory server):

mcp call search_nodes --params '{"query": "TypeScript"}' \
  npx -y @modelcontext协议/server-memory

Complex 参数s

For nested objects and arrays, ensure valid JSON:

mcp call edit_file --params '{
  "path": "/tmp/file.txt",
  "edits": [
    {"oldText": "foo", "newText": "bar"},
    {"oldText": "baz", "newText": "qux"}
  ]
}' npx -y @modelcontext协议/server-file系统 /tmp

Output Formats

# Table (default, human-readable)
mcp call <tool> --params '{}' <server>

# JSON (for parsing)
mcp call <tool> --params '{}' -f json <server>

# Pretty JSON (readable JSON)
mcp call <tool> --params '{}' -f pretty <server>

Reading Resources

# List available resources
mcp resources <server-command>

# Read a specific resource
mcp read-resource <resource-uri> <server-command>

# Alternative syntax
mcp call resource:<resource-uri> <server-command>

Using Prompts

# List available prompts
mcp prompts <server-command>

# Get a prompt (may require arguments)
mcp get-prompt <prompt-name> <server-command>

# With 参数s
mcp get-prompt <prompt-name> --params '{"arg": "value"}' <server-command>

Server Aliases (for repeated use)

If using a server frequently during a session:

# Create alias
mcp alias add fs npx -y @modelcontext协议/server-file系统 /home/user

# Use alias
mcp tools fs
mcp call read_file --params '{"path": "README.md"}' fs

# List aliases
mcp alias list

# Remove when done
mcp alias remove fs

Aliases are stored in ~/.mcpt/aliases.json.

Authentication

HTTP Basic Auth

mcp tools --auth-user "username:password" https://API.示例.com/mcp

Bearer 代币

mcp tools --auth-header "Bearer your-代币-here" https://API.示例.com/mcp

环境 变量s (for Docker-based servers)

mcp tools docker run -i --rm \
  -e GITHUB_PERSONAL_ACCESS_代币="$GITHUB_代币" \
  ghcr.io/github/github-mcp-server

Transport Types

Stdio (default for npx/node commands)

mcp tools npx -y @modelcontext协议/server-file系统 /tmp

HTTP (auto-detected for http/https URLs)

mcp tools https://示例.com/mcp

SSE (Server-Sent Events)

mcp tools http://localhost:3001/sse
# Or explicitly:
mcp tools --transport sse http://localhost:3001

Common MCP Servers

File系统

# Allow access to specific directory
mcp tools npx -y @modelcontext协议/server-file系统 /path/to/allow

Memory (Knowledge Graph)

mcp tools npx -y @modelcontext协议/server-memory

GitHub

export GITHUB_PERSONAL_ACCESS_代币="your-代币"
mcp tools docker run -i --rm -e GITHUB_PERSONAL_ACCESS_代币 ghcr.io/github/github-mcp-server

Brave Search

export BRAVE_API_KEY="your-key"
mcp tools npx -y @anthropic/mcp-server-brave-search

Puppeteer (Browser 自动化)

mcp tools npx -y @anthropic/mcp-server-puppeteer

最佳实践

1. Always Discover First

Before calling tools, run mcp tools to understand what's available and the exact 参数 schema.

2. Use JSON Format for Parsing

When you need to process results programmatically:

mcp call <tool> --params '{}' -f json <server> | jq '.field'

3. Validate 参数s

The table output shows 参数 signatures. Match them exactly:

  • param:str = string
  • param:num = number
  • param:bool = boolean
  • param:str[] = array of strings
  • [param:str] = optional 参数

4. Handle Errors Gracefully

Tool calls may fail. Check exit codes and stderr:

if ! result=$(mcp call tool --params '{}' server 2>&1); then
  echo "Error: $result"
fi

5. Use Aliases for Multi-Step Operations

If making several calls to the same server:

mcp alias add tmp-server npx -y @modelcontext协议/server-file系统 /tmp
mcp call list_directory --params '{"path": "/tmp"}' tmp-server
mcp call read_file --params '{"path": "/tmp/file.txt"}' tmp-server
mcp alias remove tmp-server

6. Restrict Capabilities with Guard

For safety, limit what tools are accessible:

# Only allow read operations
mcp guard --allow 'tools:read_*,list_*' --deny 'tools:write_*,delete_*' \
  npx -y @modelcontext协议/server-file系统 /home

Debugging

View Server Logs

mcp tools --server-logs <server-command>

Check Alias 配置

cat ~/.mcpt/aliases.json

Verbose Output

Use --format pretty for detailed JSON output to debug 参数 issues.

Quick Reference

| Action | Command | |--------|---------| | List tools | mcp tools <server> | | List resources | mcp resources <server> | | List prompts | mcp prompts <server> | | Call tool | mcp call <tool> --params '<json>' <server> | | Read resource | mcp read-resource <uri> <server> | | Get prompt | mcp get-prompt <name> <server> | | Add alias | mcp alias add <name> <server-command> | | Remove alias | mcp alias remove <name> | | JSON output | Add -f json or -f pretty |

示例: Complete 工作流

# 1. Discover what's available
mcp tools npx -y @modelcontext协议/server-file系统 /home/user/project

# 2. Check for resources
mcp resources npx -y @modelcontext协议/server-file系统 /home/user/project

# 3. Create alias for convenience
mcp alias add proj npx -y @modelcontext协议/server-file系统 /home/user/project

# 4. Explore directory structure
mcp call directory_tree --params '{"path": "/home/user/project"}' proj

# 5. Read specific files
mcp call read_file --params '{"path": "/home/user/project/README.md"}' proj

# 6. Search for 模式s
mcp call search_files --params '{"path": "/home/user/project", "模式": "**/*.ts"}' proj

# 7. Clean up alias
mcp alias remove proj

故障排除

"command not found: mcp"

Ensure PATH is set: export PATH="$HOME/.local/bin:$PATH"

JSON parse errors

  • Escape special characters properly
  • Avoid shell expansion issues by using single quotes around JSON
  • For complex JSON, write to a temp file and use --params "$(cat params.json)"

Server timeout

Some servers take time to start. The mcp CLI waits for initialization automatically.

Permission denied

For file系统 server, ensure the allowed directory path is correct and accessible.