Skip to main content
Glama

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
NameRequiredDescriptionDefault
currentInputYes当前用户输入
currentFilesNo当前涉及的文件
projectNo项目过滤(可选)

Implementation Reference

  • 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}` } ] }; } }
  • 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 || {});
  • 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; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fablefang/ai-conversation-logger-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server