get_context_suggestions
Generate relevant context suggestions based on current user input and file history to maintain conversation continuity in AI-assisted development sessions.
Instructions
获取相关上下文建议
基于当前输入和文件推荐历史记录
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| currentInput | Yes | 当前用户输入 | |
| currentFiles | No | 当前涉及的文件 | |
| project | No | 项目过滤(可选) |
Implementation Reference
- src/tools/conversationLogger.ts:183-238 (handler)Main execution logic for the get_context_suggestions tool. Validates input, extracts keywords from user input, searches for matching past conversations in the project, and formats relevant suggestions.async getContextSuggestions(params: unknown): Promise<{ content: Array<{ type: string; text: string }> }> { try { const validatedParams = validateGetContextSuggestions(params); const { currentInput, currentFiles, project } = validatedParams; // 获取项目信息 const projectInfo = await this.fileManager.getProjectInfo(); const searchProject = project || projectInfo.name; // 构建搜索关键词:从输入中提取关键词 const keywords = currentInput.split(/\s+/).filter(word => word.length > 2); // 搜索相关对话 const searchResults = await this.searchInProject(searchProject, { keywords, limit: 5, filePattern: currentFiles && currentFiles.length > 0 ? currentFiles[0] : undefined, tags: [], platform: undefined, days: 30 }); if (searchResults.count === 0) { return { content: [ { type: 'text', text: '💡 暂无相关历史记录建议' } ] }; } return { content: [ { type: 'text', text: `💡 找到 ${searchResults.count} 条相关历史记录:\n\n${searchResults.content}` } ] }; } catch (error) { const errorMessage = error instanceof ValidationError ? `参数验证失败: ${error.message}` : `获取上下文建议时出错: ${String(error)}`; return { content: [ { type: 'text', text: `❌ ${errorMessage}` } ] }; } }
- src/validation/schemas.ts:52-59 (schema)Zod schema defining the input structure and validation for get_context_suggestions parameters.export const GetContextSuggestionsSchema = z.object({ currentInput: z.string().min(1, '当前输入不能为空'), currentFiles: z.array(z.string()).optional(), // 当前涉及的文件 project: z.string().optional() }).transform((data) => ({ ...data, currentFiles: data.currentFiles || [] }));
- src/index.ts:116-137 (registration)Tool registration in the MCP server's listTools request handler, providing name, description, and simplified input schema.name: 'get_context_suggestions', description: '获取相关上下文建议\n\n基于当前输入和文件推荐历史记录', inputSchema: { type: 'object', properties: { currentInput: { type: 'string', description: '当前用户输入' }, currentFiles: { type: 'array', items: { type: 'string' }, description: '当前涉及的文件' }, project: { type: 'string', description: '项目过滤(可选)' } }, required: ['currentInput'] } },
- src/index.ts:167-168 (registration)Dispatch logic in the MCP server's callTool request handler that routes get_context_suggestions calls to the ConversationLogger handler.case 'get_context_suggestions': return await this.conversationLogger.getContextSuggestions(args || {});
- src/validation/schemas.ts:137-144 (schema)Validation function for get_context_suggestions input parameters using the defined Zod schema.export const validateGetContextSuggestions = (data: unknown): GetContextSuggestionsParams => { const result = GetContextSuggestionsSchema.safeParse(data); if (!result.success) { const errorMessages = result.error.errors.map(err => `${err.path.join('.')}: ${err.message}`).join('; '); throw new Error(`${CONSTANTS.ERROR_MESSAGES.INVALID_PARAMETERS}: ${errorMessages}`); } return result.data as GetContextSuggestionsParams; };