Repository navigation
Expand file tree
/
Copy pathpython_client.py
More file actions
68 lines (53 loc) · 2.06 KB
/
Copy pathpython_client.py
File metadata and controls
68 lines (53 loc) · 2.06 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""Minimal EasyAccessPDF MCP client — plain HTTP + JSON-RPC 2.0, no SDK.
Usage:
1. pip install requests
2. Set EAP_EMAIL and EAP_APP_PASSWORD environment variables
3. python python_client.py
"""
import base64
import json
import os
import sys
import requests
ENDPOINT = "https://easyaccesspdf.com/wp-json/easy/v1/mcp"
email = os.environ.get("EAP_EMAIL", "you@example.com")
app_password = os.environ.get("EAP_APP_PASSWORD", "xxxx xxxx xxxx xxxx xxxx xxxx")
token = base64.b64encode(f"{email}:{app_password}".encode()).decode()
HEADERS = {
"Authorization": f"Basic {token}",
"Content-Type": "application/json",
"Accept": "application/json, text/event-stream",
}
def rpc(method: str, params: dict | None = None, _id: int = 1) -> dict:
payload = {"jsonrpc": "2.0", "id": _id, "method": method, "params": params or {}}
r = requests.post(ENDPOINT, headers=HEADERS, json=payload, timeout=180)
r.raise_for_status()
return r.json()
def main() -> int:
# 1. initialize
init = rpc("initialize", {
"protocolVersion": "2025-03-26",
"capabilities": {},
"clientInfo": {"name": "python-minimal", "version": "1.0"},
})
server = init.get("result", {}).get("serverInfo", {})
print(f"connected: {server.get('name')} v{server.get('version')}")
# 2. list tools
tools = rpc("tools/list", _id=2).get("result", {}).get("tools", [])
print(f"tools ({len(tools)}): " + ", ".join(t["name"] for t in tools))
# 3. account status (free with membership)
status = rpc("tools/call", {
"name": "eap_get_account_status", "arguments": {},
}, _id=3)
text = status["result"]["content"][0]["text"]
print("account:", json.dumps(json.loads(text), indent=2)[:400])
# 4. example: check a PDF (needs an active membership)
# result = rpc("tools/call", {
# "name": "eap_check_pdf",
# "arguments": {"url": "https://example.com/your-document.pdf"},
# }, _id=4)
# print(result["result"]["content"][0]["text"])
return 0
if __name__ == "__main__":
sys.exit(main())