Files
schwab-mcp-custom/upload_cookies.py
b3nw e14e060576
All checks were successful
Build and Push Docker Image / build (push) Successful in 34s
Add local helper script for cookie uploading
2026-04-24 02:01:38 +00:00

58 lines
1.7 KiB
Python
Executable File

#!/usr/bin/env python3
import json
import sys
import argparse
import httpx
import asyncio
async def upload_cookies(url, cookie_file):
try:
with open(cookie_file, 'r') as f:
cookies = json.load(f)
cookies_str = json.dumps(cookies)
except Exception as e:
print(f"Error reading {cookie_file}: {e}")
return
# MCP tool call payload
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "upload_cookies",
"arguments": {
"cookies_json": cookies_str
}
}
}
# Construct the /mcp endpoint if not provided
if not url.endswith('/mcp'):
url = url.rstrip('/') + '/mcp'
print(f"Uploading cookies to {url}...")
async with httpx.AsyncClient(timeout=30.0) as client:
try:
response = await client.post(url, json=payload)
response.raise_for_status()
result = response.json()
if "error" in result:
print(f"Error from server: {result['error']}")
else:
print(f"Server response: {result['result']['content'][0]['text']}")
except Exception as e:
print(f"Failed to upload cookies: {e}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Upload cookies.json to Schwab MCP server")
parser.add_argument("file", help="Path to cookies.json")
parser.add_argument("--url", default="http://localhost:8160", help="MCP server URL (default: http://localhost:8160)")
args = parser.parse_args()
asyncio.run(upload_cookies(args.url, args.file))