#!/usr/bin/env python3
"""MCP Client to interact with the task manager server."""
import json
import subprocess
import sys
from datetime import datetime, timedelta
def call_mcp_tool(tool_name: str, arguments: dict):
"""Call an MCP tool through the server process."""
# Start the server process
proc = subprocess.Popen(
[sys.executable, "task_manager.py"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True
)
# Create JSON-RPC request
request = {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": tool_name,
"arguments": arguments
}
}
# Send request
proc.stdin.write(json.dumps(request) + "\n")
proc.stdin.flush()
# Read response
response_line = proc.stdout.readline()
proc.terminate()
if response_line:
return json.loads(response_line)
return None
# Add task for tomorrow
tomorrow = (datetime.now() + timedelta(days=1)).strftime("%Y-%m-%d")
result = call_mcp_tool("add_task", {
"description": "buy grocery",
"due_date": tomorrow
})
if result:
print(f"✓ Task added successfully!")
print(json.dumps(result, indent=2))
else:
print("✗ Failed to add task")