Run the MCP Client

Run the MCP Client

镜像

前提条件

确保 MCP 服务器已启动并正在运行。查看更多信息:https://github.com/dazzaji/filesystem

快速设置

1. 创建并配置环境

# 创建项目目录
mkdir mcp-client-py
cd mcp-client-py

# 创建并激活虚拟环境
python -m venv venv
source venv/bin/activate

# 安装依赖
pip install -r requirements.txt

2. 配置环境变量

创建 .env 文件:

SERVER_PATH=/Users/dazzagreenwood/filesystem/dist/index.js
ALLOWED_DIRECTORY=/Users/dazzagreenwood/mcp-hello/module1/files

# 可选测试参数
#TOOL=list_directory
#ARGS='{"path": "/Users/dazzagreenwood/mcp-hello/module1/files", "recursive": true}'

3. 运行客户端

基本用法:

python client.py

指定工具和参数:

python client.py --tool "list_directory" --args '{"path": "/path/to/directory", "recursive": true}'

4. 验证结果

  • 检查控制台输出
  • 如果使用 write_file,验证文件是否已在指定位置创建

测试工作流程

启动服务器

cd /path/to/filesystem
node dist/index.js "/path/to/allowed/directory"

常用测试命令

列出目录内容:

python client.py --tool list_directory --args '{"path": "/path/to/directory", "recursive": true}'

读取文件:

python client.py --tool read_file --args '{"path": "/path/to/file.txt"}'

注意:请根据您的实际环境替换所有路径