cerebras-cli 1.0.0
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 +10 -0
- package/README.md +15 -0
- package/bin/opencode +84 -0
- package/bunfig.toml +4 -0
- package/package.json +128 -0
- package/parsers-config.ts +239 -0
- package/script/build.ts +151 -0
- package/script/postinstall.mjs +122 -0
- package/script/publish.ts +256 -0
- package/script/schema.ts +47 -0
- package/src/acp/README.md +164 -0
- package/src/acp/agent.ts +812 -0
- package/src/acp/session.ts +70 -0
- package/src/acp/types.ts +22 -0
- package/src/agent/agent.ts +310 -0
- package/src/agent/generate.txt +75 -0
- package/src/auth/index.ts +70 -0
- package/src/bun/index.ts +152 -0
- package/src/bus/global.ts +10 -0
- package/src/bus/index.ts +142 -0
- package/src/cli/bootstrap.ts +17 -0
- package/src/cli/cmd/acp.ts +88 -0
- package/src/cli/cmd/agent.ts +165 -0
- package/src/cli/cmd/auth.ts +369 -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 +41 -0
- package/src/cli/cmd/debug/lsp.ts +47 -0
- package/src/cli/cmd/debug/ripgrep.ts +83 -0
- package/src/cli/cmd/debug/scrap.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 +1200 -0
- package/src/cli/cmd/import.ts +98 -0
- package/src/cli/cmd/mcp.ts +400 -0
- package/src/cli/cmd/models.ts +77 -0
- package/src/cli/cmd/pr.ts +112 -0
- package/src/cli/cmd/run.ts +342 -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 +732 -0
- package/src/cli/cmd/tui/attach.ts +25 -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-feedback.tsx +160 -0
- package/src/cli/cmd/tui/component/dialog-mcp.tsx +86 -0
- package/src/cli/cmd/tui/component/dialog-model.tsx +223 -0
- package/src/cli/cmd/tui/component/dialog-notification.tsx +78 -0
- package/src/cli/cmd/tui/component/dialog-provider.tsx +222 -0
- package/src/cli/cmd/tui/component/dialog-session-list.tsx +97 -0
- package/src/cli/cmd/tui/component/dialog-session-rename.tsx +31 -0
- package/src/cli/cmd/tui/component/dialog-status.tsx +114 -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/logo.tsx +37 -0
- package/src/cli/cmd/tui/component/notification-banner.tsx +58 -0
- package/src/cli/cmd/tui/component/prompt/autocomplete.tsx +530 -0
- package/src/cli/cmd/tui/component/prompt/history.tsx +107 -0
- package/src/cli/cmd/tui/component/prompt/index.tsx +931 -0
- package/src/cli/cmd/tui/context/args.tsx +14 -0
- package/src/cli/cmd/tui/context/directory.ts +12 -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 +111 -0
- package/src/cli/cmd/tui/context/kv.tsx +49 -0
- package/src/cli/cmd/tui/context/local.tsx +339 -0
- package/src/cli/cmd/tui/context/prompt.tsx +18 -0
- package/src/cli/cmd/tui/context/route.tsx +45 -0
- package/src/cli/cmd/tui/context/sdk.tsx +75 -0
- package/src/cli/cmd/tui/context/sync.tsx +374 -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-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/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/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/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 +1077 -0
- package/src/cli/cmd/tui/event.ts +39 -0
- package/src/cli/cmd/tui/routes/home.tsx +104 -0
- package/src/cli/cmd/tui/routes/session/dialog-message.tsx +93 -0
- package/src/cli/cmd/tui/routes/session/dialog-timeline.tsx +37 -0
- package/src/cli/cmd/tui/routes/session/footer.tsx +76 -0
- package/src/cli/cmd/tui/routes/session/header.tsx +183 -0
- package/src/cli/cmd/tui/routes/session/index.tsx +1703 -0
- package/src/cli/cmd/tui/routes/session/sidebar.tsx +586 -0
- package/src/cli/cmd/tui/spawn.ts +60 -0
- package/src/cli/cmd/tui/thread.ts +120 -0
- package/src/cli/cmd/tui/ui/dialog-alert.tsx +55 -0
- package/src/cli/cmd/tui/ui/dialog-confirm.tsx +81 -0
- package/src/cli/cmd/tui/ui/dialog-help.tsx +36 -0
- package/src/cli/cmd/tui/ui/dialog-prompt.tsx +75 -0
- package/src/cli/cmd/tui/ui/dialog-select.tsx +317 -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 +67 -0
- package/src/cli/cmd/web.ts +84 -0
- package/src/cli/error.ts +55 -0
- package/src/cli/ui.ts +84 -0
- package/src/cli/upgrade.ts +25 -0
- package/src/command/index.ts +79 -0
- package/src/command/template/initialize.txt +10 -0
- package/src/command/template/review.txt +73 -0
- package/src/config/config.ts +886 -0
- package/src/config/markdown.ts +41 -0
- package/src/env/index.ts +26 -0
- package/src/file/fzf.ts +124 -0
- package/src/file/ignore.ts +83 -0
- package/src/file/index.ts +326 -0
- package/src/file/ripgrep.ts +391 -0
- package/src/file/time.ts +38 -0
- package/src/file/watcher.ts +89 -0
- package/src/flag/flag.ts +28 -0
- package/src/format/formatter.ts +277 -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 +75 -0
- package/src/index.ts +158 -0
- package/src/installation/index.ts +194 -0
- package/src/lsp/client.ts +215 -0
- package/src/lsp/index.ts +370 -0
- package/src/lsp/language.ts +111 -0
- package/src/lsp/server.ts +1327 -0
- package/src/mcp/auth.ts +82 -0
- package/src/mcp/index.ts +576 -0
- package/src/mcp/oauth-callback.ts +203 -0
- package/src/mcp/oauth-provider.ts +132 -0
- package/src/notification/index.ts +101 -0
- package/src/patch/index.ts +622 -0
- package/src/permission/index.ts +198 -0
- package/src/plugin/index.ts +95 -0
- package/src/project/bootstrap.ts +31 -0
- package/src/project/instance.ts +68 -0
- package/src/project/project.ts +133 -0
- package/src/project/state.ts +65 -0
- package/src/project/vcs.ts +77 -0
- package/src/provider/auth.ts +143 -0
- package/src/provider/models-macro.ts +11 -0
- package/src/provider/models.ts +93 -0
- package/src/provider/provider.ts +996 -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 +27 -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 +406 -0
- package/src/pty/index.ts +226 -0
- package/src/ratelimit/index.ts +185 -0
- package/src/server/error.ts +36 -0
- package/src/server/project.ts +50 -0
- package/src/server/server.ts +2463 -0
- package/src/server/tui.ts +71 -0
- package/src/session/compaction.ts +257 -0
- package/src/session/index.ts +470 -0
- package/src/session/message-v2.ts +641 -0
- package/src/session/message.ts +189 -0
- package/src/session/processor.ts +443 -0
- package/src/session/prompt/anthropic-20250930.txt +166 -0
- package/src/session/prompt/anthropic.txt +105 -0
- package/src/session/prompt/anthropic_spoof.txt +1 -0
- package/src/session/prompt/beast.txt +147 -0
- package/src/session/prompt/build-switch.txt +5 -0
- package/src/session/prompt/codex.txt +318 -0
- package/src/session/prompt/compaction.txt +12 -0
- package/src/session/prompt/copilot-gpt-5.txt +143 -0
- package/src/session/prompt/gemini.txt +155 -0
- package/src/session/prompt/max-steps.txt +16 -0
- package/src/session/prompt/plan-reminder-anthropic.txt +67 -0
- package/src/session/prompt/plan.txt +26 -0
- package/src/session/prompt/polaris.txt +107 -0
- package/src/session/prompt/qwen.txt +109 -0
- package/src/session/prompt/summarize.txt +4 -0
- package/src/session/prompt/title.txt +36 -0
- package/src/session/prompt.ts +1541 -0
- package/src/session/retry.ts +82 -0
- package/src/session/revert.ts +108 -0
- package/src/session/status.ts +75 -0
- package/src/session/summary.ts +203 -0
- package/src/session/system.ts +148 -0
- package/src/session/todo.ts +36 -0
- package/src/share/share-next.ts +195 -0
- package/src/share/share.ts +87 -0
- package/src/snapshot/index.ts +197 -0
- package/src/storage/storage.ts +226 -0
- package/src/telemetry/index.ts +232 -0
- package/src/tool/bash.ts +365 -0
- package/src/tool/bash.txt +128 -0
- package/src/tool/batch.ts +173 -0
- package/src/tool/batch.txt +28 -0
- package/src/tool/codesearch.ts +138 -0
- package/src/tool/codesearch.txt +12 -0
- package/src/tool/edit.ts +674 -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 +120 -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/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 +217 -0
- package/src/tool/read.txt +12 -0
- package/src/tool/registry.ts +148 -0
- package/src/tool/task.ts +135 -0
- package/src/tool/task.txt +60 -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 +66 -0
- package/src/tool/webfetch.ts +187 -0
- package/src/tool/webfetch.txt +14 -0
- package/src/tool/websearch.ts +150 -0
- package/src/tool/websearch.txt +11 -0
- package/src/tool/write.ts +99 -0
- package/src/tool/write.txt +8 -0
- package/src/types/shims.d.ts +3 -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 +69 -0
- package/src/util/fn.ts +11 -0
- package/src/util/iife.ts +3 -0
- package/src/util/keybind.ts +79 -0
- package/src/util/lazy.ts +11 -0
- package/src/util/locale.ts +81 -0
- package/src/util/lock.ts +98 -0
- package/src/util/log.ts +177 -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/bun.test.ts +53 -0
- package/test/config/agent-color.test.ts +66 -0
- package/test/config/config.test.ts +503 -0
- package/test/config/markdown.test.ts +89 -0
- package/test/file/ignore.test.ts +10 -0
- package/test/fixture/fixture.ts +28 -0
- package/test/fixture/lsp/fake-lsp-server.js +77 -0
- package/test/ide/ide.test.ts +82 -0
- package/test/keybind.test.ts +317 -0
- package/test/lsp/client.test.ts +95 -0
- package/test/patch/patch.test.ts +348 -0
- package/test/preload.ts +38 -0
- package/test/project/project.test.ts +42 -0
- package/test/provider/provider.test.ts +1809 -0
- package/test/provider/transform.test.ts +305 -0
- package/test/session/retry.test.ts +61 -0
- package/test/session/session.test.ts +71 -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 +55 -0
- package/test/tool/patch.test.ts +259 -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 +17 -0
package/src/mcp/auth.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import path from "path"
|
|
2
|
+
import fs from "fs/promises"
|
|
3
|
+
import z from "zod"
|
|
4
|
+
import { Global } from "../global"
|
|
5
|
+
|
|
6
|
+
export namespace McpAuth {
|
|
7
|
+
export const Tokens = z.object({
|
|
8
|
+
accessToken: z.string(),
|
|
9
|
+
refreshToken: z.string().optional(),
|
|
10
|
+
expiresAt: z.number().optional(),
|
|
11
|
+
scope: z.string().optional(),
|
|
12
|
+
})
|
|
13
|
+
export type Tokens = z.infer<typeof Tokens>
|
|
14
|
+
|
|
15
|
+
export const ClientInfo = z.object({
|
|
16
|
+
clientId: z.string(),
|
|
17
|
+
clientSecret: z.string().optional(),
|
|
18
|
+
clientIdIssuedAt: z.number().optional(),
|
|
19
|
+
clientSecretExpiresAt: z.number().optional(),
|
|
20
|
+
})
|
|
21
|
+
export type ClientInfo = z.infer<typeof ClientInfo>
|
|
22
|
+
|
|
23
|
+
export const Entry = z.object({
|
|
24
|
+
tokens: Tokens.optional(),
|
|
25
|
+
clientInfo: ClientInfo.optional(),
|
|
26
|
+
codeVerifier: z.string().optional(),
|
|
27
|
+
})
|
|
28
|
+
export type Entry = z.infer<typeof Entry>
|
|
29
|
+
|
|
30
|
+
const filepath = path.join(Global.Path.data, "mcp-auth.json")
|
|
31
|
+
|
|
32
|
+
export async function get(mcpName: string): Promise<Entry | undefined> {
|
|
33
|
+
const data = await all()
|
|
34
|
+
return data[mcpName]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function all(): Promise<Record<string, Entry>> {
|
|
38
|
+
const file = Bun.file(filepath)
|
|
39
|
+
return file.json().catch(() => ({}))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function set(mcpName: string, entry: Entry): Promise<void> {
|
|
43
|
+
const file = Bun.file(filepath)
|
|
44
|
+
const data = await all()
|
|
45
|
+
await Bun.write(file, JSON.stringify({ ...data, [mcpName]: entry }, null, 2))
|
|
46
|
+
await fs.chmod(file.name!, 0o600)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export async function remove(mcpName: string): Promise<void> {
|
|
50
|
+
const file = Bun.file(filepath)
|
|
51
|
+
const data = await all()
|
|
52
|
+
delete data[mcpName]
|
|
53
|
+
await Bun.write(file, JSON.stringify(data, null, 2))
|
|
54
|
+
await fs.chmod(file.name!, 0o600)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export async function updateTokens(mcpName: string, tokens: Tokens): Promise<void> {
|
|
58
|
+
const entry = (await get(mcpName)) ?? {}
|
|
59
|
+
entry.tokens = tokens
|
|
60
|
+
await set(mcpName, entry)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export async function updateClientInfo(mcpName: string, clientInfo: ClientInfo): Promise<void> {
|
|
64
|
+
const entry = (await get(mcpName)) ?? {}
|
|
65
|
+
entry.clientInfo = clientInfo
|
|
66
|
+
await set(mcpName, entry)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function updateCodeVerifier(mcpName: string, codeVerifier: string): Promise<void> {
|
|
70
|
+
const entry = (await get(mcpName)) ?? {}
|
|
71
|
+
entry.codeVerifier = codeVerifier
|
|
72
|
+
await set(mcpName, entry)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export async function clearCodeVerifier(mcpName: string): Promise<void> {
|
|
76
|
+
const entry = await get(mcpName)
|
|
77
|
+
if (entry) {
|
|
78
|
+
delete entry.codeVerifier
|
|
79
|
+
await set(mcpName, entry)
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
package/src/mcp/index.ts
ADDED
|
@@ -0,0 +1,576 @@
|
|
|
1
|
+
import { type Tool } from "ai"
|
|
2
|
+
import { experimental_createMCPClient } from "@ai-sdk/mcp"
|
|
3
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js"
|
|
4
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js"
|
|
5
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
|
|
6
|
+
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
|
|
7
|
+
import { Config } from "../config/config"
|
|
8
|
+
import { Log } from "../util/log"
|
|
9
|
+
import { NamedError } from "@opencode-ai/util/error"
|
|
10
|
+
import z from "zod/v4"
|
|
11
|
+
import { Instance } from "../project/instance"
|
|
12
|
+
import { withTimeout } from "@/util/timeout"
|
|
13
|
+
import { McpOAuthProvider } from "./oauth-provider"
|
|
14
|
+
import { McpOAuthCallback } from "./oauth-callback"
|
|
15
|
+
import { McpAuth } from "./auth"
|
|
16
|
+
import open from "open"
|
|
17
|
+
|
|
18
|
+
export namespace MCP {
|
|
19
|
+
const log = Log.create({ service: "mcp" })
|
|
20
|
+
|
|
21
|
+
export const Failed = NamedError.create(
|
|
22
|
+
"MCPFailed",
|
|
23
|
+
z.object({
|
|
24
|
+
name: z.string(),
|
|
25
|
+
}),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
type Client = Awaited<ReturnType<typeof experimental_createMCPClient>>
|
|
29
|
+
|
|
30
|
+
export const Status = z
|
|
31
|
+
.discriminatedUnion("status", [
|
|
32
|
+
z
|
|
33
|
+
.object({
|
|
34
|
+
status: z.literal("connected"),
|
|
35
|
+
})
|
|
36
|
+
.meta({
|
|
37
|
+
ref: "MCPStatusConnected",
|
|
38
|
+
}),
|
|
39
|
+
z
|
|
40
|
+
.object({
|
|
41
|
+
status: z.literal("disabled"),
|
|
42
|
+
})
|
|
43
|
+
.meta({
|
|
44
|
+
ref: "MCPStatusDisabled",
|
|
45
|
+
}),
|
|
46
|
+
z
|
|
47
|
+
.object({
|
|
48
|
+
status: z.literal("failed"),
|
|
49
|
+
error: z.string(),
|
|
50
|
+
})
|
|
51
|
+
.meta({
|
|
52
|
+
ref: "MCPStatusFailed",
|
|
53
|
+
}),
|
|
54
|
+
z
|
|
55
|
+
.object({
|
|
56
|
+
status: z.literal("needs_auth"),
|
|
57
|
+
})
|
|
58
|
+
.meta({
|
|
59
|
+
ref: "MCPStatusNeedsAuth",
|
|
60
|
+
}),
|
|
61
|
+
z
|
|
62
|
+
.object({
|
|
63
|
+
status: z.literal("needs_client_registration"),
|
|
64
|
+
error: z.string(),
|
|
65
|
+
})
|
|
66
|
+
.meta({
|
|
67
|
+
ref: "MCPStatusNeedsClientRegistration",
|
|
68
|
+
}),
|
|
69
|
+
])
|
|
70
|
+
.meta({
|
|
71
|
+
ref: "MCPStatus",
|
|
72
|
+
})
|
|
73
|
+
export type Status = z.infer<typeof Status>
|
|
74
|
+
type MCPClient = Awaited<ReturnType<typeof experimental_createMCPClient>>
|
|
75
|
+
|
|
76
|
+
// Store transports for OAuth servers to allow finishing auth
|
|
77
|
+
type TransportWithAuth = StreamableHTTPClientTransport | SSEClientTransport
|
|
78
|
+
const pendingOAuthTransports = new Map<string, TransportWithAuth>()
|
|
79
|
+
|
|
80
|
+
const state = Instance.state(
|
|
81
|
+
async () => {
|
|
82
|
+
const cfg = await Config.get()
|
|
83
|
+
const config = cfg.mcp ?? {}
|
|
84
|
+
const clients: Record<string, Client> = {}
|
|
85
|
+
const status: Record<string, Status> = {}
|
|
86
|
+
|
|
87
|
+
await Promise.all(
|
|
88
|
+
Object.entries(config).map(async ([key, mcp]) => {
|
|
89
|
+
// If disabled by config, mark as disabled without trying to connect
|
|
90
|
+
if (mcp.enabled === false) {
|
|
91
|
+
status[key] = { status: "disabled" }
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const result = await create(key, mcp).catch(() => undefined)
|
|
96
|
+
if (!result) return
|
|
97
|
+
|
|
98
|
+
status[key] = result.status
|
|
99
|
+
|
|
100
|
+
if (result.mcpClient) {
|
|
101
|
+
clients[key] = result.mcpClient
|
|
102
|
+
}
|
|
103
|
+
}),
|
|
104
|
+
)
|
|
105
|
+
return {
|
|
106
|
+
status,
|
|
107
|
+
clients,
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
async (state) => {
|
|
111
|
+
await Promise.all(
|
|
112
|
+
Object.values(state.clients).map((client) =>
|
|
113
|
+
client.close().catch((error) => {
|
|
114
|
+
log.error("Failed to close MCP client", {
|
|
115
|
+
error,
|
|
116
|
+
})
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
)
|
|
120
|
+
pendingOAuthTransports.clear()
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
export async function add(name: string, mcp: Config.Mcp) {
|
|
125
|
+
const s = await state()
|
|
126
|
+
const result = await create(name, mcp)
|
|
127
|
+
if (!result) {
|
|
128
|
+
const status = {
|
|
129
|
+
status: "failed" as const,
|
|
130
|
+
error: "unknown error",
|
|
131
|
+
}
|
|
132
|
+
s.status[name] = status
|
|
133
|
+
return {
|
|
134
|
+
status,
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (!result.mcpClient) {
|
|
138
|
+
s.status[name] = result.status
|
|
139
|
+
return {
|
|
140
|
+
status: s.status,
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
s.clients[name] = result.mcpClient
|
|
144
|
+
s.status[name] = result.status
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
status: s.status,
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async function create(key: string, mcp: Config.Mcp) {
|
|
152
|
+
if (mcp.enabled === false) {
|
|
153
|
+
log.info("mcp server disabled", { key })
|
|
154
|
+
return {
|
|
155
|
+
mcpClient: undefined,
|
|
156
|
+
status: { status: "disabled" as const },
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
log.info("found", { key, type: mcp.type })
|
|
160
|
+
let mcpClient: MCPClient | undefined
|
|
161
|
+
let status: Status | undefined = undefined
|
|
162
|
+
|
|
163
|
+
if (mcp.type === "remote") {
|
|
164
|
+
// OAuth is enabled by default for remote servers unless explicitly disabled with oauth: false
|
|
165
|
+
const oauthDisabled = mcp.oauth === false
|
|
166
|
+
const oauthConfig = typeof mcp.oauth === "object" ? mcp.oauth : undefined
|
|
167
|
+
let authProvider: McpOAuthProvider | undefined
|
|
168
|
+
|
|
169
|
+
if (!oauthDisabled) {
|
|
170
|
+
authProvider = new McpOAuthProvider(
|
|
171
|
+
key,
|
|
172
|
+
mcp.url,
|
|
173
|
+
{
|
|
174
|
+
clientId: oauthConfig?.clientId,
|
|
175
|
+
clientSecret: oauthConfig?.clientSecret,
|
|
176
|
+
scope: oauthConfig?.scope,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
onRedirect: async (url) => {
|
|
180
|
+
log.info("oauth redirect requested", { key, url: url.toString() })
|
|
181
|
+
// Store the URL - actual browser opening is handled by startAuth
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const transports: Array<{ name: string; transport: TransportWithAuth }> = [
|
|
188
|
+
{
|
|
189
|
+
name: "StreamableHTTP",
|
|
190
|
+
transport: new StreamableHTTPClientTransport(new URL(mcp.url), {
|
|
191
|
+
authProvider,
|
|
192
|
+
requestInit: oauthDisabled && mcp.headers ? { headers: mcp.headers } : undefined,
|
|
193
|
+
}),
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "SSE",
|
|
197
|
+
transport: new SSEClientTransport(new URL(mcp.url), {
|
|
198
|
+
authProvider,
|
|
199
|
+
requestInit: oauthDisabled && mcp.headers ? { headers: mcp.headers } : undefined,
|
|
200
|
+
}),
|
|
201
|
+
},
|
|
202
|
+
]
|
|
203
|
+
|
|
204
|
+
let lastError: Error | undefined
|
|
205
|
+
for (const { name, transport } of transports) {
|
|
206
|
+
try {
|
|
207
|
+
mcpClient = await experimental_createMCPClient({
|
|
208
|
+
name: "opencode",
|
|
209
|
+
transport,
|
|
210
|
+
})
|
|
211
|
+
log.info("connected", { key, transport: name })
|
|
212
|
+
status = { status: "connected" }
|
|
213
|
+
break
|
|
214
|
+
} catch (error) {
|
|
215
|
+
lastError = error instanceof Error ? error : new Error(String(error))
|
|
216
|
+
|
|
217
|
+
// Handle OAuth-specific errors
|
|
218
|
+
if (error instanceof UnauthorizedError) {
|
|
219
|
+
log.info("mcp server requires authentication", { key, transport: name })
|
|
220
|
+
|
|
221
|
+
// Check if this is a "needs registration" error
|
|
222
|
+
if (lastError.message.includes("registration") || lastError.message.includes("client_id")) {
|
|
223
|
+
status = {
|
|
224
|
+
status: "needs_client_registration" as const,
|
|
225
|
+
error: "Server does not support dynamic client registration. Please provide clientId in config.",
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
// Store transport for later finishAuth call
|
|
229
|
+
pendingOAuthTransports.set(key, transport)
|
|
230
|
+
status = { status: "needs_auth" as const }
|
|
231
|
+
}
|
|
232
|
+
break
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
log.debug("transport connection failed", {
|
|
236
|
+
key,
|
|
237
|
+
transport: name,
|
|
238
|
+
url: mcp.url,
|
|
239
|
+
error: lastError.message,
|
|
240
|
+
})
|
|
241
|
+
status = {
|
|
242
|
+
status: "failed" as const,
|
|
243
|
+
error: lastError.message,
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (mcp.type === "local") {
|
|
250
|
+
const [cmd, ...args] = mcp.command
|
|
251
|
+
await experimental_createMCPClient({
|
|
252
|
+
name: "opencode",
|
|
253
|
+
transport: new StdioClientTransport({
|
|
254
|
+
stderr: "ignore",
|
|
255
|
+
command: cmd,
|
|
256
|
+
args,
|
|
257
|
+
env: {
|
|
258
|
+
...process.env,
|
|
259
|
+
...(cmd === "opencode" ? { BUN_BE_BUN: "1" } : {}),
|
|
260
|
+
...mcp.environment,
|
|
261
|
+
},
|
|
262
|
+
}),
|
|
263
|
+
})
|
|
264
|
+
.then((client) => {
|
|
265
|
+
mcpClient = client
|
|
266
|
+
status = {
|
|
267
|
+
status: "connected",
|
|
268
|
+
}
|
|
269
|
+
})
|
|
270
|
+
.catch((error) => {
|
|
271
|
+
log.error("local mcp startup failed", {
|
|
272
|
+
key,
|
|
273
|
+
command: mcp.command,
|
|
274
|
+
error: error instanceof Error ? error.message : String(error),
|
|
275
|
+
})
|
|
276
|
+
status = {
|
|
277
|
+
status: "failed" as const,
|
|
278
|
+
error: error instanceof Error ? error.message : String(error),
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (!status) {
|
|
284
|
+
status = {
|
|
285
|
+
status: "failed" as const,
|
|
286
|
+
error: "Unknown error",
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (!mcpClient) {
|
|
291
|
+
return {
|
|
292
|
+
mcpClient: undefined,
|
|
293
|
+
status,
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const result = await withTimeout(mcpClient.tools(), mcp.timeout ?? 5000).catch((err) => {
|
|
298
|
+
log.error("failed to get tools from client", { key, error: err })
|
|
299
|
+
return undefined
|
|
300
|
+
})
|
|
301
|
+
if (!result) {
|
|
302
|
+
await mcpClient.close().catch((error) => {
|
|
303
|
+
log.error("Failed to close MCP client", {
|
|
304
|
+
error,
|
|
305
|
+
})
|
|
306
|
+
})
|
|
307
|
+
status = {
|
|
308
|
+
status: "failed",
|
|
309
|
+
error: "Failed to get tools",
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
mcpClient: undefined,
|
|
313
|
+
status: {
|
|
314
|
+
status: "failed" as const,
|
|
315
|
+
error: "Failed to get tools",
|
|
316
|
+
},
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
log.info("create() successfully created client", { key, toolCount: Object.keys(result).length })
|
|
321
|
+
return {
|
|
322
|
+
mcpClient,
|
|
323
|
+
status,
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export async function status() {
|
|
328
|
+
const s = await state()
|
|
329
|
+
const cfg = await Config.get()
|
|
330
|
+
const config = cfg.mcp ?? {}
|
|
331
|
+
const result: Record<string, Status> = {}
|
|
332
|
+
|
|
333
|
+
// Include all MCPs from config, not just connected ones
|
|
334
|
+
for (const key of Object.keys(config)) {
|
|
335
|
+
result[key] = s.status[key] ?? { status: "disabled" }
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return result
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export async function clients() {
|
|
342
|
+
return state().then((state) => state.clients)
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export async function connect(name: string) {
|
|
346
|
+
const cfg = await Config.get()
|
|
347
|
+
const config = cfg.mcp ?? {}
|
|
348
|
+
const mcp = config[name]
|
|
349
|
+
if (!mcp) {
|
|
350
|
+
log.error("MCP config not found", { name })
|
|
351
|
+
return
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const result = await create(name, { ...mcp, enabled: true })
|
|
355
|
+
|
|
356
|
+
if (!result) {
|
|
357
|
+
const s = await state()
|
|
358
|
+
s.status[name] = {
|
|
359
|
+
status: "failed",
|
|
360
|
+
error: "Unknown error during connection",
|
|
361
|
+
}
|
|
362
|
+
return
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const s = await state()
|
|
366
|
+
s.status[name] = result.status
|
|
367
|
+
if (result.mcpClient) {
|
|
368
|
+
s.clients[name] = result.mcpClient
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export async function disconnect(name: string) {
|
|
373
|
+
const s = await state()
|
|
374
|
+
const client = s.clients[name]
|
|
375
|
+
if (client) {
|
|
376
|
+
await client.close().catch((error) => {
|
|
377
|
+
log.error("Failed to close MCP client", { name, error })
|
|
378
|
+
})
|
|
379
|
+
delete s.clients[name]
|
|
380
|
+
}
|
|
381
|
+
s.status[name] = { status: "disabled" }
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export async function tools() {
|
|
385
|
+
const result: Record<string, Tool> = {}
|
|
386
|
+
const s = await state()
|
|
387
|
+
const clientsSnapshot = await clients()
|
|
388
|
+
|
|
389
|
+
for (const [clientName, client] of Object.entries(clientsSnapshot)) {
|
|
390
|
+
// Only include tools from connected MCPs (skip disabled ones)
|
|
391
|
+
if (s.status[clientName]?.status !== "connected") {
|
|
392
|
+
continue
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
const tools = await client.tools().catch((e) => {
|
|
396
|
+
log.error("failed to get tools", { clientName, error: e.message })
|
|
397
|
+
const failedStatus = {
|
|
398
|
+
status: "failed" as const,
|
|
399
|
+
error: e instanceof Error ? e.message : String(e),
|
|
400
|
+
}
|
|
401
|
+
s.status[clientName] = failedStatus
|
|
402
|
+
delete s.clients[clientName]
|
|
403
|
+
})
|
|
404
|
+
if (!tools) {
|
|
405
|
+
continue
|
|
406
|
+
}
|
|
407
|
+
for (const [toolName, tool] of Object.entries(tools)) {
|
|
408
|
+
const sanitizedClientName = clientName.replace(/[^a-zA-Z0-9_-]/g, "_")
|
|
409
|
+
const sanitizedToolName = toolName.replace(/[^a-zA-Z0-9_-]/g, "_")
|
|
410
|
+
result[sanitizedClientName + "_" + sanitizedToolName] = tool
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
return result
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/**
|
|
417
|
+
* Start OAuth authentication flow for an MCP server.
|
|
418
|
+
* Returns the authorization URL that should be opened in a browser.
|
|
419
|
+
*/
|
|
420
|
+
export async function startAuth(mcpName: string): Promise<{ authorizationUrl: string }> {
|
|
421
|
+
const cfg = await Config.get()
|
|
422
|
+
const mcpConfig = cfg.mcp?.[mcpName]
|
|
423
|
+
|
|
424
|
+
if (!mcpConfig) {
|
|
425
|
+
throw new Error(`MCP server not found: ${mcpName}`)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (mcpConfig.type !== "remote") {
|
|
429
|
+
throw new Error(`MCP server ${mcpName} is not a remote server`)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
if (mcpConfig.oauth === false) {
|
|
433
|
+
throw new Error(`MCP server ${mcpName} has OAuth explicitly disabled`)
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// Start the callback server
|
|
437
|
+
await McpOAuthCallback.ensureRunning()
|
|
438
|
+
|
|
439
|
+
// Create a new auth provider for this flow
|
|
440
|
+
// OAuth config is optional - if not provided, we'll use auto-discovery
|
|
441
|
+
const oauthConfig = typeof mcpConfig.oauth === "object" ? mcpConfig.oauth : undefined
|
|
442
|
+
let capturedUrl: URL | undefined
|
|
443
|
+
const authProvider = new McpOAuthProvider(
|
|
444
|
+
mcpName,
|
|
445
|
+
mcpConfig.url,
|
|
446
|
+
{
|
|
447
|
+
clientId: oauthConfig?.clientId,
|
|
448
|
+
clientSecret: oauthConfig?.clientSecret,
|
|
449
|
+
scope: oauthConfig?.scope,
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
onRedirect: async (url) => {
|
|
453
|
+
capturedUrl = url
|
|
454
|
+
},
|
|
455
|
+
},
|
|
456
|
+
)
|
|
457
|
+
|
|
458
|
+
// Create transport with auth provider
|
|
459
|
+
const transport = new StreamableHTTPClientTransport(new URL(mcpConfig.url), {
|
|
460
|
+
authProvider,
|
|
461
|
+
})
|
|
462
|
+
|
|
463
|
+
// Try to connect - this will trigger the OAuth flow
|
|
464
|
+
try {
|
|
465
|
+
await experimental_createMCPClient({
|
|
466
|
+
name: "opencode",
|
|
467
|
+
transport,
|
|
468
|
+
})
|
|
469
|
+
// If we get here, we're already authenticated
|
|
470
|
+
return { authorizationUrl: "" }
|
|
471
|
+
} catch (error) {
|
|
472
|
+
if (error instanceof UnauthorizedError && capturedUrl) {
|
|
473
|
+
// Store transport for finishAuth
|
|
474
|
+
pendingOAuthTransports.set(mcpName, transport)
|
|
475
|
+
return { authorizationUrl: capturedUrl.toString() }
|
|
476
|
+
}
|
|
477
|
+
throw error
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* Complete OAuth authentication after user authorizes in browser.
|
|
483
|
+
* Opens the browser and waits for callback.
|
|
484
|
+
*/
|
|
485
|
+
export async function authenticate(mcpName: string): Promise<Status> {
|
|
486
|
+
const { authorizationUrl } = await startAuth(mcpName)
|
|
487
|
+
|
|
488
|
+
if (!authorizationUrl) {
|
|
489
|
+
// Already authenticated
|
|
490
|
+
const s = await state()
|
|
491
|
+
return s.status[mcpName] ?? { status: "connected" }
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Extract state from authorization URL to use as callback key
|
|
495
|
+
// If no state parameter, use mcpName as fallback
|
|
496
|
+
const authUrl = new URL(authorizationUrl)
|
|
497
|
+
const oauthState = authUrl.searchParams.get("state") ?? mcpName
|
|
498
|
+
|
|
499
|
+
// Open browser
|
|
500
|
+
log.info("opening browser for oauth", { mcpName, url: authorizationUrl, state: oauthState })
|
|
501
|
+
await open(authorizationUrl)
|
|
502
|
+
|
|
503
|
+
// Wait for callback using the OAuth state parameter (or mcpName as fallback)
|
|
504
|
+
const code = await McpOAuthCallback.waitForCallback(oauthState)
|
|
505
|
+
|
|
506
|
+
// Finish auth
|
|
507
|
+
return finishAuth(mcpName, code)
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Complete OAuth authentication with the authorization code.
|
|
512
|
+
*/
|
|
513
|
+
export async function finishAuth(mcpName: string, authorizationCode: string): Promise<Status> {
|
|
514
|
+
const transport = pendingOAuthTransports.get(mcpName)
|
|
515
|
+
|
|
516
|
+
if (!transport) {
|
|
517
|
+
throw new Error(`No pending OAuth flow for MCP server: ${mcpName}`)
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
try {
|
|
521
|
+
// Call finishAuth on the transport
|
|
522
|
+
await transport.finishAuth(authorizationCode)
|
|
523
|
+
|
|
524
|
+
// Clear the code verifier after successful auth
|
|
525
|
+
await McpAuth.clearCodeVerifier(mcpName)
|
|
526
|
+
|
|
527
|
+
// Now try to reconnect
|
|
528
|
+
const cfg = await Config.get()
|
|
529
|
+
const mcpConfig = cfg.mcp?.[mcpName]
|
|
530
|
+
|
|
531
|
+
if (!mcpConfig) {
|
|
532
|
+
throw new Error(`MCP server not found: ${mcpName}`)
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// Re-add the MCP server to establish connection
|
|
536
|
+
pendingOAuthTransports.delete(mcpName)
|
|
537
|
+
const result = await add(mcpName, mcpConfig)
|
|
538
|
+
|
|
539
|
+
const statusRecord = result.status as Record<string, Status>
|
|
540
|
+
return statusRecord[mcpName] ?? { status: "failed", error: "Unknown error after auth" }
|
|
541
|
+
} catch (error) {
|
|
542
|
+
log.error("failed to finish oauth", { mcpName, error })
|
|
543
|
+
return {
|
|
544
|
+
status: "failed",
|
|
545
|
+
error: error instanceof Error ? error.message : String(error),
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
/**
|
|
551
|
+
* Remove OAuth credentials for an MCP server.
|
|
552
|
+
*/
|
|
553
|
+
export async function removeAuth(mcpName: string): Promise<void> {
|
|
554
|
+
await McpAuth.remove(mcpName)
|
|
555
|
+
McpOAuthCallback.cancelPending(mcpName)
|
|
556
|
+
pendingOAuthTransports.delete(mcpName)
|
|
557
|
+
log.info("removed oauth credentials", { mcpName })
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Check if an MCP server supports OAuth (remote servers support OAuth by default unless explicitly disabled).
|
|
562
|
+
*/
|
|
563
|
+
export async function supportsOAuth(mcpName: string): Promise<boolean> {
|
|
564
|
+
const cfg = await Config.get()
|
|
565
|
+
const mcpConfig = cfg.mcp?.[mcpName]
|
|
566
|
+
return mcpConfig?.type === "remote" && mcpConfig.oauth !== false
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* Check if an MCP server has stored OAuth tokens.
|
|
571
|
+
*/
|
|
572
|
+
export async function hasStoredTokens(mcpName: string): Promise<boolean> {
|
|
573
|
+
const entry = await McpAuth.get(mcpName)
|
|
574
|
+
return !!entry?.tokens
|
|
575
|
+
}
|
|
576
|
+
}
|