add webmcp
CI / Test + coverage (push) Successful in 59s

This commit is contained in:
2026-09-19 13:38:27 -09:00
parent aa4f8ea86a
commit 5aaf5a8d6c
12 changed files with 1919 additions and 17 deletions
+14 -8
View File
@@ -1,5 +1,6 @@
(ns tbd.core
(:require [ring.adapter.jetty :as jetty]
(:require [clojure.string :as str]
[ring.adapter.jetty :as jetty]
[ring.middleware.defaults :refer [wrap-defaults api-defaults]]
[ring.middleware.head :refer [wrap-head]]
[reitit.ring :as ring]
@@ -45,10 +46,14 @@
:details (:humanized (reitit.coercion/encode-error (ex-data e)))}))
(defn- index-handler
"The HTML shell for the re-frame UI (ui/); it loads the compiled JS from /js."
[_req]
(-> (response/resource-response "public/index.html")
(response/content-type "text/html; charset=utf-8")))
"The HTML shell for the re-frame UI (ui/); it loads the compiled JS from /js. With a WebMCP
origin-trial token it also sends it as an `Origin-Trial` header, which is how Chrome enables the
trial for this origin before any script runs."
[{:keys [origin-trial-token]}]
(fn [_req]
(cond-> (-> (response/resource-response "public/index.html")
(response/content-type "text/html; charset=utf-8"))
(seq origin-trial-token) (response/header "Origin-Trial" origin-trial-token))))
(defn- decode-error-handler
"A request body that isn't valid for its Content-Type -> 400, in the same shape (and format) the routes use."
@@ -63,7 +68,7 @@
;; Each logical group (health, users, orders, ...) owns a `tbd.<group>.routes`
;; namespace that returns its own route subtree; they're concatenated here.
(defn make-router [{:keys [auth nrepl todo oauth]}]
(defn make-router [{:keys [auth nrepl todo oauth webmcp]}]
(let [oauth-ds (delay (oauth-db/open (:db-path oauth)))
;; Opened (and migrated) on first use, not when the app loads.
todo-ds (delay (todo-db/open (:db-path todo)))]
@@ -75,7 +80,7 @@
:swagger {:info {:title "tbd API" :version "1.0.0"}}
:handler (swagger-handler)}}]
["/" {:get {:no-doc true
:handler index-handler}}]
:handler (index-handler webmcp)}}]
(health/routes)
(math/routes)
(mcp-routes/routes auth oauth-ds todo-ds)
@@ -116,7 +121,8 @@
{:auth (auth/env-config)
:nrepl (nrepl/env-config)
:todo (todo-db/env-config)
:oauth (oauth-db/env-config)})
:oauth (oauth-db/env-config)
:webmcp {:origin-trial-token (some-> (System/getenv "WEBMCP_ORIGIN_TRIAL_TOKEN") str/trim not-empty)}})
(def app (make-app config))