Skip to main content
Glama

get_context_suggestions

Provides context suggestions for AI assistants by analyzing user input and file history. Enhances understanding of project continuity and improves conversation logging in structured markdown format.

Instructions

获取相关上下文建议

基于当前输入和文件推荐历史记录

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
currentFilesNo当前涉及的文件
currentInputYes当前用户输入
projectNo项目过滤(可选)

Implementation Reference

  • The core handler function that executes the 'get_context_suggestions' tool. It validates parameters, extracts keywords from current input, searches for matching historical conversations in the project using searchInProject, and returns formatted context suggestions or an error message.
    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/index.ts:115-137 (registration)
    Registers the 'get_context_suggestions' tool in the MCP server's listTools handler, providing name, description, and 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)
    The switch case in CallToolRequest handler that routes calls to the getContextSuggestions method on conversationLogger.
    case 'get_context_suggestions': return await this.conversationLogger.getContextSuggestions(args || {});
  • Zod schema for validating input parameters to the get_context_suggestions tool.
    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 || [] }));
  • Validation function that uses the schema to parse and validate input parameters, throwing ValidationError on failure.
    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; };

Other Tools

Related Tools

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