search_user_messages
Find messages from specific Mattermost users by name or username, optionally filtering by keywords to locate relevant conversations.
Instructions
특정 사용자의 메시지를 이름이나 username으로 검색합니다. '박찬우', 'cwpark' 등으로 검색 가능.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| user_name | Yes | 검색할 사용자의 이름 또는 username (예: '박찬우', 'cwpark') | |
| keyword | No | 추가로 검색할 키워드 (선택사항) |
Implementation Reference
- src/index.ts:430-506 (handler)The handler function for the 'search_user_messages' tool. It searches for the user by name or username, constructs a search query for their messages with an optional keyword, fetches the posts using Mattermost API, enriches with user info, and returns formatted results.case "search_user_messages": { const userName = args.user_name as string; const keyword = (args.keyword as string) || ""; // 먼저 사용자 검색 let users: MattermostUser[] = []; try { // username으로 직접 조회 시도 const user = await client.getUserByUsername(userName); users = [user]; } catch { // 실패하면 검색으로 시도 users = await client.searchUsers(userName); } if (users.length === 0) { return { content: [ { type: "text", text: JSON.stringify({ error: `사용자 '${userName}'를 찾을 수 없습니다.`, total_count: 0, posts: [], }, null, 2), }, ], }; } // 첫 번째 매칭된 사용자의 메시지 검색 const user = users[0]; const searchQuery = keyword ? `from:${user.username} ${keyword}` : `from:${user.username}`; const result = await client.searchPosts(searchQuery, false); // 고유한 user_id 추출 및 사용자 정보 조회 const uniqueUserIds = [...new Set(result.order?.map((postId: string) => result.posts[postId].user_id) || [])]; const userMap = await client.getUsersInfo(uniqueUserIds); const posts = result.order?.map((postId: string) => { const post = result.posts[postId]; const createTime = formatTimestamp(post.create_at); const updateTime = formatTimestamp(post.update_at); const userInfo = userMap.get(post.user_id); return { id: post.id, message: post.message, user_id: post.user_id, username: userInfo?.username || "unknown", user_name: userInfo?.name || "Unknown User", channel_id: post.channel_id, create_at: createTime, update_at: updateTime, }; }) || []; return { content: [ { type: "text", text: JSON.stringify({ found_user: { id: user.id, username: user.username, name: `${user.first_name} ${user.last_name}`.trim() || user.nickname, }, total_count: posts.length, posts: posts, }, null, 2), }, ], }; }
- src/index.ts:225-242 (registration)Registration of the 'search_user_messages' tool in the ListTools response, including its name, description, and input schema definition.{ name: "search_user_messages", description: "특정 사용자의 메시지를 이름이나 username으로 검색합니다. '박찬우', 'cwpark' 등으로 검색 가능.", inputSchema: { type: "object", properties: { user_name: { type: "string", description: "검색할 사용자의 이름 또는 username (예: '박찬우', 'cwpark')", }, keyword: { type: "string", description: "추가로 검색할 키워드 (선택사항)", }, }, required: ["user_name"], }, },
- src/index.ts:228-241 (schema)Input schema definition for the 'search_user_messages' tool, specifying parameters user_name (required) and keyword (optional).inputSchema: { type: "object", properties: { user_name: { type: "string", description: "검색할 사용자의 이름 또는 username (예: '박찬우', 'cwpark')", }, keyword: { type: "string", description: "추가로 검색할 키워드 (선택사항)", }, }, required: ["user_name"], },