diff --git a/pyproject.toml b/pyproject.toml index 0be04d5..4dedccd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,6 +9,7 @@ dependencies = [ "fastmcp>=0.4.1", "starlette>=0.41.0", "uvicorn>=0.32.0", + "httpx>=0.27.0", "aiohttp>=3.9.0", "fastapi>=0.136.1", "greenlet>=3.2.3", diff --git a/upload_cookies.py b/upload_cookies.py new file mode 100755 index 0000000..5d27ece --- /dev/null +++ b/upload_cookies.py @@ -0,0 +1,57 @@ +#!/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)) diff --git a/uv.lock b/uv.lock index 35b7693..5ded445 100644 --- a/uv.lock +++ b/uv.lock @@ -1715,6 +1715,7 @@ dependencies = [ { name = "fastapi" }, { name = "fastmcp" }, { name = "greenlet" }, + { name = "httpx" }, { name = "mcp" }, { name = "pdfplumber" }, { name = "playwright" }, @@ -1730,6 +1731,7 @@ requires-dist = [ { name = "fastapi", specifier = ">=0.136.1" }, { name = "fastmcp", specifier = ">=0.4.1" }, { name = "greenlet", specifier = ">=3.2.3" }, + { name = "httpx", specifier = ">=0.27.0" }, { name = "mcp", specifier = ">=1.2.0" }, { name = "pdfplumber", specifier = ">=0.11.4" }, { name = "playwright", specifier = "==1.54.0" },