refactor(mcp): trim exposed tool registry

This commit is contained in:
digua committed 2026-05-21 22:38:10 +08:00
1 parent 5db4b3bf9d
commit 3a2d4e753a
4 files changed
+25 -26

No files matched your search

-1
View File
@@ -21,7 +21,6 @@ import { getServerAiLogger } from './logger'
const DEFAULT_MAX_TOOL_RESULT_TOKENS = 8000
const TOOL_TRUNCATION_STRATEGY: Record<string, TruncationStrategy> = {
search_keyword: 'keep_first',
search_messages: 'keep_first',
deep_search_messages: 'keep_first',
get_recent_messages: 'keep_last',
+2 -6
View File
@@ -17,10 +17,7 @@ import { formatToolResultAsText } from './format'
const MCP_TOOL_PREFIX = 'chatlab_'
const FORMAT_PARAM = z
.enum(['text', 'json'])
.optional()
.describe('Output format: "text" for token-efficient plain text (default), "json" for structured JSON')
const FORMAT_PARAM = z.enum(['text', 'json']).optional().describe('text (default) or json')
/** Tools where JSON is a better default (raw SQL results, schema) */
const JSON_DEFAULT_TOOLS = new Set(['execute_sql', 'get_schema'])
@@ -60,9 +57,8 @@ function registerTools(server: McpServer, dbManager: McpDatabaseManager): void {
continue
}
const sessionsToolMcpName = `${MCP_TOOL_PREFIX}list_sessions`
const zodShape = {
session_id: z.string().describe(`Session ID (use ${sessionsToolMcpName} to get available sessions)`),
session_id: z.string().describe('Session ID'),
...jsonSchemaToZod(tool.inputSchema.properties, tool.inputSchema.required),
format: FORMAT_PARAM,
}
+1 -1
View File
@@ -14,7 +14,7 @@ export { CoreDataProvider } from './providers/core-data-provider'
// === Tool Definitions ===
export { memberStatsTool } from './definitions/member-stats'
export { timeStatsTool } from './definitions/time-stats'
export { searchTool } from './definitions/search'
export { recentMessagesTool } from './definitions/recent-messages'
export { sqlQueryTool, schemaTool } from './definitions/sql-query'
export { chatOverviewTool } from './definitions/chat-overview'
+22 -18
View File
@@ -1,14 +1,15 @@
/**
* 工具注册表
* Tool registries
*
* AGENT_TOOL_REGISTRY: Agent 共用(Server Agent / Electron Agent),
* 与 Electron TOOL_REGISTRY 保持一致的完整工具集。
* MCP_TOOL_REGISTRY: MCP Server 使用,包含 Agent 全量工具 + MCP 特有的会话发现工具。
* AGENT_TOOL_REGISTRY: full toolset for Server Agent / Electron Agent
* (core + analysis + raw SQL + declarative SQL tools).
* MCP_TOOL_REGISTRY: slim toolset for MCP Server — core + analysis + raw SQL
* plus MCP-specific session-discovery tools. Omits declarative SQL tools
* to keep tool-schema token cost low for external AI agents.
*/
import type { ToolDefinition } from './types'
import { searchTool } from './definitions/search'
import { sqlQueryTool, schemaTool } from './definitions/sql-query'
import { sessionInfoTool } from './definitions/session-info'
import { sessionsListTool } from './definitions/sessions'
@@ -30,12 +31,10 @@ import { keywordFrequencyTool } from './definitions/keyword-frequency'
import { SQL_TOOL_DEFS, createAllSqlToolDefinitions } from './sql'
/**
* Agent 共用注册表
*
* 与 Electron TOOL_REGISTRY 完全对齐的工具集,在"已选定会话"上下文中使用。
* 不包含 MCP 特有的会话发现工具(list_sessions、get_session_info、search_keyword)。
* Core + analysis + raw SQL — shared between Agent and MCP.
* New non-SQL tools added here will automatically appear in both registries.
*/
export const AGENT_TOOL_REGISTRY: ToolDefinition[] = [
const SHARED_TOOLS: ToolDefinition[] = [
// Core
chatOverviewTool,
searchMessagesTool,
@@ -55,25 +54,30 @@ export const AGENT_TOOL_REGISTRY: ToolDefinition[] = [
responseTimeAnalysisTool,
keywordFrequencyTool,
// SQL
// Raw SQL
sqlQueryTool,
...createAllSqlToolDefinitions(SQL_TOOL_DEFS),
]
/**
* MCP Server 注册表
* Agent full toolset (Server Agent / Electron Agent).
* Includes declarative SQL convenience tools on top of the shared set.
*/
export const AGENT_TOOL_REGISTRY: ToolDefinition[] = [...SHARED_TOOLS, ...createAllSqlToolDefinitions(SQL_TOOL_DEFS)]
/**
* MCP Server toolset — slim registry optimised for external AI agents.
*
* 包含 MCP 特有工具(会话发现、schema)以及完整的 Agent 工具集。
* MCP 层自动为非 list_sessions 工具注入 session_id 参数。
* Includes MCP-specific session-discovery tools + shared core/analysis tools.
* Omits declarative SQL tools to reduce tool-schema token overhead (~40% saving).
* LLMs can use execute_sql + get_schema for any custom query.
*/
export const MCP_TOOL_REGISTRY: ToolDefinition[] = [
// MCP-specific: session discovery & schema
sessionsListTool,
sessionInfoTool,
searchTool,
schemaTool,
// Full agent toolset
...AGENT_TOOL_REGISTRY,
// Shared core + analysis + raw SQL
...SHARED_TOOLS,
]
/**