forked from patrickomatik/mcp-bash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_client.py
More file actions
37 lines (29 loc) · 1.12 KB
/
Copy pathexample_client.py
File metadata and controls
37 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
# example_client.py - Example client for the Model-Context-Protocol (MCP) Bash Server
from mcp.client import MCPClient
import asyncio
import os
async def main():
# Connect to the MCP server (assuming it's running locally)
client = MCPClient("http://localhost:8000")
# Get the current directory
current_dir = os.getcwd()
print(f"Current directory: {current_dir}")
# Set the working directory
print("\nSetting working directory...")
response = await client.set_cwd(current_dir)
print(f"Response: {response}")
# Execute some commands
print("\nListing directory contents:")
stdout, stderr = await client.execute_bash("ls -la")
print(f"Output:\n{stdout}")
if stderr:
print(f"Error: {stderr}")
print("\nChecking system info:")
stdout, stderr = await client.execute_bash("uname -a")
print(f"Output: {stdout}")
print("\nRunning a pipe command:")
stdout, stderr = await client.execute_bash("find . -type f -name '*.py' | sort")
print(f"Python files:\n{stdout}")
if __name__ == "__main__":
asyncio.run(main())