mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 00:35:51 +00:00
feat: 工具层及 mcp 大重构 (#252)
* feat: 第一版大重构 * fix: 修复类型问题 * chore: 更新版本到 1.3.2 * Add brave as alternative WebSearchTool * fix: 修正顺序 * fix: 修复对穷鬼模式的 auto dream 和 session memory 越过 * feat: 穷鬼模式去除 session-summary * feat: 创建 builtin-tools 包,搬运所有工具实现 将 src/tools/ 下的全部 60 个工具目录迁移至 packages/builtin-tools/src/tools/, 内部导入路径已更新为 src/ alias 模式。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: 更新 src/ 中所有工具引用至 builtin-tools 包,删除 src/tools/ - src/tools.ts 及 178 个 src/ 文件的 import 路径从 ./tools/ 改为 builtin-tools/tools/ - 删除 src/tools/ 整个目录(已迁移至 packages/builtin-tools/) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: 添加 builtin-tools 路径别名至 tsconfig,更新 bun.lock - tsconfig.json 新增 builtin-tools/* 和 builtin-tools 路径映射 - 新增 packages/builtin-tools/src 至 include Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: 为 builtin-tools、mcp-client、agent-tools 添加 @claude-code-best 作用域前缀 所有包名及 import 路径统一添加 @claude-code-best/ 前缀: - builtin-tools → @claude-code-best/builtin-tools - mcp-client → @claude-code-best/mcp-client - agent-tools → @claude-code-best/agent-tools Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 修复 node 环境没有 bun 的问题 --------- Co-authored-by: Eric-Guo <eric.guocz@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -50,10 +50,10 @@ import {
|
||||
type ToolCallProgress,
|
||||
toolMatchesName,
|
||||
} from '../../Tool.js'
|
||||
import { ListMcpResourcesTool } from '../../tools/ListMcpResourcesTool/ListMcpResourcesTool.js'
|
||||
import { type MCPProgress, MCPTool } from '../../tools/MCPTool/MCPTool.js'
|
||||
import { createMcpAuthTool } from '../../tools/McpAuthTool/McpAuthTool.js'
|
||||
import { ReadMcpResourceTool } from '../../tools/ReadMcpResourceTool/ReadMcpResourceTool.js'
|
||||
import { ListMcpResourcesTool } from '@claude-code-best/builtin-tools/tools/ListMcpResourcesTool/ListMcpResourcesTool.js'
|
||||
import { type MCPProgress, MCPTool } from '@claude-code-best/builtin-tools/tools/MCPTool/MCPTool.js'
|
||||
import { createMcpAuthTool } from '@claude-code-best/builtin-tools/tools/McpAuthTool/McpAuthTool.js'
|
||||
import { ReadMcpResourceTool } from '@claude-code-best/builtin-tools/tools/ReadMcpResourceTool/ReadMcpResourceTool.js'
|
||||
import { createAbortController } from '../../utils/abortController.js'
|
||||
import { count } from '../../utils/array.js'
|
||||
import {
|
||||
@@ -93,7 +93,6 @@ import {
|
||||
getWebSocketProxyAgent,
|
||||
getWebSocketProxyUrl,
|
||||
} from '../../utils/proxy.js'
|
||||
import { recursivelySanitizeUnicode } from '../../utils/sanitization.js'
|
||||
import { getSessionIngressAuthToken } from '../../utils/sessionIngressAuth.js'
|
||||
import { subprocessEnv } from '../../utils/subprocessEnv.js'
|
||||
import {
|
||||
@@ -113,6 +112,19 @@ import { buildMcpToolName } from './mcpStringUtils.js'
|
||||
import { normalizeNameForMCP } from './normalization.js'
|
||||
import { getLoggingSafeMcpBaseUrl } from './utils.js'
|
||||
|
||||
// Package imports — delegate to mcp-client package utilities where applicable
|
||||
import {
|
||||
createMcpClient as createMcpClientFromPackage,
|
||||
captureStderr,
|
||||
isMcpSessionExpiredError as isMcpSessionExpiredErrorFromPackage,
|
||||
installConnectionMonitor,
|
||||
createCleanup as createCleanupFromPackage,
|
||||
buildConnectedServer,
|
||||
DEFAULT_CONNECTION_TIMEOUT_MS,
|
||||
MAX_MCP_DESCRIPTION_LENGTH as PKG_MAX_MCP_DESCRIPTION_LENGTH,
|
||||
} from '@claude-code-best/mcp-client'
|
||||
import { recursivelySanitizeUnicode } from '@claude-code-best/mcp-client'
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
const fetchMcpSkillsForClient = feature('MCP_SKILLS')
|
||||
? (
|
||||
@@ -123,7 +135,7 @@ const fetchMcpSkillsForClient = feature('MCP_SKILLS')
|
||||
import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js'
|
||||
import type { AssistantMessage } from 'src/types/message.js'
|
||||
/* eslint-enable @typescript-eslint/no-require-imports */
|
||||
import { classifyMcpToolForCollapse } from '../../tools/MCPTool/classifyForCollapse.js'
|
||||
import { classifyMcpToolForCollapse } from '@claude-code-best/builtin-tools/tools/MCPTool/classifyForCollapse.js'
|
||||
import { clearKeychainCache } from '../../utils/secureStorage/macOsKeychainHelpers.js'
|
||||
import { sleep } from '../../utils/sleep.js'
|
||||
import {
|
||||
@@ -191,20 +203,7 @@ export class McpToolCallError_I_VERIFIED_THIS_IS_NOT_CODE_OR_FILEPATHS extends T
|
||||
* Per the MCP spec, servers return 404 when a session ID is no longer valid.
|
||||
* We check both signals to avoid false positives from generic 404s (wrong URL, server gone, etc.).
|
||||
*/
|
||||
export function isMcpSessionExpiredError(error: Error): boolean {
|
||||
const httpStatus =
|
||||
'code' in error ? (error as Error & { code?: number }).code : undefined
|
||||
if (httpStatus !== 404) {
|
||||
return false
|
||||
}
|
||||
// The SDK embeds the response body text in the error message.
|
||||
// MCP servers return: {"error":{"code":-32001,"message":"Session not found"},...}
|
||||
// Check for the JSON-RPC error code to distinguish from generic web server 404s.
|
||||
return (
|
||||
error.message.includes('"code":-32001') ||
|
||||
error.message.includes('"code": -32001')
|
||||
)
|
||||
}
|
||||
export const isMcpSessionExpiredError = isMcpSessionExpiredErrorFromPackage
|
||||
|
||||
/**
|
||||
* Default timeout for MCP tool calls (effectively infinite - ~27.8 hours).
|
||||
@@ -216,7 +215,7 @@ const DEFAULT_MCP_TOOL_TIMEOUT_MS = 100_000_000
|
||||
* OpenAPI-generated MCP servers have been observed dumping 15-60KB of endpoint
|
||||
* docs into tool.description; this caps the p95 tail without losing the intent.
|
||||
*/
|
||||
const MAX_MCP_DESCRIPTION_LENGTH = 2048
|
||||
const MAX_MCP_DESCRIPTION_LENGTH = PKG_MAX_MCP_DESCRIPTION_LENGTH
|
||||
|
||||
/**
|
||||
* Gets the timeout for MCP tool calls in milliseconds.
|
||||
|
||||
Reference in New Issue
Block a user