rird 1.0.200
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/AGENTS.md +27 -0
- package/Dockerfile +18 -0
- package/README.md +15 -0
- package/bin/opencode +336 -0
- package/bin/pty-wrapper.js +285 -0
- package/bunfig.toml +4 -0
- package/facebook_ads_library.png +0 -0
- package/nul`nif +0 -0
- package/package.json +111 -0
- package/parsers-config.ts +239 -0
- package/rird-1.0.199.tgz +0 -0
- package/script/build-windows.ts +54 -0
- package/script/build.ts +167 -0
- package/script/postinstall.mjs +544 -0
- package/script/publish-registries.ts +187 -0
- package/script/publish.ts +72 -0
- package/script/schema.ts +47 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +1063 -0
- package/src/acp/session.ts +101 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +367 -0
- package/src/agent/generate.txt +75 -0
- package/src/agent/prompt/compaction.txt +12 -0
- package/src/agent/prompt/explore.txt +18 -0
- package/src/agent/prompt/summary.txt +10 -0
- package/src/agent/prompt/title.txt +36 -0
- package/src/auth/index.ts +70 -0
- package/src/bun/index.ts +114 -0
- package/src/bus/bus-event.ts +43 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +105 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/acp.ts +88 -0
- package/src/cli/cmd/agent.ts +256 -0
- package/src/cli/cmd/auth.ts +391 -0
- package/src/cli/cmd/cmd.ts +7 -0
- package/src/cli/cmd/debug/config.ts +15 -0
- package/src/cli/cmd/debug/file.ts +91 -0
- package/src/cli/cmd/debug/index.ts +43 -0
- package/src/cli/cmd/debug/lsp.ts +48 -0
- package/src/cli/cmd/debug/ripgrep.ts +83 -0
- package/src/cli/cmd/debug/scrap.ts +15 -0
- package/src/cli/cmd/debug/skill.ts +15 -0
- package/src/cli/cmd/debug/snapshot.ts +48 -0
- package/src/cli/cmd/export.ts +88 -0
- package/src/cli/cmd/generate.ts +38 -0
- package/src/cli/cmd/github.ts +1400 -0
- package/src/cli/cmd/import.ts +98 -0
- package/src/cli/cmd/mcp.ts +654 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +368 -0
- package/src/cli/cmd/serve.ts +31 -0
- package/src/cli/cmd/session.ts +106 -0
- package/src/cli/cmd/stats.ts +298 -0
- package/src/cli/cmd/tui/app.tsx +696 -0
- package/src/cli/cmd/tui/attach.ts +30 -0
- package/src/cli/cmd/tui/component/border.tsx +21 -0
- package/src/cli/cmd/tui/component/dialog-agent.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-command.tsx +124 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +245 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +224 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +102 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-stash.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +162 -0
- package/src/cli/cmd/tui/component/dialog-tag.tsx +44 -0
- package/src/cli/cmd/tui/component/dialog-theme-list.tsx +50 -0
- package/src/cli/cmd/tui/component/did-you-know.tsx +85 -0
- package/src/cli/cmd/tui/component/logo.tsx +35 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +574 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +108 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +1090 -0
- package/src/cli/cmd/tui/component/prompt/stash.tsx +101 -0
- package/src/cli/cmd/tui/component/tips.ts +27 -0
- package/src/cli/cmd/tui/component/todo-item.tsx +32 -0
- package/src/cli/cmd/tui/context/args.tsx +14 -0
- package/src/cli/cmd/tui/context/directory.ts +13 -0
- package/src/cli/cmd/tui/context/exit.tsx +23 -0
- package/src/cli/cmd/tui/context/helper.tsx +25 -0
- package/src/cli/cmd/tui/context/keybind.tsx +101 -0
- package/src/cli/cmd/tui/context/kv.tsx +49 -0
- package/src/cli/cmd/tui/context/local.tsx +354 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +46 -0
- package/src/cli/cmd/tui/context/sdk.tsx +74 -0
- package/src/cli/cmd/tui/context/sync.tsx +372 -0
- package/src/cli/cmd/tui/context/theme/aura.json +69 -0
- package/src/cli/cmd/tui/context/theme/ayu.json +80 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-frappe.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin-macchiato.json +233 -0
- package/src/cli/cmd/tui/context/theme/catppuccin.json +112 -0
- package/src/cli/cmd/tui/context/theme/cobalt2.json +228 -0
- package/src/cli/cmd/tui/context/theme/cursor.json +249 -0
- package/src/cli/cmd/tui/context/theme/dracula.json +219 -0
- package/src/cli/cmd/tui/context/theme/everforest.json +241 -0
- package/src/cli/cmd/tui/context/theme/flexoki.json +237 -0
- package/src/cli/cmd/tui/context/theme/github.json +233 -0
- package/src/cli/cmd/tui/context/theme/gruvbox.json +95 -0
- package/src/cli/cmd/tui/context/theme/kanagawa.json +77 -0
- package/src/cli/cmd/tui/context/theme/lucent-orng.json +227 -0
- package/src/cli/cmd/tui/context/theme/material.json +235 -0
- package/src/cli/cmd/tui/context/theme/matrix.json +77 -0
- package/src/cli/cmd/tui/context/theme/mercury.json +252 -0
- package/src/cli/cmd/tui/context/theme/monokai.json +221 -0
- package/src/cli/cmd/tui/context/theme/nightowl.json +221 -0
- package/src/cli/cmd/tui/context/theme/nord.json +223 -0
- package/src/cli/cmd/tui/context/theme/one-dark.json +84 -0
- package/src/cli/cmd/tui/context/theme/orng.json +245 -0
- package/src/cli/cmd/tui/context/theme/palenight.json +222 -0
- package/src/cli/cmd/tui/context/theme/rird.json +245 -0
- package/src/cli/cmd/tui/context/theme/rosepine.json +234 -0
- package/src/cli/cmd/tui/context/theme/solarized.json +223 -0
- package/src/cli/cmd/tui/context/theme/synthwave84.json +226 -0
- package/src/cli/cmd/tui/context/theme/tokyonight.json +243 -0
- package/src/cli/cmd/tui/context/theme/vercel.json +245 -0
- package/src/cli/cmd/tui/context/theme/vesper.json +218 -0
- package/src/cli/cmd/tui/context/theme/zenburn.json +223 -0
- package/src/cli/cmd/tui/context/theme.tsx +1109 -0
- package/src/cli/cmd/tui/event.ts +40 -0
- package/src/cli/cmd/tui/routes/home.tsx +138 -0
- package/src/cli/cmd/tui/routes/session/dialog-fork-from-timeline.tsx +64 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +109 -0
- package/src/cli/cmd/tui/routes/session/dialog-subagent.tsx +26 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +47 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +88 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +125 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +1864 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +318 -0
- package/src/cli/cmd/tui/spawn.ts +60 -0
- package/src/cli/cmd/tui/thread.ts +142 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +57 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +83 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +38 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +77 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +332 -0
- package/src/cli/cmd/tui/ui/dialog.tsx +170 -0
- package/src/cli/cmd/tui/ui/spinner.ts +368 -0
- package/src/cli/cmd/tui/ui/toast.tsx +100 -0
- package/src/cli/cmd/tui/util/clipboard.ts +127 -0
- package/src/cli/cmd/tui/util/editor.ts +32 -0
- package/src/cli/cmd/tui/util/terminal.ts +114 -0
- package/src/cli/cmd/tui/worker.ts +63 -0
- package/src/cli/cmd/uninstall.ts +344 -0
- package/src/cli/cmd/upgrade.ts +100 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/error.ts +56 -0
- package/src/cli/ui.ts +84 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +80 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +97 -0
- package/src/config/config.ts +995 -0
- package/src/config/markdown.ts +41 -0
- package/src/env/index.ts +26 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +328 -0
- package/src/file/ripgrep.ts +393 -0
- package/src/file/time.ts +64 -0
- package/src/file/watcher.ts +103 -0
- package/src/flag/flag.ts +46 -0
- package/src/format/formatter.ts +315 -0
- package/src/format/index.ts +137 -0
- package/src/global/index.ts +52 -0
- package/src/id/id.ts +73 -0
- package/src/ide/index.ts +76 -0
- package/src/index.ts +240 -0
- package/src/installation/index.ts +239 -0
- package/src/lsp/client.ts +229 -0
- package/src/lsp/index.ts +485 -0
- package/src/lsp/language.ts +116 -0
- package/src/lsp/server.ts +1895 -0
- package/src/mcp/auth.ts +135 -0
- package/src/mcp/index.ts +690 -0
- package/src/mcp/oauth-callback.ts +200 -0
- package/src/mcp/oauth-provider.ts +154 -0
- package/src/patch/index.ts +622 -0
- package/src/permission/index.ts +199 -0
- package/src/plugin/index.ts +91 -0
- package/src/project/bootstrap.ts +31 -0
- package/src/project/instance.ts +78 -0
- package/src/project/project.ts +221 -0
- package/src/project/state.ts +65 -0
- package/src/project/vcs.ts +76 -0
- package/src/provider/auth.ts +143 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +106 -0
- package/src/provider/provider.ts +1071 -0
- package/src/provider/sdk/openai-compatible/src/README.md +5 -0
- package/src/provider/sdk/openai-compatible/src/index.ts +2 -0
- package/src/provider/sdk/openai-compatible/src/openai-compatible-provider.ts +100 -0
- package/src/provider/sdk/openai-compatible/src/responses/convert-to-openai-responses-input.ts +303 -0
- package/src/provider/sdk/openai-compatible/src/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-config.ts +18 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-error.ts +22 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-api-types.ts +207 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-language-model.ts +1713 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-prepare-tools.ts +177 -0
- package/src/provider/sdk/openai-compatible/src/responses/openai-responses-settings.ts +1 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/code-interpreter.ts +88 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/file-search.ts +128 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/image-generation.ts +115 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/local-shell.ts +65 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search-preview.ts +104 -0
- package/src/provider/sdk/openai-compatible/src/responses/tool/web-search.ts +103 -0
- package/src/provider/transform.ts +455 -0
- package/src/pty/index.ts +231 -0
- package/src/security/guardrails.test.ts +341 -0
- package/src/security/guardrails.ts +558 -0
- package/src/security/index.ts +19 -0
- package/src/server/error.ts +36 -0
- package/src/server/project.ts +79 -0
- package/src/server/server.ts +2642 -0
- package/src/server/tui.ts +71 -0
- package/src/session/compaction.ts +223 -0
- package/src/session/index.ts +461 -0
- package/src/session/llm.ts +201 -0
- package/src/session/message-v2.ts +690 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +409 -0
- package/src/session/prompt/act-switch.txt +5 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +85 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +103 -0
- package/src/session/prompt/codex.txt +304 -0
- package/src/session/prompt/copilot-gpt-5.txt +138 -0
- package/src/session/prompt/gemini.txt +85 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +35 -0
- package/src/session/prompt/plan.txt +24 -0
- package/src/session/prompt/polaris.txt +84 -0
- package/src/session/prompt/qwen.txt +106 -0
- package/src/session/prompt.ts +1509 -0
- package/src/session/retry.ts +86 -0
- package/src/session/revert.ts +108 -0
- package/src/session/sensitive-filter.test.ts +327 -0
- package/src/session/sensitive-filter.ts +466 -0
- package/src/session/status.ts +76 -0
- package/src/session/summary.ts +194 -0
- package/src/session/system.ts +120 -0
- package/src/session/todo.ts +37 -0
- package/src/share/share-next.ts +194 -0
- package/src/share/share.ts +87 -0
- package/src/shell/shell.ts +67 -0
- package/src/skill/index.ts +1 -0
- package/src/skill/skill.ts +83 -0
- package/src/snapshot/index.ts +197 -0
- package/src/storage/storage.ts +226 -0
- package/src/tests/agent.test.ts +308 -0
- package/src/tests/build-guards.test.ts +267 -0
- package/src/tests/config.test.ts +664 -0
- package/src/tests/tool-registry.test.ts +589 -0
- package/src/tool/bash.ts +317 -0
- package/src/tool/bash.txt +158 -0
- package/src/tool/batch.ts +175 -0
- package/src/tool/batch.txt +24 -0
- package/src/tool/codesearch.ts +168 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +675 -0
- package/src/tool/edit.txt +10 -0
- package/src/tool/glob.ts +65 -0
- package/src/tool/glob.txt +6 -0
- package/src/tool/grep.ts +121 -0
- package/src/tool/grep.txt +8 -0
- package/src/tool/invalid.ts +17 -0
- package/src/tool/ls.ts +110 -0
- package/src/tool/ls.txt +1 -0
- package/src/tool/lsp-diagnostics.ts +26 -0
- package/src/tool/lsp-diagnostics.txt +1 -0
- package/src/tool/lsp-hover.ts +31 -0
- package/src/tool/lsp-hover.txt +1 -0
- package/src/tool/lsp.ts +87 -0
- package/src/tool/lsp.txt +19 -0
- package/src/tool/multiedit.ts +46 -0
- package/src/tool/multiedit.txt +41 -0
- package/src/tool/patch.ts +233 -0
- package/src/tool/patch.txt +1 -0
- package/src/tool/read.ts +219 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +162 -0
- package/src/tool/skill.ts +100 -0
- package/src/tool/task.ts +136 -0
- package/src/tool/task.txt +51 -0
- package/src/tool/todo.ts +39 -0
- package/src/tool/todoread.txt +14 -0
- package/src/tool/todowrite.txt +167 -0
- package/src/tool/tool.ts +71 -0
- package/src/tool/webfetch.ts +198 -0
- package/src/tool/webfetch.txt +13 -0
- package/src/tool/websearch.ts +180 -0
- package/src/tool/websearch.txt +11 -0
- package/src/tool/write.ts +110 -0
- package/src/tool/write.txt +8 -0
- package/src/util/archive.ts +16 -0
- package/src/util/color.ts +19 -0
- package/src/util/context.ts +25 -0
- package/src/util/defer.ts +12 -0
- package/src/util/eventloop.ts +20 -0
- package/src/util/filesystem.ts +83 -0
- package/src/util/fn.ts +11 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +102 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/license.ts +325 -0
- package/src/util/locale.ts +81 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +180 -0
- package/src/util/queue.ts +32 -0
- package/src/util/rpc.ts +42 -0
- package/src/util/scrap.ts +10 -0
- package/src/util/signal.ts +12 -0
- package/src/util/timeout.ts +14 -0
- package/src/util/token.ts +7 -0
- package/src/util/wildcard.ts +54 -0
- package/sst-env.d.ts +9 -0
- package/test/agent/agent.test.ts +146 -0
- package/test/bun.test.ts +53 -0
- package/test/cli/github-remote.test.ts +80 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +535 -0
- package/test/config/markdown.test.ts +89 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/fixture/fixture.ts +36 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/keybind.test.ts +421 -0
- package/test/lsp/client.test.ts +95 -0
- package/test/mcp/headers.test.ts +153 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/preload.ts +57 -0
- package/test/project/project.test.ts +72 -0
- package/test/provider/provider.test.ts +1809 -0
- package/test/provider/transform.test.ts +411 -0
- package/test/session/retry.test.ts +111 -0
- package/test/session/session.test.ts +71 -0
- package/test/skill/skill.test.ts +131 -0
- package/test/snapshot/snapshot.test.ts +939 -0
- package/test/tool/__snapshots__/tool.test.ts.snap +9 -0
- package/test/tool/bash.test.ts +434 -0
- package/test/tool/grep.test.ts +108 -0
- package/test/tool/patch.test.ts +259 -0
- package/test/tool/read.test.ts +42 -0
- package/test/util/iife.test.ts +36 -0
- package/test/util/lazy.test.ts +50 -0
- package/test/util/timeout.test.ts +21 -0
- package/test/util/wildcard.test.ts +55 -0
- 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: rird 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 rird.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., rird 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 rird.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 rird.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: "rird",
|
|
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: "rird-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: "rird-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
|
+
})
|