mcp-news-server
The MCP News Server is a wrapper around the Hacker News API, showcasing the implementation of the Modular Contract Protocol (MCP). It is designed to convert traditional REST APIs into MCP-compliant servers, facilitating easy discovery and interaction by tools such as LLM agents.
š° MCP News Server
A clean, minimal MCP wrapper around the Hacker News API ā built to showcase the Modular Contract Protocol (MCP) structure, typed contracts, and LLM-compatible interface.
š Live Demo
š¢ Deployed at: https://mcp-news-server.onrender.com
Try It Now
š What is This?
This project demonstrates how to transform an existing REST API into an MCP-compliant server. It wraps the Hacker News API using modular components:
- Contracts defined with
zod
andzod-openapi
for typed and documented inputs/outputs - Resolvers for business logic
- Handlers for HTTP routing
- OpenAPI integration for LLM function calling
My goal with this wrapper is to learn and demonstrate the full MCP process, and prepare APIs for the MCP marketplace ā where tools and agents can discover and use them programmatically.
š” Why Use MCP Instead of Raw REST Calls?
Traditional REST APIs:
- ā No contracts
- ā Inconsistent formats
- ā Not LLM friendly
MCP APIs:
- ā Contract-driven (with Zod)
- ā Composable and self-descriptive
- ā LLM-ready (via OpenAPI and function schemas)
š§ Tech Stack
- Node.js + Express
- TypeScript
- Zod +
zod-openapi
- Axios
- Deployed on Render
š Project Structure
src/
āāā contracts/ # Zod + OpenAPI metadata
āāā resolvers/ # Business logic
āāā handlers/ # Express routes
āāā utils/ # Hacker News client
āāā docs/openapi.ts # OpenAPI spec generator (zod-openapi)
āāā setup/zod-openapi-init.ts # Shared zod setup with OpenAPI support
āāā server.ts # Main entry point
šļø Endpoints
1. GET /api/listTopStories
Returns a list of top Hacker News story IDs.
Example:
curl https://mcp-news-server.onrender.com/api/listTopStories
Response:
[38643, 38642, 38641]
2. GET /api/getStory/:id
Returns full story data for a given story ID.
Example:
curl https://mcp-news-server.onrender.com/api/getStory/8863
Response:
{
"id": 8863,
"title": "My YC app: Dropbox - Throw away your USB drive",
"url": "http://www.getdropbox.com/u/2/screencast.html",
"score": 111,
"by": "dhouston",
"time": 1175714200,
"type": "story"
}
š§ How LLMs Can Use This
Each MCP endpoint is:
- Strictly typed
- Schema-bound with Zod
- Self-documenting via OpenAPI
This makes it ideal for:
- LLM agents (OpenAI, Claude)
- LangChain tools
- ai-agent-flow pipelines
š¤ Function Calling Example (OpenAI / Claude)
{
"name": "getStory",
"description": "Retrieve story details by ID from Hacker News",
"parameters": {
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "The numeric ID of the Hacker News story"
}
},
"required": ["id"]
}
}
ā”ļø Point to:
GET https://mcp-news-server.onrender.com/api/getStory/:id
š OpenAPI Schema
curl https://mcp-news-server.onrender.com/openapi.json
This endpoint can be used in:
- Swagger UI
- API clients (Postman, Insomnia)
- LLM frameworks for function discovery
š ļø Local Setup
git clone https://github.com/rajeshdh/mcp-news-server
cd mcp-news-server
npm install
npm run dev
⨠What You Can Build with This
- A summarizer tool for top HN stories
- A GPT agent that fetches and ranks HN stories
- A fact-checking or news validation agent
- Your own open MCP marketplace entry!
š License
MIT