teapot-coding-agent 0.29.30 → 0.29.32
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/dist/agent/mcp-oauth-manager.js +342 -0
- package/dist/agent/mcp-oauth.js +429 -0
- package/dist/agent/mcp-registry.js +45 -2
- package/dist/agent/mcp.js +20 -0
- package/dist/master.js +47 -16
- package/dist/server/api.js +83 -0
- package/package.json +1 -1
- package/public/assets/{index-BHtAJlui.js → index-CUHACAGL.js} +13 -13
- package/public/assets/index-CUHACAGL.js.map +1 -0
- package/public/assets/{shiki-u3mKzSh6.js → shiki-B8vfRZ8s.js} +2 -2
- package/public/assets/{shiki-u3mKzSh6.js.map → shiki-B8vfRZ8s.js.map} +1 -1
- package/public/index.html +1 -1
- package/public/assets/index-BHtAJlui.js.map +0 -1
package/dist/server/api.js
CHANGED
|
@@ -55,6 +55,7 @@ import { bus } from "../bus.js";
|
|
|
55
55
|
import { readEvents, readEventsTail, filterByBranch } from "../log/events.js";
|
|
56
56
|
import { mcp } from "../agent/mcp-registry.js";
|
|
57
57
|
import { connectMcp } from "../agent/mcp.js";
|
|
58
|
+
import { oauth } from "../agent/mcp-oauth-manager.js";
|
|
58
59
|
/** media categories the file tree can preview inline */
|
|
59
60
|
const IMAGE_EXT = new Set(["png", "jpg", "jpeg", "gif", "webp", "svg", "bmp", "ico", "avif"]);
|
|
60
61
|
const VIDEO_EXT = new Set(["mp4", "webm", "mov", "mkv", "avi", "m4v"]);
|
|
@@ -876,6 +877,88 @@ export function buildApp(master) {
|
|
|
876
877
|
warnings: p.warnings,
|
|
877
878
|
})),
|
|
878
879
|
}));
|
|
880
|
+
/**
|
|
881
|
+
* Start an OAuth flow for one server.
|
|
882
|
+
*
|
|
883
|
+
* Responds with the URL to open IMMEDIATELY; the exchange finishes when the browser
|
|
884
|
+
* comes back to the loopback listener. That split is what lets the panel show a
|
|
885
|
+
* clickable link instead of hanging the request for minutes.
|
|
886
|
+
*/
|
|
887
|
+
app.post("/api/mcp/oauth/start", async (c) => {
|
|
888
|
+
const body = await c.req
|
|
889
|
+
.json()
|
|
890
|
+
.catch(() => null);
|
|
891
|
+
if (!body?.name)
|
|
892
|
+
return c.json({ error: "missing name" }, 400);
|
|
893
|
+
const saved = (master.config.mcpServers ?? []).find((m) => m.name === body.name);
|
|
894
|
+
const url = body.url ?? saved?.url;
|
|
895
|
+
if (!url)
|
|
896
|
+
return c.json({ error: "this server has no url — OAuth needs an http(s) endpoint" }, 400);
|
|
897
|
+
// Kick the flow off; it settles when the redirect arrives. The promise is NOT
|
|
898
|
+
// awaited here — awaiting it would hold this request open until the operator
|
|
899
|
+
// finishes in the browser.
|
|
900
|
+
const flow = oauth.authorize(body.name, url, {
|
|
901
|
+
...(body.scopes?.length ? { scopes: body.scopes } : {}),
|
|
902
|
+
...(body.clientId ? { clientId: body.clientId } : {}),
|
|
903
|
+
...(body.clientSecret ? { clientSecret: body.clientSecret } : {}),
|
|
904
|
+
});
|
|
905
|
+
flow.catch(() => {
|
|
906
|
+
/* recorded in oauth.status(...).flow; nobody is listening here */
|
|
907
|
+
});
|
|
908
|
+
// Wait only long enough for the flow to produce its URL (discovery + registration
|
|
909
|
+
// are network round-trips, but short ones).
|
|
910
|
+
const deadline = Date.now() + 20_000;
|
|
911
|
+
let url_;
|
|
912
|
+
while (Date.now() < deadline) {
|
|
913
|
+
const st = oauth.status(body.name);
|
|
914
|
+
if (st.flow.phase === "authorizing") {
|
|
915
|
+
url_ = st.flow.url;
|
|
916
|
+
break;
|
|
917
|
+
}
|
|
918
|
+
if (st.flow.phase === "error")
|
|
919
|
+
break;
|
|
920
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
921
|
+
}
|
|
922
|
+
const st = oauth.status(body.name);
|
|
923
|
+
if (!url_)
|
|
924
|
+
return c.json({
|
|
925
|
+
ok: false,
|
|
926
|
+
error: st.flow.phase === "error"
|
|
927
|
+
? st.flow.message
|
|
928
|
+
: "the authorization server did not produce a URL in time",
|
|
929
|
+
}, 200);
|
|
930
|
+
return c.json({ ok: true, url: url_, redirectUri: "http://127.0.0.1/<port>/callback" });
|
|
931
|
+
});
|
|
932
|
+
app.get("/api/mcp/oauth/status", async (c) => {
|
|
933
|
+
const name = c.req.query("name");
|
|
934
|
+
if (!name)
|
|
935
|
+
return c.json({ error: "missing name" }, 400);
|
|
936
|
+
const detect = c.req.query("detect") === "1";
|
|
937
|
+
// `detect=1` probes the endpoint for a Bearer challenge. That is the ONLY way the
|
|
938
|
+
// panel can learn "this needs a grant" before the operator has guessed it, and it
|
|
939
|
+
// is opt-in because the probe is a real request to the server.
|
|
940
|
+
if (detect && !oauth.status(name).required) {
|
|
941
|
+
const saved = (master.config.mcpServers ?? []).find((m) => m.name === name);
|
|
942
|
+
if (saved?.url) {
|
|
943
|
+
try {
|
|
944
|
+
await oauth.detect(name, saved.url, {
|
|
945
|
+
...(saved.headers ? { headers: saved.headers } : {}),
|
|
946
|
+
});
|
|
947
|
+
}
|
|
948
|
+
catch {
|
|
949
|
+
/* best-effort: the status is still returned */
|
|
950
|
+
}
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
return c.json(oauth.status(name));
|
|
954
|
+
});
|
|
955
|
+
app.post("/api/mcp/oauth/disconnect", async (c) => {
|
|
956
|
+
const body = await c.req.json().catch(() => null);
|
|
957
|
+
if (!body?.name)
|
|
958
|
+
return c.json({ error: "missing name" }, 400);
|
|
959
|
+
await oauth.disconnect(body.name);
|
|
960
|
+
return c.json({ ok: true });
|
|
961
|
+
});
|
|
879
962
|
app.post("/api/mcp/test", async (c) => {
|
|
880
963
|
const body = await c.req.json().catch(() => null);
|
|
881
964
|
if (!body?.name)
|