search-notes
Search note.com articles by keyword with customizable sorting options and result limits to find relevant content quickly.
Instructions
記事を検索する
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 検索キーワード | |
| size | No | 取得する件数(最大20) | |
| start | No | 検索結果の開始位置 | |
| sort | No | ソート順(new: 新着順, popular: 人気順, hot: 急上昇) | hot |
Implementation Reference
- src/tools/search-tools.ts:26-55 (handler)The core handler function for the 'search-notes' tool. It makes an API request to note.com's search endpoint (/v3/searches?context=note), processes the response, extracts and formats notes using safeExtractData and formatNote, computes total count, and returns a success response or handles errors.async ({ query, size, start, sort }) => { try { const data = await noteApiRequest(`/v3/searches?context=note&q=${encodeURIComponent(query)}&size=${size}&start=${start}&sort=${sort}`); if (env.DEBUG) { console.error(`API Response structure for search-notes: ${JSON.stringify(data, null, 2)}`); } if (!data || !data.data) { return createErrorResponse(`APIレスポンスが空です: ${JSON.stringify(data)}`); } if (data.status === "error" || data.error) { return createErrorResponse(`APIエラー: ${JSON.stringify(data)}`); } const notesArray = safeExtractData(data, commonExtractors.notes); const totalCount = safeExtractTotal(data, notesArray.length); const formattedNotes = notesArray.map(note => formatNote(note)); return createSuccessResponse({ total: totalCount, notes: formattedNotes, rawResponse: env.DEBUG ? data : undefined }); } catch (error) { return handleApiError(error, "記事検索"); } }
- src/tools/search-tools.ts:20-25 (schema)Zod input schema defining parameters for the search-notes tool: query (required string), size, start (numbers with defaults), sort (enum with default).{ query: z.string().describe("検索キーワード"), size: z.number().default(10).describe("取得する件数(最大20)"), start: z.number().default(0).describe("検索結果の開始位置"), sort: z.enum(["new", "popular", "hot"]).default("hot").describe("ソート順(new: 新着順, popular: 人気順, hot: 急上昇)"), },
- src/tools/search-tools.ts:18-56 (registration)Direct registration of the 'search-notes' tool on the MCP server instance using server.tool(), including name, description, input schema, and handler function. This is within the registerSearchTools function."search-notes", "記事を検索する", { query: z.string().describe("検索キーワード"), size: z.number().default(10).describe("取得する件数(最大20)"), start: z.number().default(0).describe("検索結果の開始位置"), sort: z.enum(["new", "popular", "hot"]).default("hot").describe("ソート順(new: 新着順, popular: 人気順, hot: 急上昇)"), }, async ({ query, size, start, sort }) => { try { const data = await noteApiRequest(`/v3/searches?context=note&q=${encodeURIComponent(query)}&size=${size}&start=${start}&sort=${sort}`); if (env.DEBUG) { console.error(`API Response structure for search-notes: ${JSON.stringify(data, null, 2)}`); } if (!data || !data.data) { return createErrorResponse(`APIレスポンスが空です: ${JSON.stringify(data)}`); } if (data.status === "error" || data.error) { return createErrorResponse(`APIエラー: ${JSON.stringify(data)}`); } const notesArray = safeExtractData(data, commonExtractors.notes); const totalCount = safeExtractTotal(data, notesArray.length); const formattedNotes = notesArray.map(note => formatNote(note)); return createSuccessResponse({ total: totalCount, notes: formattedNotes, rawResponse: env.DEBUG ? data : undefined }); } catch (error) { return handleApiError(error, "記事検索"); } } );
- src/tools/index.ts:17-17 (registration)Top-level registration call for search tools (including search-notes) from the central registerAllTools function, invoked by main server scripts.registerSearchTools(server);