mcpField
R
Run the MCP Client

Run the MCP Client

本地服务
github.com/dazzaji开发工具097 周前更新

关于 Run the MCP Client

Run the MCP Client 是用于测试已运行的文件系统 MCP 服务的 Python 客户端,可列出工具、调用指定工具并输出结果,便于检查连接和行为。

主要功能

  1. 01连接文件系统 MCP 服务
  2. 02列出可用工具
  3. 03使用指定参数调用工具
  4. 04输出调用结果

适用场景

  1. 01检查客户端与服务的连接
  2. 02使用指定参数测试文件系统工具
  3. 03验证文件创建、读取或目录列表

MCP 相关

连接正在运行的文件系统 MCP 服务,发现可用工具并调用指定工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

运行 MCP 客户端

运行此客户端前,请确保服务已启动。有关详情,请参阅:https://github.com/dazzaji/filesystem

步骤 1:创建虚拟环境并正确安装依赖项

使用以下命令:

```bash
mkdir mcp-client-py
cd mcp-client-py
```

```bash
python -m venv venv
source venv/bin/activate
```

```bash
pip install -r requirements.txt
```

这会创建虚拟环境并激活它,然后将 mcp 和 python-dotenv(及其依赖项)安装到该环境中。

步骤 2:确认或更正 .env 中的环境变量

创建一个 .env 文件,填写服务路径和允许访问的目录。你也可以指定用于测试的工具和参数。

   SERVER_PATH=/Users/dazzagreenwood/filesystem/dist/index.js
   ALLOWED_DIRECTORY=/Users/dazzagreenwood/mcp-hello/module1/files
   
  # Test with arguments:
   #TOOL=list_directory
   #ARGS='{"path": "/Users/dazzagreenwood/mcp-hello/module1/files", "recursive": true}'
   
   # Or test with other tools
   #TOOL=read_file
   #ARGS='{"path": "/Users/dazzagreenwood/mcp-hello/module1/files/test.txt"}'
步骤 3:运行 Python 客户端

运行客户端以测试服务。

 python client.py
 ```
*   If you used the optional `TOOL` and `ARGS` add those arguments like so:
 ```bash
     python client.py --tool "list_directory" --args '{"path": "/Users/dazzagreenwood/mcp-hello/module1/files", "recursive": true}'
 ```
This will:

*   Connect to your filesystem server.
*   List available tools.
*  Call the `write_file` to create a test file with text content in the specified directory, if `tool` is not specified in the .env file.
*   Display the results to the console.

### Step 4: Verifying Results

After successfully running the client, check the following:

1.  **Client Output:** You should see output like `Available tools: [ ... ]`, and the result from the `write_file` (or other tool call).
2.  **File Creation:** Verify that `testfile.txt` has been created with the correct content inside `/Users/dazzagreenwood/mcp-hello/module1/files/`.  If testing with the read or list tools, make sure the output is what you'd expect.

### Testing Workflow

Here are steps to verify the project with the client and a server:

#### Starting the Server
1.  **Open a Terminal**. You will need to start the server from a terminal.
2.  **Navigate to Server Directory**. Change directory to the folder containing the server:
 ```
 cd /Users/dazzagreenwood/filesystem
 ```
3.  **Run the Server:**
 ```bash
 node dist/index.js "/Users/dazzagreenwood/mcp-hello/module1/files"
 ```
 *   Replace `/Users/dazzagreenwood/filesystem/dist/index.js` with the actual path to the compiled file.
 *   Replace `/Users/dazzagreenwood/mcp-hello/module1/files` with the allowed directory.

#### Testing with the Client

1.  **Open another Terminal window** or split your existing terminal tab.
2.  **Navigate to Client Directory** Change directories into the `mcp-client-py` folder:
  ```bash
  cd /Users/dazzagreenwood/mcp-client-server/mcp-client-py
  source .venv/bin/activate
  ```
3. **Run the Client in Default Mode:**
 To test basic connectivity and the `write_file` tool:
 ```bash
  python client.py
 ```
  This will attempt to call write file, to create a file named test.txt into the `/Users/dazzagreenwood/mcp-hello/module1/files` directory with the string `Hello from Python the new standup MCP client!` as it's content.

4.  **Run the client with specific tools and arguments**: To test list_directory, use the following:
```bash
   python client.py --server-path /Users/dazzagreenwood/filesystem/dist/index.js --allowed-dir /Users/dazzagreenwood/mcp-hello/module1/files --tool list_directory --args '{"path": "/Users/dazzagreenwood/mcp-hello/module1/files", "recursive": true}'
要测试 `read_file` 工具,请使用:
 python client.py --server-path /Users/dazzagreenwood/filesystem/dist/index.js --allowed-dir /Users/dazzagreenwood/mcp-hello/module1/files --tool read_file --args '{"path": "/Users/dazzagreenwood/mcp-hello/module1/files/test.txt"}'
* 将以上示例中的路径替换为与你本地路径相对应的路径。

如果设置正确,你应该会看到确认这些操作的输出。

按照这些说明操作后,你现在可以使用 Python 和 TypeScript/Node.js,通过各种工具测试 MCP 服务和客户端!

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。