@cliptude/cli 0.1.3 → 0.1.5

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.
package/README.md CHANGED
@@ -6,7 +6,7 @@ Generate videos from a saved template. Same account and credits as cliptude.com.
6
6
 
7
7
  1. Install the CLI: run `npm i -g @cliptude/cli`.
8
8
  2. Authenticate: run `cliptude auth login` and complete the sign-in in the browser it opens.
9
- 3. Install the companion skills: run `npx skills add cliptude/cliptude --path mcp_server/skills`.
9
+ 3. Install the companion skills: run `npx skills add cliptude/cliptude --path mcp_server/skills` (includes **cliptude**, **cliptude-script**, and **cliptude-faceless**).
10
10
 
11
11
  From this repo without npm:
12
12
 
@@ -21,15 +21,16 @@ cliptude auth login
21
21
  cliptude templates
22
22
  cliptude generate --template "Finance vector weekly" --title "Why index funds win" --prompt "why most retail traders underperform the S&P over 10 years, keep it for beginners" --duration 3-4
23
23
  cliptude generate --template "Finance vector weekly" --title "Why index funds win" --script-file script.txt
24
+ cliptude generate --template "Finance vector weekly" --title "Why index funds win" --voiceover narration.mp3
24
25
  cliptude status <job-id>
25
26
  ```
26
27
 
27
- `--title` is required. Optional `--duration` is a wizard bucket (`3-4`, `6-8`, `10-12`, …). Omit it to use the template duration, or the word-count estimate when you pass `--script`. `generate` returns immediately (`queued`). Poll `status`.
28
+ `--title` is required. Provide **one** of `--prompt`, `--script` / `--script-file`, or `--voiceover`. Never copy the title into `--prompt`. If you only have a topic, follow **cliptude-script** (web search → spoken narration → `--script-file`). `--voiceover` is a local audio file (same as create.html); it is transcribed and skips TTS — do not combine it with prompt/script. Optional `--duration` is a wizard bucket (`3-4`, `6-8`, `10-12`, …). Omit it to use the template duration, or the word-count estimate when you pass `--script`. Uploaded audio sets duration from the file. `generate` returns immediately (`queued`). Poll `status`.
28
29
 
29
- Faceless bring-your-own coding:
30
+ Faceless Explainer on CLI/MCP defaults to `--faceless-coding external` (this session authors HTML). Pass `--faceless-coding cliptude` to let Cliptude code. REST omit still means Cliptude codes.
30
31
 
31
32
  ```bash
32
- cliptude generate --template "My Faceless" --title "Why index funds win" --prompt "why most retail traders underperform the S&P over 10 years, keep it for beginners" --faceless-coding external
33
+ cliptude generate --template "My Faceless" --title "Why index funds win" --script-file script.txt
33
34
  cliptude kit <job-id> --out ./kit.zip
34
35
  cliptude submit-project <job-id> ./project.zip
35
36
  ```
@@ -7,7 +7,7 @@ from typing import Any
7
7
 
8
8
  import httpx
9
9
 
10
- from cliptude_mcp.client import resolve_base_url
10
+ from cliptude_mcp.client import django_proxy_headers, resolve_base_url
11
11
 
12
12
 
13
13
  def _resource_url() -> str:
@@ -39,6 +39,7 @@ class CliptudeTokenVerifier:
39
39
  headers={
40
40
  "Authorization": f"Bearer {token}",
41
41
  "Accept": "application/json",
42
+ **django_proxy_headers(self.base_url),
42
43
  },
43
44
  )
44
45
  except httpx.HTTPError:
@@ -80,3 +81,34 @@ def auth_settings():
80
81
  resource_server_url=AnyHttpUrl(_resource_url()),
81
82
  required_scopes=["jobs"],
82
83
  )
84
+
85
+
86
+ def protected_resource_metadata() -> dict[str, Any]:
87
+ """RFC 9728 document. Served at both path-inserted and origin-root well-known URLs."""
88
+ return {
89
+ "resource": _resource_url(),
90
+ "authorization_servers": [_issuer_url()],
91
+ "bearer_methods_supported": ["header"],
92
+ "scopes_supported": ["jobs"],
93
+ }
94
+
95
+
96
+ def authorization_server_metadata() -> dict[str, Any]:
97
+ """RFC 8414 document pointing at cliptude.com (not the MCP origin)."""
98
+ issuer = _issuer_url()
99
+ return {
100
+ "issuer": issuer,
101
+ "authorization_endpoint": f"{issuer}/o/authorize/",
102
+ "token_endpoint": f"{issuer}/o/token/",
103
+ "registration_endpoint": f"{issuer}/o/register/",
104
+ "revocation_endpoint": f"{issuer}/o/revoke_token/",
105
+ "response_types_supported": ["code"],
106
+ "grant_types_supported": ["authorization_code", "refresh_token"],
107
+ "code_challenge_methods_supported": ["S256"],
108
+ "token_endpoint_auth_methods_supported": [
109
+ "none",
110
+ "client_secret_post",
111
+ "client_secret_basic",
112
+ ],
113
+ "scopes_supported": ["jobs"],
114
+ }
@@ -94,7 +94,11 @@ def main(argv: list[str] | None = None) -> None:
94
94
  "example:\n"
95
95
  ' cliptude generate --template "Finance vector weekly" --title "Why index funds win" '
96
96
  '--prompt "why most retail traders underperform the S&P over 10 years, keep it for beginners" '
97
- '--duration 3-4'
97
+ '--duration 3-4\n'
98
+ ' cliptude generate --template "Finance vector weekly" --title "Why index funds win" '
99
+ '--script-file script.txt\n'
100
+ ' cliptude generate --template "Finance vector weekly" --title "Why index funds win" '
101
+ '--voiceover narration.mp3'
98
102
  ),
99
103
  )
100
104
  g.add_argument("--template", required=True, help="Template name or UUID")
@@ -107,9 +111,17 @@ def main(argv: list[str] | None = None) -> None:
107
111
  g.add_argument("--script", default="")
108
112
  g.add_argument("--script-file", default="")
109
113
  g.add_argument(
110
- "--faceless-coding",
114
+ "--voiceover",
111
115
  default="",
112
- help="external = you author Faceless storyboard/HTML; omit for Cliptude coding",
116
+ help="Path to a narration audio file (MP3, M4A, WAV, …). Transcribed; skips TTS. Do not combine with --prompt or --script.",
117
+ )
118
+ g.add_argument(
119
+ "--faceless-coding",
120
+ default="external",
121
+ help=(
122
+ "Faceless Explainer: default external (this session authors HTML). "
123
+ "Pass cliptude to let Cliptude code. Ignored on other formats."
124
+ ),
113
125
  )
114
126
  g.add_argument(
115
127
  "--duration",
@@ -149,16 +161,23 @@ def main(argv: list[str] | None = None) -> None:
149
161
  script = args.script
150
162
  if args.script_file:
151
163
  script = Path(args.script_file).read_text(encoding="utf-8")
152
- if not (args.prompt or script):
153
- raise CliptudeApiError("Provide --prompt or --script / --script-file.")
164
+ voiceover = (args.voiceover or "").strip()
165
+ if voiceover and (args.prompt or script):
166
+ raise CliptudeApiError(
167
+ "Use --voiceover or --prompt/--script, not both. "
168
+ "An uploaded file is transcribed and used as the narration."
169
+ )
170
+ if not voiceover and not (args.prompt or script):
171
+ raise CliptudeApiError("Provide --prompt, --script / --script-file, or --voiceover.")
154
172
  template_id = _resolve_template_id(client, args.template)
155
173
  _print(client.create_job(
156
174
  template_id=template_id,
157
175
  title=args.title,
158
176
  prompt=args.prompt or None,
159
177
  script=script or None,
160
- faceless_coding=(args.faceless_coding or None),
178
+ faceless_coding=args.faceless_coding,
161
179
  duration=(args.duration or None),
180
+ voiceover_path=voiceover or None,
162
181
  ))
163
182
  elif args.cmd == "kit":
164
183
  dest = Path(args.out)
@@ -13,6 +13,9 @@ import httpx
13
13
  from cliptude_mcp.credentials import stored_access_token
14
14
 
15
15
  DEFAULT_SAAS_URL = "https://cliptude.com"
16
+ FACELESS_EXPLAINER_FORMAT = "faceless_explainer"
17
+ FACELESS_CODING_EXTERNAL = "external"
18
+ FACELESS_CODING_CLIPTUDE = "cliptude"
16
19
  _request_token: ContextVar[str | None] = ContextVar("cliptude_request_token", default=None)
17
20
 
18
21
 
@@ -53,6 +56,18 @@ def resolve_base_url() -> str:
53
56
  return desktop or DEFAULT_SAAS_URL
54
57
 
55
58
 
59
+ def django_proxy_headers(base_url: str) -> dict[str, str]:
60
+ """Mark docker-internal HTTP as HTTPS so Django skips SECURE_SSL_REDIRECT.
61
+
62
+ Production Django 301s ``http://web:5021`` to ``https://web:5021``. That
63
+ handshake times out inside the compose network, so MCP token verification
64
+ always failed after a successful OAuth exchange.
65
+ """
66
+ if (base_url or "").strip().lower().startswith("http://"):
67
+ return {"X-Forwarded-Proto": "https"}
68
+ return {}
69
+
70
+
56
71
  class CliptudeApiError(Exception):
57
72
  def __init__(self, message: str, status: int | None = None, payload: Any = None):
58
73
  super().__init__(message)
@@ -80,14 +95,17 @@ class CliptudeClient:
80
95
  or (os.environ.get("CLIPTUDE_API_KEY") or "").strip()
81
96
  )
82
97
 
83
- def _headers(self) -> dict[str, str]:
98
+ def _headers(self, *, json_content: bool = True) -> dict[str, str]:
84
99
  if not self.api_key:
85
100
  raise CliptudeApiError("Not authenticated. Run: cliptude auth login")
86
- return {
101
+ headers = {
87
102
  "Authorization": f"Bearer {self.api_key}",
88
103
  "Accept": "application/json",
89
- "Content-Type": "application/json",
104
+ **django_proxy_headers(self.base_url),
90
105
  }
106
+ if json_content:
107
+ headers["Content-Type"] = "application/json"
108
+ return headers
91
109
 
92
110
  def _maybe_refresh(self) -> bool:
93
111
  if not self._session_file:
@@ -136,6 +154,26 @@ class CliptudeClient:
136
154
  def get_template(self, template_id: str) -> Any:
137
155
  return self.request("GET", f"/api/v1/templates/{template_id}")
138
156
 
157
+ def _template_format(self, template_id: str) -> str:
158
+ try:
159
+ tmpl = self.get_template(template_id)
160
+ except CliptudeApiError:
161
+ return ""
162
+ if not isinstance(tmpl, dict):
163
+ return ""
164
+ return str(tmpl.get("format") or "").strip().lower()
165
+
166
+ def _resolve_faceless_coding(self, template_id: str, faceless_coding: str | None) -> str | None:
167
+ """CLI/MCP default is external for Faceless Explainer. Other formats omit the field."""
168
+ raw = (faceless_coding or "").strip().lower() or None
169
+ if raw == FACELESS_CODING_CLIPTUDE:
170
+ return FACELESS_CODING_CLIPTUDE
171
+ if raw not in (None, FACELESS_CODING_EXTERNAL):
172
+ return raw
173
+ if self._template_format(template_id) == FACELESS_EXPLAINER_FORMAT:
174
+ return FACELESS_CODING_EXTERNAL
175
+ return None
176
+
139
177
  def create_job(
140
178
  self,
141
179
  *,
@@ -145,18 +183,79 @@ class CliptudeClient:
145
183
  script: str | None = None,
146
184
  faceless_coding: str | None = None,
147
185
  duration: str | None = None,
186
+ voiceover_path: str | Path | None = None,
148
187
  ) -> Any:
188
+ coding = self._resolve_faceless_coding(template_id, faceless_coding)
189
+ if voiceover_path:
190
+ return self._create_job_multipart(
191
+ template_id=template_id,
192
+ title=title,
193
+ faceless_coding=coding,
194
+ duration=duration,
195
+ voiceover_path=voiceover_path,
196
+ )
149
197
  body: dict[str, Any] = {"template_id": template_id, "title": title}
150
198
  if prompt:
151
199
  body["prompt"] = prompt
152
200
  if script:
153
201
  body["script"] = script
154
- if faceless_coding:
155
- body["faceless_coding"] = faceless_coding
202
+ if coding:
203
+ body["faceless_coding"] = coding
156
204
  if duration:
157
205
  body["duration"] = duration
158
206
  return self.request("POST", "/api/v1/jobs", json_body=body)
159
207
 
208
+ def _create_job_multipart(
209
+ self,
210
+ *,
211
+ template_id: str,
212
+ title: str,
213
+ faceless_coding: str | None,
214
+ duration: str | None,
215
+ voiceover_path: str | Path,
216
+ _retried: bool = False,
217
+ ) -> Any:
218
+ path = Path(voiceover_path)
219
+ if not path.is_file():
220
+ raise CliptudeApiError(f"Voiceover file not found: {path}")
221
+ data: dict[str, str] = {"template_id": str(template_id), "title": title}
222
+ if faceless_coding:
223
+ data["faceless_coding"] = faceless_coding
224
+ if duration:
225
+ data["duration"] = duration
226
+ url = f"{self.base_url}/api/v1/jobs"
227
+ headers = self._headers(json_content=False)
228
+ try:
229
+ with path.open("rb") as fh:
230
+ resp = httpx.post(
231
+ url,
232
+ headers=headers,
233
+ data=data,
234
+ files={"voiceover": (path.name, fh, "application/octet-stream")},
235
+ timeout=max(self.timeout, 300.0),
236
+ )
237
+ except httpx.HTTPError as exc:
238
+ raise CliptudeApiError(str(exc)) from exc
239
+ if resp.status_code == 401 and not _retried and self._maybe_refresh():
240
+ return self._create_job_multipart(
241
+ template_id=template_id,
242
+ title=title,
243
+ faceless_coding=faceless_coding,
244
+ duration=duration,
245
+ voiceover_path=voiceover_path,
246
+ _retried=True,
247
+ )
248
+ try:
249
+ payload = resp.json()
250
+ except ValueError:
251
+ payload = {"error": resp.text}
252
+ if resp.status_code >= 400:
253
+ message = payload.get("error") if isinstance(payload, dict) else str(payload)
254
+ if resp.status_code == 401:
255
+ message = message or "Not authenticated. Run: cliptude auth login"
256
+ raise CliptudeApiError(message or f"HTTP {resp.status_code}", status=resp.status_code, payload=payload)
257
+ return payload
258
+
160
259
  def get_job(self, job_id: str) -> Any:
161
260
  return self.request("GET", f"/api/v1/jobs/{job_id}")
162
261
 
@@ -177,6 +276,7 @@ class CliptudeClient:
177
276
  headers={
178
277
  "Authorization": f"Bearer {self.api_key}",
179
278
  "Accept": "application/zip, application/json",
279
+ **django_proxy_headers(self.base_url),
180
280
  },
181
281
  timeout=self.timeout,
182
282
  follow_redirects=True,
@@ -208,6 +308,7 @@ class CliptudeClient:
208
308
  headers = {
209
309
  "Authorization": f"Bearer {self.api_key}",
210
310
  "Accept": "application/json",
311
+ **django_proxy_headers(self.base_url),
211
312
  }
212
313
  try:
213
314
  with path.open("rb") as fh:
@@ -35,6 +35,53 @@ def _err(exc: Exception) -> dict[str, Any]:
35
35
  return {"error": str(exc)}
36
36
 
37
37
 
38
+ def mcp_allowed_hosts(resource_url: str | None = None) -> list[str]:
39
+ """Host header values the Streamable HTTP transport should accept.
40
+
41
+ The SDK auto-allowlists only localhost when streamable_http_app() is called
42
+ with the default host. Public MCP is reached as mcp.cliptude.com via nginx,
43
+ so authenticated POSTs otherwise return 421 Invalid Host header.
44
+ """
45
+ hosts = ["127.0.0.1:*", "localhost:*", "[::1]:*"]
46
+ extra = (os.environ.get("MCP_ALLOWED_HOSTS") or "").strip()
47
+ if extra:
48
+ hosts.extend(h.strip() for h in extra.split(",") if h.strip())
49
+ return hosts
50
+ from urllib.parse import urlparse
51
+
52
+ parsed = urlparse(
53
+ resource_url
54
+ or os.environ.get("MCP_RESOURCE_URL")
55
+ or "https://mcp.cliptude.com/mcp"
56
+ )
57
+ hostname = (parsed.hostname or "").strip()
58
+ if hostname:
59
+ hosts.append(hostname)
60
+ hosts.append(f"{hostname}:*")
61
+ return hosts
62
+
63
+
64
+ def mcp_allowed_origins(resource_url: str | None = None) -> list[str]:
65
+ origins = ["http://127.0.0.1:*", "http://localhost:*", "http://[::1]:*"]
66
+ extra = (os.environ.get("MCP_ALLOWED_ORIGINS") or "").strip()
67
+ if extra:
68
+ origins.extend(o.strip() for o in extra.split(",") if o.strip())
69
+ return origins
70
+ from urllib.parse import urlparse
71
+
72
+ parsed = urlparse(
73
+ resource_url
74
+ or os.environ.get("MCP_RESOURCE_URL")
75
+ or "https://mcp.cliptude.com/mcp"
76
+ )
77
+ hostname = (parsed.hostname or "").strip()
78
+ scheme = (parsed.scheme or "https").strip() or "https"
79
+ if hostname:
80
+ origins.append(f"{scheme}://{hostname}")
81
+ origins.append(f"{scheme}://{hostname}:*")
82
+ return origins
83
+
84
+
38
85
  def build_server(*, with_http_auth: bool = False):
39
86
  from mcp.server import MCPServer
40
87
  from mcp.types import ToolAnnotations
@@ -42,9 +89,16 @@ def build_server(*, with_http_auth: bool = False):
42
89
  kwargs: dict[str, Any] = {
43
90
  "instructions": (
44
91
  "Generate Cliptude videos from a saved template. "
45
- "Call list_templates, then create_job with template_id + title + prompt or script. "
92
+ "Call list_templates, then create_job with template_id + title plus "
93
+ "prompt, script, or voiceover_path (uploaded audio, transcribed; skips TTS). "
46
94
  "create_job returns immediately; poll get_job until completed or failed. "
47
- "If the user pastes a full narration, pass it as script, not prompt."
95
+ "Never set prompt to the video title. If the user only named a topic or title, "
96
+ "web-search current facts, write spoken narration, and pass it as script. "
97
+ "If the user pastes a full narration, pass it as script, not prompt. "
98
+ "If they provide a voiceover file, pass voiceover_path and omit prompt/script. "
99
+ "Faceless Explainer jobs default to faceless_coding=external (this session "
100
+ "authors HTML). Pass faceless_coding=cliptude only if the user wants Cliptude "
101
+ "to code the visuals."
48
102
  ),
49
103
  }
50
104
  if with_http_auth:
@@ -86,19 +140,42 @@ def build_server(*, with_http_auth: bool = False):
86
140
  def create_job(
87
141
  template_id: Annotated[str, Field(min_length=8, description="Saved template UUID")],
88
142
  title: Annotated[str, Field(min_length=1, max_length=255, description="Video title")],
89
- prompt: Annotated[str | None, Field(description="Topic/brief. Cliptude writes the narration.")] = None,
90
- script: Annotated[str | None, Field(description="Custom spoken narration. Cliptude does not rewrite it.")] = None,
91
- faceless_coding: Annotated[
143
+ prompt: Annotated[str | None, Field(description="Topic/brief for Cliptude to write the VO. Never the video title. Prefer script after research.")] = None,
144
+ script: Annotated[str | None, Field(description="Spoken narration. Use this when the user gave a topic (after web search) or pasted a script. Cliptude does not rewrite it.")] = None,
145
+ voiceover_path: Annotated[
92
146
  str | None,
93
- Field(description='Use "external" for Faceless Explainer BYO HTML. Omit for Cliptude coding.'),
147
+ Field(
148
+ description=(
149
+ "Local path to a narration audio file (MP3, M4A, WAV, …). "
150
+ "Cliptude transcribes it and skips TTS. Do not also send prompt or script. "
151
+ "Stdio / local MCP only — remote hosts should use the CLI."
152
+ ),
153
+ ),
94
154
  ] = None,
155
+ faceless_coding: Annotated[
156
+ str | None,
157
+ Field(
158
+ description=(
159
+ 'Faceless Explainer only. Default "external": this session authors HTML. '
160
+ 'Pass "cliptude" to let Cliptude code. Other formats ignore this field.'
161
+ ),
162
+ ),
163
+ ] = "external",
95
164
  duration: Annotated[
96
165
  str | None,
97
- Field(description="Wizard duration bucket such as 3-4 or 6-8. Omit to use the template (or estimate from script)."),
166
+ Field(description="Wizard duration bucket such as 3-4 or 6-8. Omit to use the template (or estimate from script). Ignored when voiceover_path is set — duration comes from the audio."),
98
167
  ] = None,
99
168
  ) -> dict[str, Any]:
100
- """Start generation and return a job id immediately. Do not wait for the MP4. Poll get_job. Provide prompt and/or script."""
169
+ """Start generation and return a job id immediately. Do not wait for the MP4. Poll get_job. Provide prompt, script, or voiceover_path. Never copy the title into prompt; for a topic-only request write a spoken script after web search and pass script. Uploaded audio is transcribed. Faceless Explainer defaults to faceless_coding=external; pass cliptude only if the user wants Cliptude to code."""
101
170
  try:
171
+ vo = (voiceover_path or "").strip() or None
172
+ if vo and ((prompt or "").strip() or (script or "").strip()):
173
+ return {
174
+ "error": (
175
+ "Upload a voiceover, or send a prompt / custom script — not both. "
176
+ "An uploaded file is transcribed and used as the narration."
177
+ )
178
+ }
102
179
  return _client().create_job(
103
180
  template_id=template_id,
104
181
  title=title,
@@ -106,6 +183,7 @@ def build_server(*, with_http_auth: bool = False):
106
183
  script=script,
107
184
  faceless_coding=faceless_coding,
108
185
  duration=duration,
186
+ voiceover_path=vo,
109
187
  )
110
188
  except Exception as exc:
111
189
  return _err(exc)
@@ -207,12 +285,105 @@ def build_server(*, with_http_auth: bool = False):
207
285
  """Use a saved Cliptude template to generate a video from a topic or a custom script."""
208
286
  return (
209
287
  "List my Cliptude templates, pick the one I name, then create_job "
210
- "with title plus prompt (topic) or script (full narration). Poll get_job."
288
+ "with title plus prompt (topic), script (full narration), or "
289
+ "voiceover_path (local audio file). Poll get_job. "
290
+ "Faceless Explainer defaults to faceless_coding=external."
211
291
  )
212
292
 
213
293
  return mcp
214
294
 
215
295
 
296
+ def _cors_json(payload: dict[str, Any]):
297
+ from starlette.responses import JSONResponse
298
+
299
+ response = JSONResponse(payload)
300
+ response.headers["Access-Control-Allow-Origin"] = "*"
301
+ response.headers["Access-Control-Allow-Headers"] = "Authorization, Content-Type"
302
+ response.headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS"
303
+ return response
304
+
305
+
306
+ def _discovery_starlette(inner):
307
+ """Cursor's OAuth callback rediscovers AS via origin-root well-known, not WWW-Authenticate.
308
+
309
+ RFC 9728 path-inserted metadata lives at /.well-known/oauth-protected-resource/mcp.
310
+ Cursor also requests /.well-known/oauth-protected-resource (no /mcp). A 404 there
311
+ makes it treat mcp.cliptude.com as the authorization server and hang on token exchange.
312
+
313
+ The inner Streamable HTTP app's lifespan must be forwarded. Mount() does not
314
+ start it, and without session_manager.run() every POST /mcp raises
315
+ ``Task group is not initialized``.
316
+ """
317
+ from contextlib import asynccontextmanager
318
+
319
+ from starlette.applications import Starlette
320
+ from starlette.responses import Response
321
+ from starlette.routing import Mount, Route
322
+
323
+ from cliptude_mcp.auth import authorization_server_metadata, protected_resource_metadata
324
+
325
+ async def options(_request):
326
+ response = Response(status_code=204)
327
+ response.headers["Access-Control-Allow-Origin"] = "*"
328
+ response.headers["Access-Control-Allow-Headers"] = "Authorization, Content-Type"
329
+ response.headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS"
330
+ return response
331
+
332
+ async def prm(_request):
333
+ return _cors_json(protected_resource_metadata())
334
+
335
+ async def oauth_as(_request):
336
+ return _cors_json(authorization_server_metadata())
337
+
338
+ inner_lifespan = inner.router.lifespan_context
339
+
340
+ @asynccontextmanager
341
+ async def lifespan(app):
342
+ async with inner_lifespan(inner):
343
+ yield
344
+
345
+ return Starlette(
346
+ routes=[
347
+ Route("/.well-known/oauth-protected-resource", prm, methods=["GET"]),
348
+ Route("/.well-known/oauth-protected-resource", options, methods=["OPTIONS"]),
349
+ Route("/.well-known/oauth-authorization-server", oauth_as, methods=["GET"]),
350
+ Route("/.well-known/oauth-authorization-server", options, methods=["OPTIONS"]),
351
+ Mount("/", app=inner),
352
+ ],
353
+ lifespan=lifespan,
354
+ )
355
+
356
+
357
+ def _run_http(mcp, host: str, port: int) -> None:
358
+ inner = None
359
+ transport_security = None
360
+ try:
361
+ from mcp.server.transport_security import TransportSecuritySettings
362
+
363
+ transport_security = TransportSecuritySettings(
364
+ enable_dns_rebinding_protection=True,
365
+ allowed_hosts=mcp_allowed_hosts(),
366
+ allowed_origins=mcp_allowed_origins(),
367
+ )
368
+ except ImportError:
369
+ transport_security = None
370
+ for attr in ("streamable_http_app", "http_app"):
371
+ fn = getattr(mcp, attr, None)
372
+ if not callable(fn):
373
+ continue
374
+ try:
375
+ inner = fn(host=host, transport_security=transport_security)
376
+ except TypeError:
377
+ inner = fn()
378
+ break
379
+ if inner is None:
380
+ mcp.run(transport="streamable-http", host=host, port=port)
381
+ return
382
+ import uvicorn
383
+
384
+ uvicorn.run(_discovery_starlette(inner), host=host, port=port)
385
+
386
+
216
387
  def main() -> None:
217
388
  transport = (os.environ.get("CLIPTUDE_MCP_TRANSPORT") or "stdio").strip().lower()
218
389
  http_mode = transport in {"http", "streamable-http", "streamable_http"}
@@ -221,7 +392,7 @@ def main() -> None:
221
392
  host = os.environ.get("CLIPTUDE_MCP_HOST", "0.0.0.0")
222
393
  port = int(os.environ.get("CLIPTUDE_MCP_PORT") or "8787")
223
394
  logger.info("Starting Streamable HTTP MCP on %s:%s", host, port)
224
- mcp.run(transport="streamable-http", host=host, port=port)
395
+ _run_http(mcp, host, port)
225
396
  return
226
397
  mcp.run()
227
398
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cliptude/cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Cliptude CLI — generate videos from saved templates.",
5
5
  "homepage": "https://github.com/cliptude/cliptude#readme",
6
6
  "bin": {
package/pyproject.toml CHANGED
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "cliptude-mcp"
7
- version = "0.1.3"
7
+ version = "0.1.5"
8
8
  description = "Cliptude jobs CLI and MCP server (thin client of /api/v1)."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"