Skip to main content
Glama

MCP Hacker News

by paabloLC

getJobStories

Fetch and retrieve job postings from Hacker News with customizable limits, enabling quick access to relevant career opportunities using the MCP Hacker News server.

Instructions

Get job postings from Hacker News

Input Schema

NameRequiredDescriptionDefault
limitNoNumber of jobs to return (default: 10, max: 30)

Input Schema (JSON Schema)

{ "properties": { "limit": { "default": 10, "description": "Number of jobs to return (default: 10, max: 30)", "type": "number" } }, "type": "object" }

Implementation Reference

  • Handler function that fetches job story IDs from the Hacker News API endpoint '/jobstories', limits and fetches the item details using helper functions, formats the data, and returns a JSON response with the job postings.
    execute: async (args: any) => { const limit = Math.min(args.limit || 10, 30); const jobIds = await fetchFromAPI<number[]>("/jobstories"); if (!jobIds) { return { content: [ { type: "text", text: JSON.stringify({ error: "Failed to fetch job stories" }), }, ], }; } const jobs = await fetchMultipleItems(jobIds, limit); const formattedJobs = jobs.map((job) => ({ id: job.id, title: job.title, url: job.url, score: job.score, author: job.by, time: job.time ? formatTime(job.time) : "unknown", hnUrl: `https://news.ycombinator.com/item?id=${job.id}`, text: job.text, })); return { content: [ { type: "text", text: JSON.stringify( { message: `Latest ${limit} job postings`, jobs: formattedJobs, }, null, 2 ), }, ], }; },
  • Input schema for the getJobStories tool, defining an optional 'limit' parameter for the number of job stories to retrieve.
    inputSchema: { type: "object", properties: { limit: { type: "number", description: "Number of jobs to return (default: 10, max: 30)", default: 10, }, }, },
  • Helper function used to fetch multiple Hacker News items by their IDs in parallel, filtering out deleted or dead items.
    export async function fetchMultipleItems( ids: number[], maxItems = 30 ): Promise<HackerNewsItem[]> { const limitedIds = ids.slice(0, maxItems); const promises = limitedIds.map((id) => fetchFromAPI<HackerNewsItem>(`/item/${id}`) ); const results = await Promise.all(promises); return results.filter( (item): item is HackerNewsItem => item !== null && !item.deleted && !item.dead ); }
  • Core helper function to fetch data from Hacker News Firebase API with caching support.
    export async function fetchFromAPI<T>(endpoint: string): Promise<T | null> { const cacheKey = endpoint; const cached = getCached<T>(cacheKey); if (cached) return cached; try { const response = await fetch( `https://hacker-news.firebaseio.com/v0${endpoint}.json` ); if (!response.ok) throw new Error(`HTTP ${response.status}`); const data = await response.json(); setCache(cacheKey, data); return data; } catch (error) { console.error(`Error fetching ${endpoint}:`, error); return null; } }
  • Helper function to format Unix timestamps into human-readable relative time strings (e.g., '2h ago').
    export function formatTime(timestamp: number): string { const date = new Date(timestamp * 1000); const now = new Date(); const diff = now.getTime() - date.getTime(); const minutes = Math.floor(diff / (1000 * 60)); const hours = Math.floor(diff / (1000 * 60 * 60)); const days = Math.floor(diff / (1000 * 60 * 60 * 24)); if (minutes < 60) return `${minutes}m ago`; if (hours < 24) return `${hours}h ago`; return `${days}d ago`; }

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/paabloLC/mcp-hacker-news'

If you have feedback or need assistance with the MCP directory API, please join our Discord server