@shareai-lab/kode 1.1.14 → 1.1.16-dev.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.
- package/cli.js +77 -82
- package/dist/entrypoints/cli.js +59 -38
- package/dist/entrypoints/cli.js.map +3 -3
- package/dist/index.js +5 -26
- package/dist/package.json +4 -1
- package/package.json +11 -104
- package/dist/test/testAdapters.js +0 -88
- package/dist/test/testAdapters.js.map +0 -1
- package/src/ProjectOnboarding.tsx +0 -198
- package/src/Tool.ts +0 -83
- package/src/commands/agents.tsx +0 -3416
- package/src/commands/approvedTools.ts +0 -53
- package/src/commands/bug.tsx +0 -20
- package/src/commands/clear.ts +0 -43
- package/src/commands/compact.ts +0 -120
- package/src/commands/config.tsx +0 -19
- package/src/commands/cost.ts +0 -18
- package/src/commands/ctx_viz.ts +0 -209
- package/src/commands/doctor.ts +0 -24
- package/src/commands/help.tsx +0 -19
- package/src/commands/init.ts +0 -37
- package/src/commands/listen.ts +0 -42
- package/src/commands/login.tsx +0 -51
- package/src/commands/logout.tsx +0 -40
- package/src/commands/mcp.ts +0 -41
- package/src/commands/model.tsx +0 -40
- package/src/commands/modelstatus.tsx +0 -20
- package/src/commands/onboarding.tsx +0 -34
- package/src/commands/pr_comments.ts +0 -59
- package/src/commands/refreshCommands.ts +0 -54
- package/src/commands/release-notes.ts +0 -34
- package/src/commands/resume.tsx +0 -31
- package/src/commands/review.ts +0 -49
- package/src/commands/terminalSetup.ts +0 -221
- package/src/commands.ts +0 -139
- package/src/components/ApproveApiKey.tsx +0 -93
- package/src/components/AsciiLogo.tsx +0 -13
- package/src/components/AutoUpdater.tsx +0 -148
- package/src/components/Bug.tsx +0 -367
- package/src/components/Config.tsx +0 -293
- package/src/components/ConsoleOAuthFlow.tsx +0 -327
- package/src/components/Cost.tsx +0 -23
- package/src/components/CostThresholdDialog.tsx +0 -46
- package/src/components/CustomSelect/option-map.ts +0 -42
- package/src/components/CustomSelect/select-option.tsx +0 -78
- package/src/components/CustomSelect/select.tsx +0 -152
- package/src/components/CustomSelect/theme.ts +0 -45
- package/src/components/CustomSelect/use-select-state.ts +0 -414
- package/src/components/CustomSelect/use-select.ts +0 -35
- package/src/components/FallbackToolUseRejectedMessage.tsx +0 -15
- package/src/components/FileEditToolUpdatedMessage.tsx +0 -66
- package/src/components/Help.tsx +0 -215
- package/src/components/HighlightedCode.tsx +0 -33
- package/src/components/InvalidConfigDialog.tsx +0 -113
- package/src/components/Link.tsx +0 -32
- package/src/components/LogSelector.tsx +0 -86
- package/src/components/Logo.tsx +0 -170
- package/src/components/MCPServerApprovalDialog.tsx +0 -100
- package/src/components/MCPServerDialogCopy.tsx +0 -25
- package/src/components/MCPServerMultiselectDialog.tsx +0 -109
- package/src/components/Message.tsx +0 -221
- package/src/components/MessageResponse.tsx +0 -15
- package/src/components/MessageSelector.tsx +0 -211
- package/src/components/ModeIndicator.tsx +0 -88
- package/src/components/ModelConfig.tsx +0 -301
- package/src/components/ModelListManager.tsx +0 -227
- package/src/components/ModelSelector.tsx +0 -3387
- package/src/components/ModelStatusDisplay.tsx +0 -230
- package/src/components/Onboarding.tsx +0 -274
- package/src/components/PressEnterToContinue.tsx +0 -11
- package/src/components/PromptInput.tsx +0 -760
- package/src/components/SentryErrorBoundary.ts +0 -39
- package/src/components/Spinner.tsx +0 -129
- package/src/components/StickerRequestForm.tsx +0 -16
- package/src/components/StructuredDiff.tsx +0 -191
- package/src/components/TextInput.tsx +0 -259
- package/src/components/TodoItem.tsx +0 -47
- package/src/components/TokenWarning.tsx +0 -31
- package/src/components/ToolUseLoader.tsx +0 -40
- package/src/components/TrustDialog.tsx +0 -106
- package/src/components/binary-feedback/BinaryFeedback.tsx +0 -63
- package/src/components/binary-feedback/BinaryFeedbackOption.tsx +0 -111
- package/src/components/binary-feedback/BinaryFeedbackView.tsx +0 -172
- package/src/components/binary-feedback/utils.ts +0 -220
- package/src/components/messages/AssistantBashOutputMessage.tsx +0 -22
- package/src/components/messages/AssistantLocalCommandOutputMessage.tsx +0 -49
- package/src/components/messages/AssistantRedactedThinkingMessage.tsx +0 -19
- package/src/components/messages/AssistantTextMessage.tsx +0 -144
- package/src/components/messages/AssistantThinkingMessage.tsx +0 -40
- package/src/components/messages/AssistantToolUseMessage.tsx +0 -132
- package/src/components/messages/TaskProgressMessage.tsx +0 -32
- package/src/components/messages/TaskToolMessage.tsx +0 -58
- package/src/components/messages/UserBashInputMessage.tsx +0 -28
- package/src/components/messages/UserCommandMessage.tsx +0 -30
- package/src/components/messages/UserKodingInputMessage.tsx +0 -28
- package/src/components/messages/UserPromptMessage.tsx +0 -35
- package/src/components/messages/UserTextMessage.tsx +0 -39
- package/src/components/messages/UserToolResultMessage/UserToolCanceledMessage.tsx +0 -12
- package/src/components/messages/UserToolResultMessage/UserToolErrorMessage.tsx +0 -36
- package/src/components/messages/UserToolResultMessage/UserToolRejectMessage.tsx +0 -31
- package/src/components/messages/UserToolResultMessage/UserToolResultMessage.tsx +0 -57
- package/src/components/messages/UserToolResultMessage/UserToolSuccessMessage.tsx +0 -35
- package/src/components/messages/UserToolResultMessage/utils.tsx +0 -56
- package/src/components/permissions/BashPermissionRequest/BashPermissionRequest.tsx +0 -121
- package/src/components/permissions/FallbackPermissionRequest.tsx +0 -153
- package/src/components/permissions/FileEditPermissionRequest/FileEditPermissionRequest.tsx +0 -182
- package/src/components/permissions/FileEditPermissionRequest/FileEditToolDiff.tsx +0 -77
- package/src/components/permissions/FileWritePermissionRequest/FileWritePermissionRequest.tsx +0 -164
- package/src/components/permissions/FileWritePermissionRequest/FileWriteToolDiff.tsx +0 -83
- package/src/components/permissions/FilesystemPermissionRequest/FilesystemPermissionRequest.tsx +0 -240
- package/src/components/permissions/PermissionRequest.tsx +0 -101
- package/src/components/permissions/PermissionRequestTitle.tsx +0 -69
- package/src/components/permissions/hooks.ts +0 -44
- package/src/components/permissions/toolUseOptions.ts +0 -59
- package/src/components/permissions/utils.ts +0 -23
- package/src/constants/betas.ts +0 -5
- package/src/constants/claude-asterisk-ascii-art.tsx +0 -238
- package/src/constants/figures.ts +0 -4
- package/src/constants/keys.ts +0 -3
- package/src/constants/macros.ts +0 -11
- package/src/constants/modelCapabilities.ts +0 -179
- package/src/constants/models.ts +0 -1025
- package/src/constants/oauth.ts +0 -18
- package/src/constants/product.ts +0 -17
- package/src/constants/prompts.ts +0 -168
- package/src/constants/releaseNotes.ts +0 -7
- package/src/context/PermissionContext.tsx +0 -149
- package/src/context.ts +0 -278
- package/src/cost-tracker.ts +0 -84
- package/src/entrypoints/cli.tsx +0 -1561
- package/src/entrypoints/mcp.ts +0 -175
- package/src/history.ts +0 -25
- package/src/hooks/useApiKeyVerification.ts +0 -59
- package/src/hooks/useArrowKeyHistory.ts +0 -55
- package/src/hooks/useCanUseTool.ts +0 -138
- package/src/hooks/useCancelRequest.ts +0 -39
- package/src/hooks/useDoublePress.ts +0 -41
- package/src/hooks/useExitOnCtrlCD.ts +0 -31
- package/src/hooks/useInterval.ts +0 -25
- package/src/hooks/useLogMessages.ts +0 -16
- package/src/hooks/useLogStartupTime.ts +0 -12
- package/src/hooks/useNotifyAfterTimeout.ts +0 -65
- package/src/hooks/usePermissionRequestLogging.ts +0 -44
- package/src/hooks/useTerminalSize.ts +0 -49
- package/src/hooks/useTextInput.ts +0 -317
- package/src/hooks/useUnifiedCompletion.ts +0 -1405
- package/src/index.ts +0 -34
- package/src/messages.ts +0 -38
- package/src/permissions.ts +0 -268
- package/src/query.ts +0 -720
- package/src/screens/ConfigureNpmPrefix.tsx +0 -197
- package/src/screens/Doctor.tsx +0 -219
- package/src/screens/LogList.tsx +0 -68
- package/src/screens/REPL.tsx +0 -813
- package/src/screens/ResumeConversation.tsx +0 -68
- package/src/services/adapters/base.ts +0 -38
- package/src/services/adapters/chatCompletions.ts +0 -90
- package/src/services/adapters/responsesAPI.ts +0 -170
- package/src/services/browserMocks.ts +0 -66
- package/src/services/claude.ts +0 -2197
- package/src/services/customCommands.ts +0 -704
- package/src/services/fileFreshness.ts +0 -377
- package/src/services/gpt5ConnectionTest.ts +0 -340
- package/src/services/mcpClient.ts +0 -564
- package/src/services/mcpServerApproval.tsx +0 -50
- package/src/services/mentionProcessor.ts +0 -273
- package/src/services/modelAdapterFactory.ts +0 -69
- package/src/services/notifier.ts +0 -40
- package/src/services/oauth.ts +0 -357
- package/src/services/openai.ts +0 -1359
- package/src/services/responseStateManager.ts +0 -90
- package/src/services/sentry.ts +0 -3
- package/src/services/statsig.ts +0 -172
- package/src/services/statsigStorage.ts +0 -86
- package/src/services/systemReminder.ts +0 -507
- package/src/services/vcr.ts +0 -161
- package/src/test/testAdapters.ts +0 -96
- package/src/tools/ArchitectTool/ArchitectTool.tsx +0 -135
- package/src/tools/ArchitectTool/prompt.ts +0 -15
- package/src/tools/AskExpertModelTool/AskExpertModelTool.tsx +0 -576
- package/src/tools/BashTool/BashTool.tsx +0 -243
- package/src/tools/BashTool/BashToolResultMessage.tsx +0 -38
- package/src/tools/BashTool/OutputLine.tsx +0 -49
- package/src/tools/BashTool/prompt.ts +0 -174
- package/src/tools/BashTool/utils.ts +0 -56
- package/src/tools/FileEditTool/FileEditTool.tsx +0 -319
- package/src/tools/FileEditTool/prompt.ts +0 -51
- package/src/tools/FileEditTool/utils.ts +0 -58
- package/src/tools/FileReadTool/FileReadTool.tsx +0 -404
- package/src/tools/FileReadTool/prompt.ts +0 -7
- package/src/tools/FileWriteTool/FileWriteTool.tsx +0 -301
- package/src/tools/FileWriteTool/prompt.ts +0 -10
- package/src/tools/GlobTool/GlobTool.tsx +0 -119
- package/src/tools/GlobTool/prompt.ts +0 -8
- package/src/tools/GrepTool/GrepTool.tsx +0 -147
- package/src/tools/GrepTool/prompt.ts +0 -11
- package/src/tools/MCPTool/MCPTool.tsx +0 -107
- package/src/tools/MCPTool/prompt.ts +0 -3
- package/src/tools/MemoryReadTool/MemoryReadTool.tsx +0 -127
- package/src/tools/MemoryReadTool/prompt.ts +0 -3
- package/src/tools/MemoryWriteTool/MemoryWriteTool.tsx +0 -89
- package/src/tools/MemoryWriteTool/prompt.ts +0 -3
- package/src/tools/MultiEditTool/MultiEditTool.tsx +0 -388
- package/src/tools/MultiEditTool/prompt.ts +0 -45
- package/src/tools/NotebookEditTool/NotebookEditTool.tsx +0 -298
- package/src/tools/NotebookEditTool/prompt.ts +0 -3
- package/src/tools/NotebookReadTool/NotebookReadTool.tsx +0 -258
- package/src/tools/NotebookReadTool/prompt.ts +0 -3
- package/src/tools/StickerRequestTool/StickerRequestTool.tsx +0 -107
- package/src/tools/StickerRequestTool/prompt.ts +0 -19
- package/src/tools/TaskTool/TaskTool.tsx +0 -438
- package/src/tools/TaskTool/constants.ts +0 -1
- package/src/tools/TaskTool/prompt.ts +0 -92
- package/src/tools/ThinkTool/ThinkTool.tsx +0 -54
- package/src/tools/ThinkTool/prompt.ts +0 -12
- package/src/tools/TodoWriteTool/TodoWriteTool.tsx +0 -313
- package/src/tools/TodoWriteTool/prompt.ts +0 -63
- package/src/tools/URLFetcherTool/URLFetcherTool.tsx +0 -178
- package/src/tools/URLFetcherTool/cache.ts +0 -55
- package/src/tools/URLFetcherTool/htmlToMarkdown.ts +0 -55
- package/src/tools/URLFetcherTool/prompt.ts +0 -17
- package/src/tools/WebSearchTool/WebSearchTool.tsx +0 -103
- package/src/tools/WebSearchTool/prompt.ts +0 -13
- package/src/tools/WebSearchTool/searchProviders.ts +0 -66
- package/src/tools/lsTool/lsTool.tsx +0 -272
- package/src/tools/lsTool/prompt.ts +0 -2
- package/src/tools.ts +0 -67
- package/src/types/PermissionMode.ts +0 -120
- package/src/types/RequestContext.ts +0 -72
- package/src/types/common.d.ts +0 -2
- package/src/types/conversation.ts +0 -51
- package/src/types/logs.ts +0 -58
- package/src/types/modelCapabilities.ts +0 -64
- package/src/types/notebook.ts +0 -87
- package/src/utils/Cursor.ts +0 -436
- package/src/utils/PersistentShell.ts +0 -552
- package/src/utils/advancedFuzzyMatcher.ts +0 -290
- package/src/utils/agentLoader.ts +0 -278
- package/src/utils/agentStorage.ts +0 -97
- package/src/utils/array.ts +0 -3
- package/src/utils/ask.tsx +0 -99
- package/src/utils/auth.ts +0 -13
- package/src/utils/autoCompactCore.ts +0 -223
- package/src/utils/autoUpdater.ts +0 -458
- package/src/utils/betas.ts +0 -20
- package/src/utils/browser.ts +0 -14
- package/src/utils/cleanup.ts +0 -72
- package/src/utils/commands.ts +0 -261
- package/src/utils/commonUnixCommands.ts +0 -161
- package/src/utils/config.ts +0 -945
- package/src/utils/conversationRecovery.ts +0 -55
- package/src/utils/debugLogger.ts +0 -1235
- package/src/utils/diff.ts +0 -42
- package/src/utils/env.ts +0 -57
- package/src/utils/errors.ts +0 -21
- package/src/utils/exampleCommands.ts +0 -109
- package/src/utils/execFileNoThrow.ts +0 -51
- package/src/utils/expertChatStorage.ts +0 -136
- package/src/utils/file.ts +0 -405
- package/src/utils/fileRecoveryCore.ts +0 -71
- package/src/utils/format.tsx +0 -44
- package/src/utils/fuzzyMatcher.ts +0 -328
- package/src/utils/generators.ts +0 -62
- package/src/utils/git.ts +0 -92
- package/src/utils/globalLogger.ts +0 -77
- package/src/utils/http.ts +0 -10
- package/src/utils/imagePaste.ts +0 -38
- package/src/utils/json.ts +0 -13
- package/src/utils/log.ts +0 -382
- package/src/utils/markdown.ts +0 -213
- package/src/utils/messageContextManager.ts +0 -294
- package/src/utils/messages.tsx +0 -945
- package/src/utils/model.ts +0 -914
- package/src/utils/permissions/filesystem.ts +0 -127
- package/src/utils/responseState.ts +0 -23
- package/src/utils/ripgrep.ts +0 -167
- package/src/utils/secureFile.ts +0 -564
- package/src/utils/sessionState.ts +0 -49
- package/src/utils/state.ts +0 -25
- package/src/utils/style.ts +0 -29
- package/src/utils/terminal.ts +0 -50
- package/src/utils/theme.ts +0 -127
- package/src/utils/thinking.ts +0 -144
- package/src/utils/todoStorage.ts +0 -431
- package/src/utils/tokens.ts +0 -43
- package/src/utils/toolExecutionController.ts +0 -163
- package/src/utils/unaryLogging.ts +0 -26
- package/src/utils/user.ts +0 -37
- package/src/utils/validate.ts +0 -165
|
@@ -1,564 +0,0 @@
|
|
|
1
|
-
import { zipObject } from 'lodash-es'
|
|
2
|
-
import {
|
|
3
|
-
getCurrentProjectConfig,
|
|
4
|
-
McpServerConfig,
|
|
5
|
-
saveCurrentProjectConfig,
|
|
6
|
-
getGlobalConfig,
|
|
7
|
-
saveGlobalConfig,
|
|
8
|
-
getMcprcConfig,
|
|
9
|
-
addMcprcServerForTesting,
|
|
10
|
-
removeMcprcServerForTesting,
|
|
11
|
-
} from '../utils/config.js'
|
|
12
|
-
import { existsSync, readFileSync, writeFileSync } from 'fs'
|
|
13
|
-
import { join } from 'path'
|
|
14
|
-
import { getCwd } from '../utils/state'
|
|
15
|
-
import { safeParseJSON } from '../utils/json'
|
|
16
|
-
import {
|
|
17
|
-
ImageBlockParam,
|
|
18
|
-
MessageParam,
|
|
19
|
-
ToolResultBlockParam,
|
|
20
|
-
} from '@anthropic-ai/sdk/resources/index.mjs'
|
|
21
|
-
import { Client } from '@modelcontextprotocol/sdk/client/index.js'
|
|
22
|
-
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'
|
|
23
|
-
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js'
|
|
24
|
-
import {
|
|
25
|
-
CallToolResultSchema,
|
|
26
|
-
ClientRequest,
|
|
27
|
-
ListPromptsResult,
|
|
28
|
-
ListPromptsResultSchema,
|
|
29
|
-
ListToolsResult,
|
|
30
|
-
ListToolsResultSchema,
|
|
31
|
-
Result,
|
|
32
|
-
ResultSchema,
|
|
33
|
-
} from '@modelcontextprotocol/sdk/types.js'
|
|
34
|
-
import { memoize, pickBy } from 'lodash-es'
|
|
35
|
-
import type { Tool } from '../Tool'
|
|
36
|
-
import { MCPTool } from '../tools/MCPTool/MCPTool'
|
|
37
|
-
import { logMCPError } from '../utils/log'
|
|
38
|
-
import { Command } from '../commands'
|
|
39
|
-
import { logEvent } from '../services/statsig'
|
|
40
|
-
import { PRODUCT_COMMAND } from '../constants/product.js'
|
|
41
|
-
|
|
42
|
-
type McpName = string
|
|
43
|
-
|
|
44
|
-
export function parseEnvVars(
|
|
45
|
-
rawEnvArgs: string[] | undefined,
|
|
46
|
-
): Record<string, string> {
|
|
47
|
-
const parsedEnv: Record<string, string> = {}
|
|
48
|
-
|
|
49
|
-
// Parse individual env vars
|
|
50
|
-
if (rawEnvArgs) {
|
|
51
|
-
for (const envStr of rawEnvArgs) {
|
|
52
|
-
const [key, ...valueParts] = envStr.split('=')
|
|
53
|
-
if (!key || valueParts.length === 0) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Invalid environment variable format: ${envStr}, environment variables should be added as: -e KEY1=value1 -e KEY2=value2`,
|
|
56
|
-
)
|
|
57
|
-
}
|
|
58
|
-
parsedEnv[key] = valueParts.join('=')
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return parsedEnv
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const VALID_SCOPES = ['project', 'global', 'mcprc'] as const
|
|
65
|
-
type ConfigScope = (typeof VALID_SCOPES)[number]
|
|
66
|
-
const EXTERNAL_SCOPES = ['project', 'global'] as ConfigScope[]
|
|
67
|
-
|
|
68
|
-
export function ensureConfigScope(scope?: string): ConfigScope {
|
|
69
|
-
if (!scope) return 'project'
|
|
70
|
-
|
|
71
|
-
const scopesToCheck =
|
|
72
|
-
process.env.USER_TYPE === 'external' ? EXTERNAL_SCOPES : VALID_SCOPES
|
|
73
|
-
|
|
74
|
-
if (!scopesToCheck.includes(scope as ConfigScope)) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
`Invalid scope: ${scope}. Must be one of: ${scopesToCheck.join(', ')}`,
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return scope as ConfigScope
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function addMcpServer(
|
|
84
|
-
name: McpName,
|
|
85
|
-
server: McpServerConfig,
|
|
86
|
-
scope: ConfigScope = 'project',
|
|
87
|
-
): void {
|
|
88
|
-
if (scope === 'mcprc') {
|
|
89
|
-
if (process.env.NODE_ENV === 'test') {
|
|
90
|
-
addMcprcServerForTesting(name, server)
|
|
91
|
-
} else {
|
|
92
|
-
const mcprcPath = join(getCwd(), '.mcprc')
|
|
93
|
-
let mcprcConfig: Record<string, McpServerConfig> = {}
|
|
94
|
-
|
|
95
|
-
// Read existing config if present
|
|
96
|
-
if (existsSync(mcprcPath)) {
|
|
97
|
-
try {
|
|
98
|
-
const mcprcContent = readFileSync(mcprcPath, 'utf-8')
|
|
99
|
-
const existingConfig = safeParseJSON(mcprcContent)
|
|
100
|
-
if (existingConfig && typeof existingConfig === 'object') {
|
|
101
|
-
mcprcConfig = existingConfig as Record<string, McpServerConfig>
|
|
102
|
-
}
|
|
103
|
-
} catch {
|
|
104
|
-
// If we can't read/parse, start with empty config
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Add the server
|
|
109
|
-
mcprcConfig[name] = server
|
|
110
|
-
|
|
111
|
-
// Write back to .mcprc
|
|
112
|
-
try {
|
|
113
|
-
writeFileSync(mcprcPath, JSON.stringify(mcprcConfig, null, 2), 'utf-8')
|
|
114
|
-
} catch (error) {
|
|
115
|
-
throw new Error(`Failed to write to .mcprc: ${error}`)
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
} else if (scope === 'global') {
|
|
119
|
-
const config = getGlobalConfig()
|
|
120
|
-
if (!config.mcpServers) {
|
|
121
|
-
config.mcpServers = {}
|
|
122
|
-
}
|
|
123
|
-
config.mcpServers[name] = server
|
|
124
|
-
saveGlobalConfig(config)
|
|
125
|
-
} else {
|
|
126
|
-
const config = getCurrentProjectConfig()
|
|
127
|
-
if (!config.mcpServers) {
|
|
128
|
-
config.mcpServers = {}
|
|
129
|
-
}
|
|
130
|
-
config.mcpServers[name] = server
|
|
131
|
-
saveCurrentProjectConfig(config)
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export function removeMcpServer(
|
|
136
|
-
name: McpName,
|
|
137
|
-
scope: ConfigScope = 'project',
|
|
138
|
-
): void {
|
|
139
|
-
if (scope === 'mcprc') {
|
|
140
|
-
if (process.env.NODE_ENV === 'test') {
|
|
141
|
-
removeMcprcServerForTesting(name)
|
|
142
|
-
} else {
|
|
143
|
-
const mcprcPath = join(getCwd(), '.mcprc')
|
|
144
|
-
if (!existsSync(mcprcPath)) {
|
|
145
|
-
throw new Error('No .mcprc file found in this directory')
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
const mcprcContent = readFileSync(mcprcPath, 'utf-8')
|
|
150
|
-
const mcprcConfig = safeParseJSON(mcprcContent) as Record<
|
|
151
|
-
string,
|
|
152
|
-
McpServerConfig
|
|
153
|
-
> | null
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
!mcprcConfig ||
|
|
157
|
-
typeof mcprcConfig !== 'object' ||
|
|
158
|
-
!mcprcConfig[name]
|
|
159
|
-
) {
|
|
160
|
-
throw new Error(`No MCP server found with name: ${name} in .mcprc`)
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
delete mcprcConfig[name]
|
|
164
|
-
writeFileSync(mcprcPath, JSON.stringify(mcprcConfig, null, 2), 'utf-8')
|
|
165
|
-
} catch (error) {
|
|
166
|
-
if (error instanceof Error) {
|
|
167
|
-
throw error
|
|
168
|
-
}
|
|
169
|
-
throw new Error(`Failed to remove from .mcprc: ${error}`)
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
} else if (scope === 'global') {
|
|
173
|
-
const config = getGlobalConfig()
|
|
174
|
-
if (!config.mcpServers?.[name]) {
|
|
175
|
-
throw new Error(`No global MCP server found with name: ${name}`)
|
|
176
|
-
}
|
|
177
|
-
delete config.mcpServers[name]
|
|
178
|
-
saveGlobalConfig(config)
|
|
179
|
-
} else {
|
|
180
|
-
const config = getCurrentProjectConfig()
|
|
181
|
-
if (!config.mcpServers?.[name]) {
|
|
182
|
-
throw new Error(`No local MCP server found with name: ${name}`)
|
|
183
|
-
}
|
|
184
|
-
delete config.mcpServers[name]
|
|
185
|
-
saveCurrentProjectConfig(config)
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export function listMCPServers(): Record<string, McpServerConfig> {
|
|
190
|
-
const globalConfig = getGlobalConfig()
|
|
191
|
-
const mcprcConfig = getMcprcConfig()
|
|
192
|
-
const projectConfig = getCurrentProjectConfig()
|
|
193
|
-
return {
|
|
194
|
-
...(globalConfig.mcpServers ?? {}),
|
|
195
|
-
...(mcprcConfig ?? {}), // mcprc configs override global ones
|
|
196
|
-
...(projectConfig.mcpServers ?? {}), // Project configs override mcprc ones
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export type ScopedMcpServerConfig = McpServerConfig & {
|
|
201
|
-
scope: ConfigScope
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export function getMcpServer(name: McpName): ScopedMcpServerConfig | undefined {
|
|
205
|
-
const projectConfig = getCurrentProjectConfig()
|
|
206
|
-
const mcprcConfig = getMcprcConfig()
|
|
207
|
-
const globalConfig = getGlobalConfig()
|
|
208
|
-
|
|
209
|
-
// Check each scope in order of precedence
|
|
210
|
-
if (projectConfig.mcpServers?.[name]) {
|
|
211
|
-
return { ...projectConfig.mcpServers[name], scope: 'project' }
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (mcprcConfig?.[name]) {
|
|
215
|
-
return { ...mcprcConfig[name], scope: 'mcprc' }
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
if (globalConfig.mcpServers?.[name]) {
|
|
219
|
-
return { ...globalConfig.mcpServers[name], scope: 'global' }
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
return undefined
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
async function connectToServer(
|
|
226
|
-
name: string,
|
|
227
|
-
serverRef: McpServerConfig,
|
|
228
|
-
): Promise<Client> {
|
|
229
|
-
const transport =
|
|
230
|
-
serverRef.type === 'sse'
|
|
231
|
-
? new SSEClientTransport(new URL(serverRef.url))
|
|
232
|
-
: new StdioClientTransport({
|
|
233
|
-
command: serverRef.command,
|
|
234
|
-
args: serverRef.args,
|
|
235
|
-
env: {
|
|
236
|
-
...process.env,
|
|
237
|
-
...serverRef.env,
|
|
238
|
-
} as Record<string, string>,
|
|
239
|
-
stderr: 'pipe', // prevents error output from the MCP server from printing to the UI
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
const client = new Client(
|
|
243
|
-
{
|
|
244
|
-
name: PRODUCT_COMMAND,
|
|
245
|
-
version: '0.1.0',
|
|
246
|
-
},
|
|
247
|
-
{
|
|
248
|
-
capabilities: {},
|
|
249
|
-
},
|
|
250
|
-
)
|
|
251
|
-
|
|
252
|
-
// Add a timeout to connection attempts to prevent tests from hanging indefinitely
|
|
253
|
-
const CONNECTION_TIMEOUT_MS = 5000
|
|
254
|
-
const connectPromise = client.connect(transport)
|
|
255
|
-
const timeoutPromise = new Promise<never>((_, reject) => {
|
|
256
|
-
const timeoutId = setTimeout(() => {
|
|
257
|
-
reject(
|
|
258
|
-
new Error(
|
|
259
|
-
`Connection to MCP server "${name}" timed out after ${CONNECTION_TIMEOUT_MS}ms`,
|
|
260
|
-
),
|
|
261
|
-
)
|
|
262
|
-
}, CONNECTION_TIMEOUT_MS)
|
|
263
|
-
|
|
264
|
-
// Clean up timeout if connect resolves or rejects
|
|
265
|
-
connectPromise.then(
|
|
266
|
-
() => clearTimeout(timeoutId),
|
|
267
|
-
() => clearTimeout(timeoutId),
|
|
268
|
-
)
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
await Promise.race([connectPromise, timeoutPromise])
|
|
272
|
-
|
|
273
|
-
if (serverRef.type === 'stdio') {
|
|
274
|
-
;(transport as StdioClientTransport).stderr?.on('data', (data: Buffer) => {
|
|
275
|
-
const errorText = data.toString().trim()
|
|
276
|
-
if (errorText) {
|
|
277
|
-
logMCPError(name, `Server stderr: ${errorText}`)
|
|
278
|
-
}
|
|
279
|
-
})
|
|
280
|
-
}
|
|
281
|
-
return client
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
type ConnectedClient = {
|
|
285
|
-
client: Client
|
|
286
|
-
name: string
|
|
287
|
-
type: 'connected'
|
|
288
|
-
}
|
|
289
|
-
type FailedClient = {
|
|
290
|
-
name: string
|
|
291
|
-
type: 'failed'
|
|
292
|
-
}
|
|
293
|
-
export type WrappedClient = ConnectedClient | FailedClient
|
|
294
|
-
|
|
295
|
-
export function getMcprcServerStatus(
|
|
296
|
-
serverName: string,
|
|
297
|
-
): 'approved' | 'rejected' | 'pending' {
|
|
298
|
-
const config = getCurrentProjectConfig()
|
|
299
|
-
if (config.approvedMcprcServers?.includes(serverName)) {
|
|
300
|
-
return 'approved'
|
|
301
|
-
}
|
|
302
|
-
if (config.rejectedMcprcServers?.includes(serverName)) {
|
|
303
|
-
return 'rejected'
|
|
304
|
-
}
|
|
305
|
-
return 'pending'
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
export const getClients = memoize(async (): Promise<WrappedClient[]> => {
|
|
309
|
-
// TODO: This is a temporary fix for a hang during npm run verify in CI.
|
|
310
|
-
// We need to investigate why MCP client connections hang in CI verify but not in CI tests.
|
|
311
|
-
if (process.env.CI && process.env.NODE_ENV !== 'test') {
|
|
312
|
-
return []
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
const globalServers = getGlobalConfig().mcpServers ?? {}
|
|
316
|
-
const mcprcServers = getMcprcConfig()
|
|
317
|
-
const projectServers = getCurrentProjectConfig().mcpServers ?? {}
|
|
318
|
-
|
|
319
|
-
// Filter mcprc servers to only include approved ones
|
|
320
|
-
const approvedMcprcServers = pickBy(
|
|
321
|
-
mcprcServers,
|
|
322
|
-
(_, name) => getMcprcServerStatus(name) === 'approved',
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
const allServers = {
|
|
326
|
-
...globalServers,
|
|
327
|
-
...approvedMcprcServers, // Approved .mcprc servers override global ones
|
|
328
|
-
...projectServers, // Project servers take highest precedence
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
return await Promise.all(
|
|
332
|
-
Object.entries(allServers).map(async ([name, serverRef]) => {
|
|
333
|
-
try {
|
|
334
|
-
const client = await connectToServer(name, serverRef as McpServerConfig)
|
|
335
|
-
logEvent('tengu_mcp_server_connection_succeeded', {})
|
|
336
|
-
return { name, client, type: 'connected' as const }
|
|
337
|
-
} catch (error) {
|
|
338
|
-
logEvent('tengu_mcp_server_connection_failed', {})
|
|
339
|
-
logMCPError(
|
|
340
|
-
name,
|
|
341
|
-
`Connection failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
342
|
-
)
|
|
343
|
-
return { name, type: 'failed' as const }
|
|
344
|
-
}
|
|
345
|
-
}),
|
|
346
|
-
)
|
|
347
|
-
})
|
|
348
|
-
|
|
349
|
-
async function requestAll<
|
|
350
|
-
ResultT extends Result,
|
|
351
|
-
ResultSchemaT extends typeof ResultSchema,
|
|
352
|
-
>(
|
|
353
|
-
req: ClientRequest,
|
|
354
|
-
resultSchema: ResultSchemaT,
|
|
355
|
-
requiredCapability: string,
|
|
356
|
-
): Promise<{ client: ConnectedClient; result: ResultT }[]> {
|
|
357
|
-
const clients = await getClients()
|
|
358
|
-
const results = await Promise.allSettled(
|
|
359
|
-
clients.map(async client => {
|
|
360
|
-
if (client.type === 'failed') return null
|
|
361
|
-
|
|
362
|
-
try {
|
|
363
|
-
const capabilities = await client.client.getServerCapabilities()
|
|
364
|
-
if (!capabilities?.[requiredCapability]) {
|
|
365
|
-
return null
|
|
366
|
-
}
|
|
367
|
-
return {
|
|
368
|
-
client,
|
|
369
|
-
result: (await client.client.request(req, resultSchema)) as ResultT,
|
|
370
|
-
}
|
|
371
|
-
} catch (error) {
|
|
372
|
-
if (client.type === 'connected') {
|
|
373
|
-
logMCPError(
|
|
374
|
-
client.name,
|
|
375
|
-
`Failed to request '${req.method}': ${error instanceof Error ? error.message : String(error)}`,
|
|
376
|
-
)
|
|
377
|
-
}
|
|
378
|
-
return null
|
|
379
|
-
}
|
|
380
|
-
}),
|
|
381
|
-
)
|
|
382
|
-
return results
|
|
383
|
-
.filter(
|
|
384
|
-
(
|
|
385
|
-
result,
|
|
386
|
-
): result is PromiseFulfilledResult<{
|
|
387
|
-
client: ConnectedClient
|
|
388
|
-
result: ResultT
|
|
389
|
-
} | null> => result.status === 'fulfilled',
|
|
390
|
-
)
|
|
391
|
-
.map(result => result.value)
|
|
392
|
-
.filter(
|
|
393
|
-
(result): result is { client: ConnectedClient; result: ResultT } =>
|
|
394
|
-
result !== null,
|
|
395
|
-
)
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
export const getMCPTools = memoize(async (): Promise<Tool[]> => {
|
|
399
|
-
const toolsList = await requestAll<
|
|
400
|
-
ListToolsResult,
|
|
401
|
-
typeof ListToolsResultSchema
|
|
402
|
-
>(
|
|
403
|
-
{
|
|
404
|
-
method: 'tools/list',
|
|
405
|
-
},
|
|
406
|
-
ListToolsResultSchema,
|
|
407
|
-
'tools',
|
|
408
|
-
)
|
|
409
|
-
|
|
410
|
-
// TODO: Add zod schema validation
|
|
411
|
-
return toolsList.flatMap(({ client, result: { tools } }) =>
|
|
412
|
-
tools.map(
|
|
413
|
-
(tool): Tool => ({
|
|
414
|
-
...MCPTool,
|
|
415
|
-
name: 'mcp__' + client.name + '__' + tool.name,
|
|
416
|
-
async description() {
|
|
417
|
-
return tool.description ?? ''
|
|
418
|
-
},
|
|
419
|
-
async prompt() {
|
|
420
|
-
return tool.description ?? ''
|
|
421
|
-
},
|
|
422
|
-
inputJSONSchema: tool.inputSchema as Tool['inputJSONSchema'],
|
|
423
|
-
async validateInput(input, context) {
|
|
424
|
-
// MCP tools handle their own validation through their schemas
|
|
425
|
-
return { result: true }
|
|
426
|
-
},
|
|
427
|
-
async *call(args: Record<string, unknown>, context) {
|
|
428
|
-
const data = await callMCPTool({ client, tool: tool.name, args })
|
|
429
|
-
yield {
|
|
430
|
-
type: 'result' as const,
|
|
431
|
-
data,
|
|
432
|
-
resultForAssistant: data,
|
|
433
|
-
}
|
|
434
|
-
},
|
|
435
|
-
userFacingName() {
|
|
436
|
-
return `${client.name}:${tool.name} (MCP)`
|
|
437
|
-
},
|
|
438
|
-
}),
|
|
439
|
-
),
|
|
440
|
-
)
|
|
441
|
-
})
|
|
442
|
-
|
|
443
|
-
async function callMCPTool({
|
|
444
|
-
client: { client, name },
|
|
445
|
-
tool,
|
|
446
|
-
args,
|
|
447
|
-
}: {
|
|
448
|
-
client: ConnectedClient
|
|
449
|
-
tool: string
|
|
450
|
-
args: Record<string, unknown>
|
|
451
|
-
}): Promise<ToolResultBlockParam['content']> {
|
|
452
|
-
const result = await client.callTool(
|
|
453
|
-
{
|
|
454
|
-
name: tool,
|
|
455
|
-
arguments: args,
|
|
456
|
-
},
|
|
457
|
-
CallToolResultSchema,
|
|
458
|
-
)
|
|
459
|
-
|
|
460
|
-
if ('isError' in result && result.isError) {
|
|
461
|
-
const errorMessage = `Error calling tool ${tool}: ${result.error}`
|
|
462
|
-
logMCPError(name, errorMessage)
|
|
463
|
-
throw Error(errorMessage)
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
// Handle toolResult-type response
|
|
467
|
-
if ('toolResult' in result) {
|
|
468
|
-
return String(result.toolResult)
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
// Handle content array response
|
|
472
|
-
if ('content' in result && Array.isArray(result.content)) {
|
|
473
|
-
return result.content.map(item => {
|
|
474
|
-
if (item.type === 'image') {
|
|
475
|
-
return {
|
|
476
|
-
type: 'image',
|
|
477
|
-
source: {
|
|
478
|
-
type: 'base64',
|
|
479
|
-
data: String(item.data),
|
|
480
|
-
media_type: item.mimeType as ImageBlockParam.Source['media_type'],
|
|
481
|
-
},
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return item
|
|
485
|
-
})
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
throw Error(`Unexpected response format from tool ${tool}`)
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
export const getMCPCommands = memoize(async (): Promise<Command[]> => {
|
|
492
|
-
const results = await requestAll<
|
|
493
|
-
ListPromptsResult,
|
|
494
|
-
typeof ListPromptsResultSchema
|
|
495
|
-
>(
|
|
496
|
-
{
|
|
497
|
-
method: 'prompts/list',
|
|
498
|
-
},
|
|
499
|
-
ListPromptsResultSchema,
|
|
500
|
-
'prompts',
|
|
501
|
-
)
|
|
502
|
-
|
|
503
|
-
return results.flatMap(({ client, result }) =>
|
|
504
|
-
result.prompts?.map(_ => {
|
|
505
|
-
const argNames = Object.values(_.arguments ?? {}).map(k => k.name)
|
|
506
|
-
return {
|
|
507
|
-
type: 'prompt',
|
|
508
|
-
name: 'mcp__' + client.name + '__' + _.name,
|
|
509
|
-
description: _.description ?? '',
|
|
510
|
-
isEnabled: true,
|
|
511
|
-
isHidden: false,
|
|
512
|
-
progressMessage: 'running',
|
|
513
|
-
userFacingName() {
|
|
514
|
-
return `${client.name}:${_.name} (MCP)`
|
|
515
|
-
},
|
|
516
|
-
argNames,
|
|
517
|
-
async getPromptForCommand(args: string) {
|
|
518
|
-
const argsArray = args.split(' ')
|
|
519
|
-
return await runCommand(
|
|
520
|
-
{ name: _.name, client },
|
|
521
|
-
zipObject(argNames, argsArray),
|
|
522
|
-
)
|
|
523
|
-
},
|
|
524
|
-
}
|
|
525
|
-
}),
|
|
526
|
-
)
|
|
527
|
-
})
|
|
528
|
-
|
|
529
|
-
export async function runCommand(
|
|
530
|
-
{ name, client }: { name: string; client: ConnectedClient },
|
|
531
|
-
args: Record<string, string>,
|
|
532
|
-
): Promise<MessageParam[]> {
|
|
533
|
-
try {
|
|
534
|
-
const result = await client.client.getPrompt({ name, arguments: args })
|
|
535
|
-
// TODO: Support type == resource
|
|
536
|
-
return result.messages.map(
|
|
537
|
-
(message): MessageParam => ({
|
|
538
|
-
role: message.role,
|
|
539
|
-
content: [
|
|
540
|
-
message.content.type === 'text'
|
|
541
|
-
? {
|
|
542
|
-
type: 'text',
|
|
543
|
-
text: message.content.text,
|
|
544
|
-
}
|
|
545
|
-
: {
|
|
546
|
-
type: 'image',
|
|
547
|
-
source: {
|
|
548
|
-
data: String(message.content.data),
|
|
549
|
-
media_type: message.content
|
|
550
|
-
.mimeType as ImageBlockParam.Source['media_type'],
|
|
551
|
-
type: 'base64',
|
|
552
|
-
},
|
|
553
|
-
},
|
|
554
|
-
],
|
|
555
|
-
}),
|
|
556
|
-
)
|
|
557
|
-
} catch (error) {
|
|
558
|
-
logMCPError(
|
|
559
|
-
client.name,
|
|
560
|
-
`Error running command '${name}': ${error instanceof Error ? error.message : String(error)}`,
|
|
561
|
-
)
|
|
562
|
-
throw error
|
|
563
|
-
}
|
|
564
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { render } from 'ink'
|
|
3
|
-
import { MCPServerMultiselectDialog } from '../components/MCPServerMultiselectDialog'
|
|
4
|
-
import { MCPServerApprovalDialog } from '../components/MCPServerApprovalDialog'
|
|
5
|
-
import { getMcprcServerStatus } from './mcpClient'
|
|
6
|
-
import { getMcprcConfig } from '../utils/config'
|
|
7
|
-
|
|
8
|
-
export async function handleMcprcServerApprovals(): Promise<void> {
|
|
9
|
-
const mcprcServers = getMcprcConfig()
|
|
10
|
-
const pendingServers = Object.keys(mcprcServers).filter(
|
|
11
|
-
serverName => getMcprcServerStatus(serverName) === 'pending',
|
|
12
|
-
)
|
|
13
|
-
|
|
14
|
-
if (pendingServers.length === 0) {
|
|
15
|
-
return
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
await new Promise<void>(resolve => {
|
|
19
|
-
const clearScreenAndResolve = () => {
|
|
20
|
-
// Clear screen after dialog
|
|
21
|
-
process.stdout.write('\x1b[2J\x1b[3J\x1b[H', () => {
|
|
22
|
-
resolve()
|
|
23
|
-
})
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (pendingServers.length === 1 && pendingServers[0] !== undefined) {
|
|
27
|
-
const result = render(
|
|
28
|
-
<MCPServerApprovalDialog
|
|
29
|
-
serverName={pendingServers[0]}
|
|
30
|
-
onDone={() => {
|
|
31
|
-
result.unmount?.()
|
|
32
|
-
clearScreenAndResolve()
|
|
33
|
-
}}
|
|
34
|
-
/>,
|
|
35
|
-
{ exitOnCtrlC: false },
|
|
36
|
-
)
|
|
37
|
-
} else {
|
|
38
|
-
const result = render(
|
|
39
|
-
<MCPServerMultiselectDialog
|
|
40
|
-
serverNames={pendingServers}
|
|
41
|
-
onDone={() => {
|
|
42
|
-
result.unmount?.()
|
|
43
|
-
clearScreenAndResolve()
|
|
44
|
-
}}
|
|
45
|
-
/>,
|
|
46
|
-
{ exitOnCtrlC: false },
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
}
|