search-by-url
Find HackerNews posts that link to a specific URL. Use this tool to discover discussions and comments related to any webpage or online resource.
Instructions
Search for HackerNews posts that link to a specific URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| hitsPerPage | No | Number of results per page (default: 20) | |
| page | No | Page number for pagination (default: 0) | |
| url | Yes | The URL to search for |
Implementation Reference
- src/index.ts:423-437 (handler)Handler function for 'search-by-url' tool. It constructs a search query on the HackerNews Algolia API restricted to the 'url' attribute, fetches the results using the shared fetchHN helper, and returns formatted content.async ({ url, page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('query', url); params.append('restrictSearchableAttributes', 'url'); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; }
- src/index.ts:407-422 (schema)Schema definition for the 'search-by-url' tool, including input schema (url required, optional pagination) and output schema matching the HN API search response structure.{ title: 'Search Posts by URL', description: 'Search for HackerNews posts that link to a specific URL', inputSchema: { url: z.string().describe('The URL to search for'), page: z.number().optional().describe('Page number for pagination (default: 0)'), hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)') }, outputSchema: { hits: z.array(z.any()), nbHits: z.number(), nbPages: z.number(), page: z.number(), hitsPerPage: z.number() } },
- src/index.ts:405-438 (registration)Registration of the 'search-by-url' tool using server.registerTool, including name, schema, and inline handler function.server.registerTool( 'search-by-url', { title: 'Search Posts by URL', description: 'Search for HackerNews posts that link to a specific URL', inputSchema: { url: z.string().describe('The URL to search for'), page: z.number().optional().describe('Page number for pagination (default: 0)'), hitsPerPage: z.number().optional().describe('Number of results per page (default: 20)') }, outputSchema: { hits: z.array(z.any()), nbHits: z.number(), nbPages: z.number(), page: z.number(), hitsPerPage: z.number() } }, async ({ url, page, hitsPerPage }) => { const params = new URLSearchParams(); params.append('query', url); params.append('restrictSearchableAttributes', 'url'); if (page !== undefined) params.append('page', page.toString()); if (hitsPerPage !== undefined) params.append('hitsPerPage', hitsPerPage.toString()); const endpoint = `/search?${params.toString()}`; const result = await fetchHN(endpoint); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], structuredContent: result }; } );