Search stories
search_storiesSearch Hacker News stories by keyword to find relevant technology discussions and news articles.
Instructions
Search Hacker News stories by keyword.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| limit | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| stories | Yes | ||
| returned | Yes |
Implementation Reference
- servers/hackernews/src/index.ts:339-346 (handler)The handler implementation for the `search_stories` tool in the Hacker News MCP server. It calls the `client.searchStories` method and returns the formatted stories and the count.
handler: async ({ query, limit }, context) => { await context.log("info", `Searching Hacker News for ${query}`); const stories = await this.client.searchStories({ query, limit }); return { stories: [...stories], returned: stories.length, }; }, - servers/hackernews/src/index.ts:326-354 (registration)Tool registration for `search_stories` within the Hacker News Server constructor.
this.registerTool( defineTool({ name: "search_stories", title: "Search stories", description: "Search Hacker News stories by keyword.", inputSchema: { query: z.string().trim().min(1), limit: z.number().int().min(1).max(30).default(10), }, outputSchema: { stories: z.array(storySummarySchema), returned: z.number().int(), }, handler: async ({ query, limit }, context) => { await context.log("info", `Searching Hacker News for ${query}`); const stories = await this.client.searchStories({ query, limit }); return { stories: [...stories], returned: stories.length, }; }, renderText: ({ stories, returned }) => { if (returned === 0) { return "No matching Hacker News stories found."; } return stories.map((story) => `${story.title} by ${story.author ?? "unknown"}`).join("\n"); }, }), );