xtikapi-mcp 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .venv/
7
+ .pytest_cache/
8
+ .DS_Store
@@ -0,0 +1,19 @@
1
+ Metadata-Version: 2.5
2
+ Name: xtikapi-mcp
3
+ Version: 0.1.0
4
+ Summary: Zero-dependency Python stdio MCP server (uvx xtikapi-mcp) for XTikAPI — 19 social media platforms, 229 endpoints, 94.5% fewer tokens.
5
+ Project-URL: Homepage, https://xtikapi.com/mcp
6
+ Project-URL: Repository, https://github.com/xtikapi/xtikapi-python
7
+ Author-email: XTikAPI <support@xtikapi.com>
8
+ License-Expression: MIT
9
+ Keywords: ai-agent,douyin,mcp,social-media-api,tiktok,wechat,xiaohongshu,xtikapi
10
+ Requires-Python: >=3.9
11
+ Description-Content-Type: text/markdown
12
+
13
+ # xtikapi-mcp
14
+
15
+ Zero-dependency Python stdio MCP server (`uvx xtikapi-mcp`) bridging local MCP clients to `https://xtikapi.com/v1/mcp`.
16
+
17
+ ```bash
18
+ XTIKAPI_API_KEY=dk_your_key uvx xtikapi-mcp
19
+ ```
@@ -0,0 +1,7 @@
1
+ # xtikapi-mcp
2
+
3
+ Zero-dependency Python stdio MCP server (`uvx xtikapi-mcp`) bridging local MCP clients to `https://xtikapi.com/v1/mcp`.
4
+
5
+ ```bash
6
+ XTIKAPI_API_KEY=dk_your_key uvx xtikapi-mcp
7
+ ```
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.25.0"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "xtikapi-mcp"
7
+ version = "0.1.0"
8
+ description = "Zero-dependency Python stdio MCP server (uvx xtikapi-mcp) for XTikAPI — 19 social media platforms, 229 endpoints, 94.5% fewer tokens."
9
+ readme = "README.md"
10
+ license = "MIT"
11
+ requires-python = ">=3.9"
12
+ authors = [{ name = "XTikAPI", email = "support@xtikapi.com" }]
13
+ keywords = ["mcp", "xtikapi", "social-media-api", "douyin", "xiaohongshu", "tiktok", "wechat", "ai-agent"]
14
+ dependencies = []
15
+
16
+ [project.scripts]
17
+ xtikapi-mcp = "xtikapi_mcp:main"
18
+
19
+ [project.urls]
20
+ Homepage = "https://xtikapi.com/mcp"
21
+ Repository = "https://github.com/xtikapi/xtikapi-python"
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["src/xtikapi_mcp"]
@@ -0,0 +1,131 @@
1
+ """Zero-dependency stdio-to-Streamable-HTTP MCP bridge for XTikAPI."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import json
6
+ import os
7
+ import sys
8
+ import urllib.error
9
+ import urllib.request
10
+ from typing import List, Optional
11
+
12
+ DEFAULT_MCP_URL = "https://xtikapi.com/v1/mcp"
13
+
14
+
15
+ def _extract_sse_data(body: str) -> List[str]:
16
+ events: List[str] = []
17
+ data_lines: List[str] = []
18
+ for raw in body.splitlines():
19
+ if raw.startswith("data:"):
20
+ data_lines.append(raw[5:].lstrip())
21
+ elif raw == "" and data_lines:
22
+ joined = "\n".join(data_lines).strip()
23
+ if joined and joined != "[DONE]":
24
+ events.append(joined)
25
+ data_lines = []
26
+ if data_lines:
27
+ joined = "\n".join(data_lines).strip()
28
+ if joined and joined != "[DONE]":
29
+ events.append(joined)
30
+ return events
31
+
32
+
33
+ class McpBridge:
34
+ def __init__(self, api_key: Optional[str] = None, endpoint: Optional[str] = None) -> None:
35
+ self.api_key = (api_key if api_key is not None else os.environ.get("XTIKAPI_API_KEY", "")).strip()
36
+ self.endpoint = (endpoint or os.environ.get("XTIKAPI_MCP_URL") or DEFAULT_MCP_URL).strip()
37
+ self.session_id: Optional[str] = None
38
+
39
+ def forward(self, raw_line: str) -> List[str]:
40
+ try:
41
+ msg = json.loads(raw_line)
42
+ except json.JSONDecodeError:
43
+ return [json.dumps({"jsonrpc": "2.0", "id": None, "error": {"code": -32700, "message": "Parse error"}})]
44
+
45
+ has_id = isinstance(msg, dict) and "id" in msg and msg["id"] is not None
46
+ if not self.api_key:
47
+ if not has_id:
48
+ return []
49
+ return [
50
+ json.dumps(
51
+ {
52
+ "jsonrpc": "2.0",
53
+ "id": msg["id"],
54
+ "error": {
55
+ "code": -32001,
56
+ "message": "XTIKAPI_API_KEY is not set. Get a key at https://xtikapi.com/settings/apikeys",
57
+ },
58
+ }
59
+ )
60
+ ]
61
+
62
+ headers = {
63
+ "Content-Type": "application/json",
64
+ "Accept": "application/json, text/event-stream",
65
+ "Authorization": f"Bearer {self.api_key}",
66
+ "User-Agent": "xtikapi-mcp-py/0.1.0",
67
+ }
68
+ if self.session_id:
69
+ headers["Mcp-Session-Id"] = self.session_id
70
+
71
+ req = urllib.request.Request(self.endpoint, data=raw_line.encode("utf-8"), headers=headers, method="POST")
72
+ try:
73
+ with urllib.request.urlopen(req, timeout=45) as resp:
74
+ next_sid = resp.headers.get("Mcp-Session-Id")
75
+ if next_sid:
76
+ self.session_id = next_sid
77
+ if resp.status in (202, 204):
78
+ return []
79
+ content_type = resp.headers.get("Content-Type", "")
80
+ body = resp.read().decode("utf-8", errors="replace")
81
+ if "text/event-stream" in content_type:
82
+ return _extract_sse_data(body)
83
+ return [body.strip()] if body.strip() else []
84
+ except urllib.error.HTTPError as exc:
85
+ body = exc.read().decode("utf-8", errors="replace")
86
+ if body.strip().startswith("{"):
87
+ return [body.strip()]
88
+ if not has_id:
89
+ return []
90
+ return [
91
+ json.dumps(
92
+ {
93
+ "jsonrpc": "2.0",
94
+ "id": msg["id"],
95
+ "error": {"code": -32000, "message": f"HTTP {exc.code}: {body or exc.reason}"},
96
+ }
97
+ )
98
+ ]
99
+ except Exception as exc:
100
+ if not has_id:
101
+ return []
102
+ return [
103
+ json.dumps(
104
+ {
105
+ "jsonrpc": "2.0",
106
+ "id": msg["id"],
107
+ "error": {"code": -32603, "message": f"Failed to reach {self.endpoint}: {exc}"},
108
+ }
109
+ )
110
+ ]
111
+
112
+
113
+ def main() -> None:
114
+ if any(arg in ("-h", "--help") for arg in sys.argv[1:]):
115
+ sys.stderr.write(
116
+ "xtikapi-mcp — Stdio MCP bridge to https://xtikapi.com/v1/mcp\n"
117
+ "Usage: XTIKAPI_API_KEY=dk_your_key uvx xtikapi-mcp\n"
118
+ )
119
+ return
120
+ bridge = McpBridge()
121
+ for line in sys.stdin:
122
+ trimmed = line.strip()
123
+ if not trimmed:
124
+ continue
125
+ for out in bridge.forward(trimmed):
126
+ sys.stdout.write(out + "\n")
127
+ sys.stdout.flush()
128
+
129
+
130
+ if __name__ == "__main__":
131
+ main()