bincode-cli 1.0.1

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.
Files changed (300) hide show
  1. package/AGENTS.md +27 -0
  2. package/README.md +15 -0
  3. package/bin/bincode +98 -0
  4. package/bunfig.toml +4 -0
  5. package/package.json +124 -0
  6. package/parsers-config.ts +239 -0
  7. package/script/build.ts +167 -0
  8. package/script/postinstall.mjs +206 -0
  9. package/script/publish.ts +99 -0
  10. package/script/schema.ts +47 -0
  11. package/src/acp/README.md +164 -0
  12. package/src/acp/agent.ts +1051 -0
  13. package/src/acp/session.ts +101 -0
  14. package/src/acp/types.ts +22 -0
  15. package/src/agent/agent.ts +398 -0
  16. package/src/agent/generate.txt +75 -0
  17. package/src/agent/prompt/compaction.txt +12 -0
  18. package/src/agent/prompt/explore.txt +18 -0
  19. package/src/agent/prompt/summary.txt +10 -0
  20. package/src/agent/prompt/title.txt +36 -0
  21. package/src/auth/bineric-login.ts +506 -0
  22. package/src/auth/index.ts +70 -0
  23. package/src/bun/index.ts +114 -0
  24. package/src/bus/bus-event.ts +43 -0
  25. package/src/bus/global.ts +10 -0
  26. package/src/bus/index.ts +105 -0
  27. package/src/cli/auth-check.ts +61 -0
  28. package/src/cli/bootstrap.ts +21 -0
  29. package/src/cli/cmd/acp.ts +88 -0
  30. package/src/cli/cmd/agent.ts +256 -0
  31. package/src/cli/cmd/auth.ts +436 -0
  32. package/src/cli/cmd/cmd.ts +7 -0
  33. package/src/cli/cmd/debug/config.ts +15 -0
  34. package/src/cli/cmd/debug/file.ts +91 -0
  35. package/src/cli/cmd/debug/index.ts +43 -0
  36. package/src/cli/cmd/debug/lsp.ts +48 -0
  37. package/src/cli/cmd/debug/ripgrep.ts +83 -0
  38. package/src/cli/cmd/debug/scrap.ts +15 -0
  39. package/src/cli/cmd/debug/skill.ts +15 -0
  40. package/src/cli/cmd/debug/snapshot.ts +48 -0
  41. package/src/cli/cmd/export.ts +88 -0
  42. package/src/cli/cmd/generate.ts +38 -0
  43. package/src/cli/cmd/github.ts +1399 -0
  44. package/src/cli/cmd/import.ts +98 -0
  45. package/src/cli/cmd/login.ts +112 -0
  46. package/src/cli/cmd/logout.ts +38 -0
  47. package/src/cli/cmd/mcp.ts +654 -0
  48. package/src/cli/cmd/models.ts +77 -0
  49. package/src/cli/cmd/pr.ts +112 -0
  50. package/src/cli/cmd/run.ts +368 -0
  51. package/src/cli/cmd/serve.ts +31 -0
  52. package/src/cli/cmd/session.ts +106 -0
  53. package/src/cli/cmd/stats.ts +298 -0
  54. package/src/cli/cmd/tui/app.tsx +669 -0
  55. package/src/cli/cmd/tui/attach.ts +30 -0
  56. package/src/cli/cmd/tui/component/border.tsx +21 -0
  57. package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
  58. package/src/cli/cmd/tui/component/dialog-command.tsx +123 -0
  59. package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
  60. package/src/cli/cmd/tui/component/dialog-model.tsx +223 -0
  61. package/src/cli/cmd/tui/component/dialog-provider.tsx +224 -0
  62. package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
  63. package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
  64. package/src/cli/cmd/tui/component/dialog-status.tsx +162 -0
  65. package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
  66. package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
  67. package/src/cli/cmd/tui/component/logo.tsx +32 -0
  68. package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +560 -0
  69. package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
  70. package/src/cli/cmd/tui/component/prompt/index.tsx +1052 -0
  71. package/src/cli/cmd/tui/context/args.tsx +14 -0
  72. package/src/cli/cmd/tui/context/directory.ts +13 -0
  73. package/src/cli/cmd/tui/context/exit.tsx +23 -0
  74. package/src/cli/cmd/tui/context/helper.tsx +25 -0
  75. package/src/cli/cmd/tui/context/keybind.tsx +101 -0
  76. package/src/cli/cmd/tui/context/kv.tsx +49 -0
  77. package/src/cli/cmd/tui/context/local.tsx +339 -0
  78. package/src/cli/cmd/tui/context/prompt.tsx +18 -0
  79. package/src/cli/cmd/tui/context/route.tsx +46 -0
  80. package/src/cli/cmd/tui/context/sdk.tsx +74 -0
  81. package/src/cli/cmd/tui/context/sync.tsx +372 -0
  82. package/src/cli/cmd/tui/context/theme/aura.json +69 -0
  83. package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
  84. package/src/cli/cmd/tui/context/theme/bincode.json +245 -0
  85. package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
  86. package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
  87. package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
  88. package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
  89. package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
  90. package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
  91. package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
  92. package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
  93. package/src/cli/cmd/tui/context/theme/github.json +233 -0
  94. package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
  95. package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
  96. package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -0
  97. package/src/cli/cmd/tui/context/theme/material.json +235 -0
  98. package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
  99. package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
  100. package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
  101. package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
  102. package/src/cli/cmd/tui/context/theme/nord.json +223 -0
  103. package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
  104. package/src/cli/cmd/tui/context/theme/orng.json +245 -0
  105. package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
  106. package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
  107. package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
  108. package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
  109. package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
  110. package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
  111. package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
  112. package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
  113. package/src/cli/cmd/tui/context/theme.tsx +1109 -0
  114. package/src/cli/cmd/tui/event.ts +40 -0
  115. package/src/cli/cmd/tui/routes/home.tsx +105 -0
  116. package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
  117. package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
  118. package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
  119. package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
  120. package/src/cli/cmd/tui/routes/session/footer.tsx +88 -0
  121. package/src/cli/cmd/tui/routes/session/header.tsx +141 -0
  122. package/src/cli/cmd/tui/routes/session/index.tsx +1888 -0
  123. package/src/cli/cmd/tui/routes/session/sidebar.tsx +321 -0
  124. package/src/cli/cmd/tui/spawn.ts +60 -0
  125. package/src/cli/cmd/tui/thread.ts +120 -0
  126. package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
  127. package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
  128. package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
  129. package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
  130. package/src/cli/cmd/tui/ui/dialog-select.tsx +330 -0
  131. package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
  132. package/src/cli/cmd/tui/ui/spinner.ts +368 -0
  133. package/src/cli/cmd/tui/ui/toast.tsx +100 -0
  134. package/src/cli/cmd/tui/util/clipboard.ts +127 -0
  135. package/src/cli/cmd/tui/util/editor.ts +32 -0
  136. package/src/cli/cmd/tui/util/terminal.ts +114 -0
  137. package/src/cli/cmd/tui/worker.ts +63 -0
  138. package/src/cli/cmd/uninstall.ts +344 -0
  139. package/src/cli/cmd/upgrade.ts +67 -0
  140. package/src/cli/cmd/web.ts +84 -0
  141. package/src/cli/error.ts +55 -0
  142. package/src/cli/ui.ts +84 -0
  143. package/src/cli/upgrade.ts +25 -0
  144. package/src/command/index.ts +80 -0
  145. package/src/command/template/initialize.txt +10 -0
  146. package/src/command/template/review.txt +97 -0
  147. package/src/config/config.ts +995 -0
  148. package/src/config/markdown.ts +41 -0
  149. package/src/env/index.ts +26 -0
  150. package/src/file/ignore.ts +83 -0
  151. package/src/file/index.ts +328 -0
  152. package/src/file/ripgrep.ts +393 -0
  153. package/src/file/time.ts +64 -0
  154. package/src/file/watcher.ts +103 -0
  155. package/src/flag/flag.ts +46 -0
  156. package/src/format/formatter.ts +315 -0
  157. package/src/format/index.ts +137 -0
  158. package/src/global/index.ts +52 -0
  159. package/src/id/id.ts +73 -0
  160. package/src/ide/index.ts +76 -0
  161. package/src/index.ts +217 -0
  162. package/src/installation/index.ts +196 -0
  163. package/src/lsp/client.ts +229 -0
  164. package/src/lsp/index.ts +485 -0
  165. package/src/lsp/language.ts +116 -0
  166. package/src/lsp/server.ts +1895 -0
  167. package/src/mcp/auth.ts +135 -0
  168. package/src/mcp/index.ts +654 -0
  169. package/src/mcp/oauth-callback.ts +200 -0
  170. package/src/mcp/oauth-provider.ts +154 -0
  171. package/src/patch/index.ts +622 -0
  172. package/src/permission/index.ts +199 -0
  173. package/src/plugin/index.ts +101 -0
  174. package/src/project/bootstrap.ts +31 -0
  175. package/src/project/instance.ts +78 -0
  176. package/src/project/project.ts +221 -0
  177. package/src/project/state.ts +65 -0
  178. package/src/project/vcs.ts +76 -0
  179. package/src/provider/auth.ts +143 -0
  180. package/src/provider/models-macro.ts +11 -0
  181. package/src/provider/models.ts +106 -0
  182. package/src/provider/provider.ts +1071 -0
  183. package/src/provider/sdk/openai-compatible/src/README.md +5 -0
  184. package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
  185. package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +101 -0
  186. package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
  187. package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
  188. package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
  189. package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
  190. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
  191. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
  192. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
  193. package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
  194. package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
  195. package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
  196. package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
  197. package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
  198. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
  199. package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
  200. package/src/provider/transform.ts +455 -0
  201. package/src/pty/index.ts +231 -0
  202. package/src/server/error.ts +36 -0
  203. package/src/server/project.ts +79 -0
  204. package/src/server/server.ts +2642 -0
  205. package/src/server/tui.ts +71 -0
  206. package/src/session/compaction.ts +223 -0
  207. package/src/session/index.ts +458 -0
  208. package/src/session/llm.ts +201 -0
  209. package/src/session/message-v2.ts +659 -0
  210. package/src/session/message.ts +189 -0
  211. package/src/session/processor.ts +409 -0
  212. package/src/session/prompt/anthropic-20250930.txt +166 -0
  213. package/src/session/prompt/anthropic.txt +104 -0
  214. package/src/session/prompt/anthropic_spoof.txt +1 -0
  215. package/src/session/prompt/beast.txt +147 -0
  216. package/src/session/prompt/build-switch.txt +5 -0
  217. package/src/session/prompt/codex.txt +318 -0
  218. package/src/session/prompt/copilot-gpt-5.txt +143 -0
  219. package/src/session/prompt/gemini.txt +155 -0
  220. package/src/session/prompt/max-steps.txt +16 -0
  221. package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
  222. package/src/session/prompt/plan.txt +26 -0
  223. package/src/session/prompt/polaris.txt +106 -0
  224. package/src/session/prompt/qwen.txt +109 -0
  225. package/src/session/prompt.ts +1446 -0
  226. package/src/session/retry.ts +86 -0
  227. package/src/session/revert.ts +108 -0
  228. package/src/session/status.ts +76 -0
  229. package/src/session/summary.ts +194 -0
  230. package/src/session/system.ts +120 -0
  231. package/src/session/todo.ts +37 -0
  232. package/src/share/share-next.ts +194 -0
  233. package/src/share/share.ts +87 -0
  234. package/src/shell/shell.ts +67 -0
  235. package/src/skill/index.ts +1 -0
  236. package/src/skill/skill.ts +83 -0
  237. package/src/snapshot/index.ts +197 -0
  238. package/src/storage/storage.ts +226 -0
  239. package/src/tool/bash.ts +306 -0
  240. package/src/tool/bash.txt +158 -0
  241. package/src/tool/batch.ts +175 -0
  242. package/src/tool/batch.txt +24 -0
  243. package/src/tool/codesearch.ts +138 -0
  244. package/src/tool/codesearch.txt +12 -0
  245. package/src/tool/edit.ts +675 -0
  246. package/src/tool/edit.txt +10 -0
  247. package/src/tool/glob.ts +65 -0
  248. package/src/tool/glob.txt +6 -0
  249. package/src/tool/grep.ts +121 -0
  250. package/src/tool/grep.txt +8 -0
  251. package/src/tool/invalid.ts +17 -0
  252. package/src/tool/ls.ts +110 -0
  253. package/src/tool/ls.txt +1 -0
  254. package/src/tool/lsp-diagnostics.ts +26 -0
  255. package/src/tool/lsp-diagnostics.txt +1 -0
  256. package/src/tool/lsp-hover.ts +31 -0
  257. package/src/tool/lsp-hover.txt +1 -0
  258. package/src/tool/lsp.ts +87 -0
  259. package/src/tool/lsp.txt +19 -0
  260. package/src/tool/multiedit.ts +46 -0
  261. package/src/tool/multiedit.txt +41 -0
  262. package/src/tool/patch.ts +233 -0
  263. package/src/tool/patch.txt +1 -0
  264. package/src/tool/read.ts +219 -0
  265. package/src/tool/read.txt +12 -0
  266. package/src/tool/registry.ts +162 -0
  267. package/src/tool/skill.ts +100 -0
  268. package/src/tool/task.ts +136 -0
  269. package/src/tool/task.txt +60 -0
  270. package/src/tool/todo.ts +39 -0
  271. package/src/tool/todoread.txt +14 -0
  272. package/src/tool/todowrite.txt +167 -0
  273. package/src/tool/tool.ts +71 -0
  274. package/src/tool/webfetch.ts +187 -0
  275. package/src/tool/webfetch.txt +13 -0
  276. package/src/tool/websearch.ts +150 -0
  277. package/src/tool/websearch.txt +11 -0
  278. package/src/tool/write.ts +110 -0
  279. package/src/tool/write.txt +8 -0
  280. package/src/util/archive.ts +16 -0
  281. package/src/util/color.ts +19 -0
  282. package/src/util/context.ts +25 -0
  283. package/src/util/defer.ts +12 -0
  284. package/src/util/eventloop.ts +20 -0
  285. package/src/util/filesystem.ts +83 -0
  286. package/src/util/fn.ts +11 -0
  287. package/src/util/iife.ts +3 -0
  288. package/src/util/keybind.ts +102 -0
  289. package/src/util/lazy.ts +11 -0
  290. package/src/util/locale.ts +81 -0
  291. package/src/util/lock.ts +98 -0
  292. package/src/util/log.ts +180 -0
  293. package/src/util/queue.ts +32 -0
  294. package/src/util/rpc.ts +42 -0
  295. package/src/util/scrap.ts +10 -0
  296. package/src/util/signal.ts +12 -0
  297. package/src/util/timeout.ts +14 -0
  298. package/src/util/token.ts +7 -0
  299. package/src/util/wildcard.ts +54 -0
  300. package/tsconfig.json +16 -0
@@ -0,0 +1,654 @@
1
+ import { cmd } from "./cmd"
2
+ import { Client } from "@modelcontextprotocol/sdk/client/index.js"
3
+ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
4
+ import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
5
+ import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
6
+ import * as prompts from "@clack/prompts"
7
+ import { UI } from "../ui"
8
+ import { MCP } from "../../mcp"
9
+ import { McpAuth } from "../../mcp/auth"
10
+ import { McpOAuthProvider } from "../../mcp/oauth-provider"
11
+ import { Config } from "../../config/config"
12
+ import { Instance } from "../../project/instance"
13
+ import { Installation } from "../../installation"
14
+ import path from "path"
15
+ import { Global } from "../../global"
16
+
17
+ function getAuthStatusIcon(status: MCP.AuthStatus): string {
18
+ switch (status) {
19
+ case "authenticated":
20
+ return "✓"
21
+ case "expired":
22
+ return "⚠"
23
+ case "not_authenticated":
24
+ return "○"
25
+ }
26
+ }
27
+
28
+ function getAuthStatusText(status: MCP.AuthStatus): string {
29
+ switch (status) {
30
+ case "authenticated":
31
+ return "authenticated"
32
+ case "expired":
33
+ return "expired"
34
+ case "not_authenticated":
35
+ return "not authenticated"
36
+ }
37
+ }
38
+
39
+ export const McpCommand = cmd({
40
+ command: "mcp",
41
+ builder: (yargs) =>
42
+ yargs
43
+ .command(McpAddCommand)
44
+ .command(McpListCommand)
45
+ .command(McpAuthCommand)
46
+ .command(McpLogoutCommand)
47
+ .command(McpDebugCommand)
48
+ .demandCommand(),
49
+ async handler() {},
50
+ })
51
+
52
+ export const McpListCommand = cmd({
53
+ command: "list",
54
+ aliases: ["ls"],
55
+ describe: "list MCP servers and their status",
56
+ async handler() {
57
+ await Instance.provide({
58
+ directory: process.cwd(),
59
+ async fn() {
60
+ UI.empty()
61
+ prompts.intro("MCP Servers")
62
+
63
+ const config = await Config.get()
64
+ const mcpServers = config.mcp ?? {}
65
+ const statuses = await MCP.status()
66
+
67
+ if (Object.keys(mcpServers).length === 0) {
68
+ prompts.log.warn("No MCP servers configured")
69
+ prompts.outro("Add servers with: bincode mcp add")
70
+ return
71
+ }
72
+
73
+ for (const [name, serverConfig] of Object.entries(mcpServers)) {
74
+ const status = statuses[name]
75
+ const hasOAuth = serverConfig.type === "remote" && !!serverConfig.oauth
76
+ const hasStoredTokens = await MCP.hasStoredTokens(name)
77
+
78
+ let statusIcon: string
79
+ let statusText: string
80
+ let hint = ""
81
+
82
+ if (!status) {
83
+ statusIcon = "○"
84
+ statusText = "not initialized"
85
+ } else if (status.status === "connected") {
86
+ statusIcon = "✓"
87
+ statusText = "connected"
88
+ if (hasOAuth && hasStoredTokens) {
89
+ hint = " (OAuth)"
90
+ }
91
+ } else if (status.status === "disabled") {
92
+ statusIcon = "○"
93
+ statusText = "disabled"
94
+ } else if (status.status === "needs_auth") {
95
+ statusIcon = "⚠"
96
+ statusText = "needs authentication"
97
+ } else if (status.status === "needs_client_registration") {
98
+ statusIcon = "✗"
99
+ statusText = "needs client registration"
100
+ hint = "\n " + status.error
101
+ } else {
102
+ statusIcon = "✗"
103
+ statusText = "failed"
104
+ hint = "\n " + status.error
105
+ }
106
+
107
+ const typeHint = serverConfig.type === "remote" ? serverConfig.url : serverConfig.command.join(" ")
108
+ prompts.log.info(
109
+ `${statusIcon} ${name} ${UI.Style.TEXT_DIM}${statusText}${hint}\n ${UI.Style.TEXT_DIM}${typeHint}`,
110
+ )
111
+ }
112
+
113
+ prompts.outro(`${Object.keys(mcpServers).length} server(s)`)
114
+ },
115
+ })
116
+ },
117
+ })
118
+
119
+ export const McpAuthCommand = cmd({
120
+ command: "auth [name]",
121
+ describe: "authenticate with an OAuth-enabled MCP server",
122
+ builder: (yargs) =>
123
+ yargs
124
+ .positional("name", {
125
+ describe: "name of the MCP server",
126
+ type: "string",
127
+ })
128
+ .command(McpAuthListCommand),
129
+ async handler(args) {
130
+ await Instance.provide({
131
+ directory: process.cwd(),
132
+ async fn() {
133
+ UI.empty()
134
+ prompts.intro("MCP OAuth Authentication")
135
+
136
+ const config = await Config.get()
137
+ const mcpServers = config.mcp ?? {}
138
+
139
+ // Get OAuth-capable servers (remote servers with oauth not explicitly disabled)
140
+ const oauthServers = Object.entries(mcpServers).filter(
141
+ ([_, cfg]) => cfg.type === "remote" && cfg.oauth !== false,
142
+ )
143
+
144
+ if (oauthServers.length === 0) {
145
+ prompts.log.warn("No OAuth-capable MCP servers configured")
146
+ prompts.log.info("Remote MCP servers support OAuth by default. Add a remote server in bincode.json:")
147
+ prompts.log.info(`
148
+ "mcp": {
149
+ "my-server": {
150
+ "type": "remote",
151
+ "url": "https://example.com/mcp"
152
+ }
153
+ }`)
154
+ prompts.outro("Done")
155
+ return
156
+ }
157
+
158
+ let serverName = args.name
159
+ if (!serverName) {
160
+ // Build options with auth status
161
+ const options = await Promise.all(
162
+ oauthServers.map(async ([name, cfg]) => {
163
+ const authStatus = await MCP.getAuthStatus(name)
164
+ const icon = getAuthStatusIcon(authStatus)
165
+ const statusText = getAuthStatusText(authStatus)
166
+ const url = cfg.type === "remote" ? cfg.url : ""
167
+ return {
168
+ label: `${icon} ${name} (${statusText})`,
169
+ value: name,
170
+ hint: url,
171
+ }
172
+ }),
173
+ )
174
+
175
+ const selected = await prompts.select({
176
+ message: "Select MCP server to authenticate",
177
+ options,
178
+ })
179
+ if (prompts.isCancel(selected)) throw new UI.CancelledError()
180
+ serverName = selected
181
+ }
182
+
183
+ const serverConfig = mcpServers[serverName]
184
+ if (!serverConfig) {
185
+ prompts.log.error(`MCP server not found: ${serverName}`)
186
+ prompts.outro("Done")
187
+ return
188
+ }
189
+
190
+ if (serverConfig.type !== "remote" || serverConfig.oauth === false) {
191
+ prompts.log.error(`MCP server ${serverName} does not support OAuth (oauth is disabled)`)
192
+ prompts.outro("Done")
193
+ return
194
+ }
195
+
196
+ // Check if already authenticated
197
+ const authStatus = await MCP.getAuthStatus(serverName)
198
+ if (authStatus === "authenticated") {
199
+ const confirm = await prompts.confirm({
200
+ message: `${serverName} already has valid credentials. Re-authenticate?`,
201
+ })
202
+ if (prompts.isCancel(confirm) || !confirm) {
203
+ prompts.outro("Cancelled")
204
+ return
205
+ }
206
+ } else if (authStatus === "expired") {
207
+ prompts.log.warn(`${serverName} has expired credentials. Re-authenticating...`)
208
+ }
209
+
210
+ const spinner = prompts.spinner()
211
+ spinner.start("Starting OAuth flow...")
212
+
213
+ try {
214
+ const status = await MCP.authenticate(serverName)
215
+
216
+ if (status.status === "connected") {
217
+ spinner.stop("Authentication successful!")
218
+ } else if (status.status === "needs_client_registration") {
219
+ spinner.stop("Authentication failed", 1)
220
+ prompts.log.error(status.error)
221
+ prompts.log.info("Add clientId to your MCP server config:")
222
+ prompts.log.info(`
223
+ "mcp": {
224
+ "${serverName}": {
225
+ "type": "remote",
226
+ "url": "${serverConfig.url}",
227
+ "oauth": {
228
+ "clientId": "your-client-id",
229
+ "clientSecret": "your-client-secret"
230
+ }
231
+ }
232
+ }`)
233
+ } else if (status.status === "failed") {
234
+ spinner.stop("Authentication failed", 1)
235
+ prompts.log.error(status.error)
236
+ } else {
237
+ spinner.stop("Unexpected status: " + status.status, 1)
238
+ }
239
+ } catch (error) {
240
+ spinner.stop("Authentication failed", 1)
241
+ prompts.log.error(error instanceof Error ? error.message : String(error))
242
+ }
243
+
244
+ prompts.outro("Done")
245
+ },
246
+ })
247
+ },
248
+ })
249
+
250
+ export const McpAuthListCommand = cmd({
251
+ command: "list",
252
+ aliases: ["ls"],
253
+ describe: "list OAuth-capable MCP servers and their auth status",
254
+ async handler() {
255
+ await Instance.provide({
256
+ directory: process.cwd(),
257
+ async fn() {
258
+ UI.empty()
259
+ prompts.intro("MCP OAuth Status")
260
+
261
+ const config = await Config.get()
262
+ const mcpServers = config.mcp ?? {}
263
+
264
+ // Get OAuth-capable servers
265
+ const oauthServers = Object.entries(mcpServers).filter(
266
+ ([_, cfg]) => cfg.type === "remote" && cfg.oauth !== false,
267
+ )
268
+
269
+ if (oauthServers.length === 0) {
270
+ prompts.log.warn("No OAuth-capable MCP servers configured")
271
+ prompts.outro("Done")
272
+ return
273
+ }
274
+
275
+ for (const [name, serverConfig] of oauthServers) {
276
+ const authStatus = await MCP.getAuthStatus(name)
277
+ const icon = getAuthStatusIcon(authStatus)
278
+ const statusText = getAuthStatusText(authStatus)
279
+ const url = serverConfig.type === "remote" ? serverConfig.url : ""
280
+
281
+ prompts.log.info(`${icon} ${name} ${UI.Style.TEXT_DIM}${statusText}\n ${UI.Style.TEXT_DIM}${url}`)
282
+ }
283
+
284
+ prompts.outro(`${oauthServers.length} OAuth-capable server(s)`)
285
+ },
286
+ })
287
+ },
288
+ })
289
+
290
+ export const McpLogoutCommand = cmd({
291
+ command: "logout [name]",
292
+ describe: "remove OAuth credentials for an MCP server",
293
+ builder: (yargs) =>
294
+ yargs.positional("name", {
295
+ describe: "name of the MCP server",
296
+ type: "string",
297
+ }),
298
+ async handler(args) {
299
+ await Instance.provide({
300
+ directory: process.cwd(),
301
+ async fn() {
302
+ UI.empty()
303
+ prompts.intro("MCP OAuth Logout")
304
+
305
+ const authPath = path.join(Global.Path.data, "mcp-auth.json")
306
+ const credentials = await McpAuth.all()
307
+ const serverNames = Object.keys(credentials)
308
+
309
+ if (serverNames.length === 0) {
310
+ prompts.log.warn("No MCP OAuth credentials stored")
311
+ prompts.outro("Done")
312
+ return
313
+ }
314
+
315
+ let serverName = args.name
316
+ if (!serverName) {
317
+ const selected = await prompts.select({
318
+ message: "Select MCP server to logout",
319
+ options: serverNames.map((name) => {
320
+ const entry = credentials[name]
321
+ const hasTokens = !!entry.tokens
322
+ const hasClient = !!entry.clientInfo
323
+ let hint = ""
324
+ if (hasTokens && hasClient) hint = "tokens + client"
325
+ else if (hasTokens) hint = "tokens"
326
+ else if (hasClient) hint = "client registration"
327
+ return {
328
+ label: name,
329
+ value: name,
330
+ hint,
331
+ }
332
+ }),
333
+ })
334
+ if (prompts.isCancel(selected)) throw new UI.CancelledError()
335
+ serverName = selected
336
+ }
337
+
338
+ if (!credentials[serverName]) {
339
+ prompts.log.error(`No credentials found for: ${serverName}`)
340
+ prompts.outro("Done")
341
+ return
342
+ }
343
+
344
+ await MCP.removeAuth(serverName)
345
+ prompts.log.success(`Removed OAuth credentials for ${serverName}`)
346
+ prompts.outro("Done")
347
+ },
348
+ })
349
+ },
350
+ })
351
+
352
+ export const McpAddCommand = cmd({
353
+ command: "add",
354
+ describe: "add an MCP server",
355
+ async handler() {
356
+ UI.empty()
357
+ prompts.intro("Add MCP server")
358
+
359
+ const name = await prompts.text({
360
+ message: "Enter MCP server name",
361
+ validate: (x) => (x && x.length > 0 ? undefined : "Required"),
362
+ })
363
+ if (prompts.isCancel(name)) throw new UI.CancelledError()
364
+
365
+ const type = await prompts.select({
366
+ message: "Select MCP server type",
367
+ options: [
368
+ {
369
+ label: "Local",
370
+ value: "local",
371
+ hint: "Run a local command",
372
+ },
373
+ {
374
+ label: "Remote",
375
+ value: "remote",
376
+ hint: "Connect to a remote URL",
377
+ },
378
+ ],
379
+ })
380
+ if (prompts.isCancel(type)) throw new UI.CancelledError()
381
+
382
+ if (type === "local") {
383
+ const command = await prompts.text({
384
+ message: "Enter command to run",
385
+ placeholder: "e.g., bincode x @modelcontextprotocol/server-filesystem",
386
+ validate: (x) => (x && x.length > 0 ? undefined : "Required"),
387
+ })
388
+ if (prompts.isCancel(command)) throw new UI.CancelledError()
389
+
390
+ prompts.log.info(`Local MCP server "${name}" configured with command: ${command}`)
391
+ prompts.outro("MCP server added successfully")
392
+ return
393
+ }
394
+
395
+ if (type === "remote") {
396
+ const url = await prompts.text({
397
+ message: "Enter MCP server URL",
398
+ placeholder: "e.g., https://example.com/mcp",
399
+ validate: (x) => {
400
+ if (!x) return "Required"
401
+ if (x.length === 0) return "Required"
402
+ const isValid = URL.canParse(x)
403
+ return isValid ? undefined : "Invalid URL"
404
+ },
405
+ })
406
+ if (prompts.isCancel(url)) throw new UI.CancelledError()
407
+
408
+ const useOAuth = await prompts.confirm({
409
+ message: "Does this server require OAuth authentication?",
410
+ initialValue: false,
411
+ })
412
+ if (prompts.isCancel(useOAuth)) throw new UI.CancelledError()
413
+
414
+ if (useOAuth) {
415
+ const hasClientId = await prompts.confirm({
416
+ message: "Do you have a pre-registered client ID?",
417
+ initialValue: false,
418
+ })
419
+ if (prompts.isCancel(hasClientId)) throw new UI.CancelledError()
420
+
421
+ if (hasClientId) {
422
+ const clientId = await prompts.text({
423
+ message: "Enter client ID",
424
+ validate: (x) => (x && x.length > 0 ? undefined : "Required"),
425
+ })
426
+ if (prompts.isCancel(clientId)) throw new UI.CancelledError()
427
+
428
+ const hasSecret = await prompts.confirm({
429
+ message: "Do you have a client secret?",
430
+ initialValue: false,
431
+ })
432
+ if (prompts.isCancel(hasSecret)) throw new UI.CancelledError()
433
+
434
+ let clientSecret: string | undefined
435
+ if (hasSecret) {
436
+ const secret = await prompts.password({
437
+ message: "Enter client secret",
438
+ })
439
+ if (prompts.isCancel(secret)) throw new UI.CancelledError()
440
+ clientSecret = secret
441
+ }
442
+
443
+ prompts.log.info(`Remote MCP server "${name}" configured with OAuth (client ID: ${clientId})`)
444
+ prompts.log.info("Add this to your bincode.json:")
445
+ prompts.log.info(`
446
+ "mcp": {
447
+ "${name}": {
448
+ "type": "remote",
449
+ "url": "${url}",
450
+ "oauth": {
451
+ "clientId": "${clientId}"${clientSecret ? `,\n "clientSecret": "${clientSecret}"` : ""}
452
+ }
453
+ }
454
+ }`)
455
+ } else {
456
+ prompts.log.info(`Remote MCP server "${name}" configured with OAuth (dynamic registration)`)
457
+ prompts.log.info("Add this to your bincode.json:")
458
+ prompts.log.info(`
459
+ "mcp": {
460
+ "${name}": {
461
+ "type": "remote",
462
+ "url": "${url}",
463
+ "oauth": {}
464
+ }
465
+ }`)
466
+ }
467
+ } else {
468
+ const client = new Client({
469
+ name: "bincode",
470
+ version: "1.0.0",
471
+ })
472
+ const transport = new StreamableHTTPClientTransport(new URL(url))
473
+ await client.connect(transport)
474
+ prompts.log.info(`Remote MCP server "${name}" configured with URL: ${url}`)
475
+ }
476
+ }
477
+
478
+ prompts.outro("MCP server added successfully")
479
+ },
480
+ })
481
+
482
+ export const McpDebugCommand = cmd({
483
+ command: "debug <name>",
484
+ describe: "debug OAuth connection for an MCP server",
485
+ builder: (yargs) =>
486
+ yargs.positional("name", {
487
+ describe: "name of the MCP server",
488
+ type: "string",
489
+ demandOption: true,
490
+ }),
491
+ async handler(args) {
492
+ await Instance.provide({
493
+ directory: process.cwd(),
494
+ async fn() {
495
+ UI.empty()
496
+ prompts.intro("MCP OAuth Debug")
497
+
498
+ const config = await Config.get()
499
+ const mcpServers = config.mcp ?? {}
500
+ const serverName = args.name
501
+
502
+ const serverConfig = mcpServers[serverName]
503
+ if (!serverConfig) {
504
+ prompts.log.error(`MCP server not found: ${serverName}`)
505
+ prompts.outro("Done")
506
+ return
507
+ }
508
+
509
+ if (serverConfig.type !== "remote") {
510
+ prompts.log.error(`MCP server ${serverName} is not a remote server`)
511
+ prompts.outro("Done")
512
+ return
513
+ }
514
+
515
+ if (serverConfig.oauth === false) {
516
+ prompts.log.warn(`MCP server ${serverName} has OAuth explicitly disabled`)
517
+ prompts.outro("Done")
518
+ return
519
+ }
520
+
521
+ prompts.log.info(`Server: ${serverName}`)
522
+ prompts.log.info(`URL: ${serverConfig.url}`)
523
+
524
+ // Check stored auth status
525
+ const authStatus = await MCP.getAuthStatus(serverName)
526
+ prompts.log.info(`Auth status: ${getAuthStatusIcon(authStatus)} ${getAuthStatusText(authStatus)}`)
527
+
528
+ const entry = await McpAuth.get(serverName)
529
+ if (entry?.tokens) {
530
+ prompts.log.info(` Access token: ${entry.tokens.accessToken.substring(0, 20)}...`)
531
+ if (entry.tokens.expiresAt) {
532
+ const expiresDate = new Date(entry.tokens.expiresAt * 1000)
533
+ const isExpired = entry.tokens.expiresAt < Date.now() / 1000
534
+ prompts.log.info(` Expires: ${expiresDate.toISOString()} ${isExpired ? "(EXPIRED)" : ""}`)
535
+ }
536
+ if (entry.tokens.refreshToken) {
537
+ prompts.log.info(` Refresh token: present`)
538
+ }
539
+ }
540
+ if (entry?.clientInfo) {
541
+ prompts.log.info(` Client ID: ${entry.clientInfo.clientId}`)
542
+ if (entry.clientInfo.clientSecretExpiresAt) {
543
+ const expiresDate = new Date(entry.clientInfo.clientSecretExpiresAt * 1000)
544
+ prompts.log.info(` Client secret expires: ${expiresDate.toISOString()}`)
545
+ }
546
+ }
547
+
548
+ const spinner = prompts.spinner()
549
+ spinner.start("Testing connection...")
550
+
551
+ // Test basic HTTP connectivity first
552
+ try {
553
+ const response = await fetch(serverConfig.url, {
554
+ method: "POST",
555
+ headers: {
556
+ "Content-Type": "application/json",
557
+ Accept: "application/json, text/event-stream",
558
+ },
559
+ body: JSON.stringify({
560
+ jsonrpc: "2.0",
561
+ method: "initialize",
562
+ params: {
563
+ protocolVersion: "2024-11-05",
564
+ capabilities: {},
565
+ clientInfo: { name: "bincode-debug", version: Installation.VERSION },
566
+ },
567
+ id: 1,
568
+ }),
569
+ })
570
+
571
+ spinner.stop(`HTTP response: ${response.status} ${response.statusText}`)
572
+
573
+ // Check for WWW-Authenticate header
574
+ const wwwAuth = response.headers.get("www-authenticate")
575
+ if (wwwAuth) {
576
+ prompts.log.info(`WWW-Authenticate: ${wwwAuth}`)
577
+ }
578
+
579
+ if (response.status === 401) {
580
+ prompts.log.warn("Server returned 401 Unauthorized")
581
+
582
+ // Try to discover OAuth metadata
583
+ const oauthConfig = typeof serverConfig.oauth === "object" ? serverConfig.oauth : undefined
584
+ const authProvider = new McpOAuthProvider(
585
+ serverName,
586
+ serverConfig.url,
587
+ {
588
+ clientId: oauthConfig?.clientId,
589
+ clientSecret: oauthConfig?.clientSecret,
590
+ scope: oauthConfig?.scope,
591
+ },
592
+ {
593
+ onRedirect: async () => {},
594
+ },
595
+ )
596
+
597
+ prompts.log.info("Testing OAuth flow (without completing authorization)...")
598
+
599
+ // Try creating transport with auth provider to trigger discovery
600
+ const transport = new StreamableHTTPClientTransport(new URL(serverConfig.url), {
601
+ authProvider,
602
+ })
603
+
604
+ try {
605
+ const client = new Client({
606
+ name: "bincode-debug",
607
+ version: Installation.VERSION,
608
+ })
609
+ await client.connect(transport)
610
+ prompts.log.success("Connection successful (already authenticated)")
611
+ await client.close()
612
+ } catch (error) {
613
+ if (error instanceof UnauthorizedError) {
614
+ prompts.log.info(`OAuth flow triggered: ${error.message}`)
615
+
616
+ // Check if dynamic registration would be attempted
617
+ const clientInfo = await authProvider.clientInformation()
618
+ if (clientInfo) {
619
+ prompts.log.info(`Client ID available: ${clientInfo.client_id}`)
620
+ } else {
621
+ prompts.log.info("No client ID - dynamic registration will be attempted")
622
+ }
623
+ } else {
624
+ prompts.log.error(`Connection error: ${error instanceof Error ? error.message : String(error)}`)
625
+ }
626
+ }
627
+ } else if (response.status >= 200 && response.status < 300) {
628
+ prompts.log.success("Server responded successfully (no auth required or already authenticated)")
629
+ const body = await response.text()
630
+ try {
631
+ const json = JSON.parse(body)
632
+ if (json.result?.serverInfo) {
633
+ prompts.log.info(`Server info: ${JSON.stringify(json.result.serverInfo)}`)
634
+ }
635
+ } catch {
636
+ // Not JSON, ignore
637
+ }
638
+ } else {
639
+ prompts.log.warn(`Unexpected status: ${response.status}`)
640
+ const body = await response.text().catch(() => "")
641
+ if (body) {
642
+ prompts.log.info(`Response body: ${body.substring(0, 500)}`)
643
+ }
644
+ }
645
+ } catch (error) {
646
+ spinner.stop("Connection failed", 1)
647
+ prompts.log.error(`Error: ${error instanceof Error ? error.message : String(error)}`)
648
+ }
649
+
650
+ prompts.outro("Debug complete")
651
+ },
652
+ })
653
+ },
654
+ })