Описание
JSON-RPC 2.0 implementation
README
A simple yet complete implementation of a JSON-RPC 2.0 real-time server using Node.js and Express, with a vanilla JavaScript frontend client.
📋 Project Overview
This project demonstrates a modern JSON-RPC 2.0 implementation with:
- Backend: Express.js server implementing JSON-RPC 2.0 specification
- Frontend: Vanilla HTML/CSS/JavaScript client (no frameworks)
- Protocol: JSON-RPC 2.0 (https://www.jsonrpc.org/specification)
Available Methods
The server provides three time-related RPC methods:
- getCurrentTime - Returns current server time in ISO 8601 format
- getTimeZone - Returns server timezone name and UTC offset
- getUnixTimestamp - Returns current Unix timestamp in seconds
🚀 Quick Start
Prerequisites
- Node.js (v12 or higher)
- npm
Installation
cd d:\PROJECTS\JSON-RPC-Protocol
npm install
Running the Server
npm start
The server will start on http://localhost:3000 with the following endpoints:
- RPC Endpoint:
POST http://localhost:3000/rpc - Health Check:
GET http://localhost:3000/health - Server Info:
GET http://localhost:3000/
Opening the Client
- Open
index.htmlin your web browser - Click any of the three buttons to send RPC requests
- View formatted JSON responses
📚 API Documentation
Base URL
http://localhost:3000/rpc
Request Format (JSON-RPC 2.0)
{
"jsonrpc": "2.0",
"method": "methodName",
"params": {},
"id": 1
}
Parameters:
jsonrpc(string, required): Must be exactly "2.0"method(string, required): Name of the method to callparams(object, optional): Method parameters (empty object if no params needed)id(number/string, required): Unique request identifier for matching responses
Response Format
Success Response
{
"jsonrpc": "2.0",
"result": { /* result data */ },
"id": 1
}
Error Response
{
"jsonrpc": "2.0",
"error": {
"code": -32601,
"message": "Method not found",
"data": "Additional error details"
},
"id": 1
}
Error Codes
| Code | Message | Description |
|---|---|---|
| -32700 | Parse error | Invalid JSON was received |
| -32600 | Invalid Request | Request structure is invalid |
| -32601 | Method not found | Called method doesn't exist |
| -32602 | Invalid params | Method parameters are invalid |
| -32603 | Internal error | Internal server error |
🔧 Available Methods
1. getCurrentTime
Returns the current server time in ISO 8601 format.
Request:
{
"jsonrpc": "2.0",
"method": "getCurrentTime",
"params": {},
"id": 1
}
Response:
{
"jsonrpc": "2.0",
"result": {
"timestamp": "2026-01-11T10:30:45.123Z"
},
"id": 1
}
2. getTimeZone
Returns the server's timezone information including name and UTC offset.
Request:
{
"jsonrpc": "2.0",
"method": "getTimeZone",
"params": {},
"id": 2
}
Response:
{
"jsonrpc": "2.0",
"result": {
"timezone": "America/New_York",
"offset": "-05:00"
},
"id": 2
}
3. getUnixTimestamp
Returns the current Unix timestamp in seconds.
Request:
{
"jsonrpc": "2.0",
"method": "getUnixTimestamp",
"params": {},
"id": 3
}
Response:
{
"jsonrpc": "2.0",
"result": {
"timestamp": 1736509845
},
"id": 3
}
💻 Using the Frontend Client
The index.html file provides a user-friendly web interface to interact with the server.
Features
- Three Action Buttons: Send requests to each of the three available methods
- Live Response Display: Pretty-printed JSON responses
- Loading State: Visual feedback while waiting for responses
- Error Handling: Clear error messages if requests fail
- Clear Response: Button to clear the response area
- Last Request Timestamp: Shows when the last request was made
- Responsive Design: Works on desktop and mobile devices
How to Use
- Start the server with
npm start - Open
index.htmlin your browser - Click "Get Current Time", "Get Time Zone", or "Get Unix Timestamp"
- View the formatted JSON response
- Use "Clear Response" to reset the display
🧪 Testing with cURL
Test getCurrentTime
curl -X POST http://localhost:3000/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"getCurrentTime","params":{},"id":1}'
Test getTimeZone
curl -X POST http://localhost:3000/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"getTimeZone","params":{},"id":2}'
Test getUnixTimestamp
curl -X POST http://localhost:3000/rpc \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"getUnixTimestamp","params":{},"id":3}'
Test Health Check
curl http://localhost:3000/health
Test Server Info
curl http://localhost:3000/
📁 Project Structure
JSON-RPC-Protocol/
├── server.js # Express server with JSON-RPC 2.0 implementation
├── index.html # Frontend client (HTML + CSS + JavaScript)
├── package.json # Project metadata and dependencies
├── package-lock.json # Dependency lock file
├── README.md # This file
├── .gitignore # Git ignore rules
├── .gitattributes # Git attributes
└── postman_collection.json # Postman API collection
🔐 CORS Support
The server includes CORS (Cross-Origin Resource Sharing) support, allowing the frontend client to communicate with the API from different origins. This is configured in server.js with the following headers:
Access-Control-Allow-Origin: *Access-Control-Allow-Methods: GET, POST, OPTIONSAccess-Control-Allow-Headers: Content-Type
🛠️ Development
Modifying the Server
To add new RPC methods:
- Create a new function (e.g.,
function getNewMethod() { ... }) - Add a case in the
routeMethod()function - Document the method with JSDoc comments
Example: Adding a New Method
function getNewMethod() {
return {
data: 'your data here'
};
}
// In routeMethod() switch statement:
case 'getNewMethod':
return getNewMethod();
📦 Dependencies
- express (^4.18.2) - Web framework for Node.js
📄 License
ISC
🤝 Contributing
Feel free to modify and extend this project for your needs. This is a great learning resource for understanding JSON-RPC 2.0 implementation.
📞 Support
For issues or questions:
- Check the README.md (this file)
- Review the code comments in server.js and index.html
- Test using the provided cURL examples or Postman collection
- Verify the server is running on http://localhost:3000
Created: January 11, 2026 Version: 1.0.0
Установка JSON RPC Protocol
У этого сервера нет опубликованного пакета — он собирается из исходников. Открой репозиторий и следуй инструкции в README.
▸ github.com/Sabari-Vasan-SM/JSON-RPC-ProtocolFAQ
JSON RPC Protocol MCP бесплатный?
Да, JSON RPC Protocol MCP бесплатный — установка в пару кликов через Unyly без оплаты.
Нужен ли API-ключ для JSON RPC Protocol?
Нет, JSON RPC Protocol работает без API-ключей и переменных окружения.
JSON RPC Protocol — hosted или self-hosted?
Self-hosted: сервер запускается локально на твоей машине командой из раздела установки.
Как установить JSON RPC Protocol в Claude Desktop, Claude Code или Cursor?
Открой JSON RPC Protocol на unyly.org, выбери вкладку своего клиента (Claude Desktop, Claude Code, Cursor) и нажми Install — конфиг сгенерируется автоматически, без правки JSON.
Похожие MCP
GitHub
PRs, issues, code search, CI status
автор: GitHubFilesystem
Secure file operations with configurable access controls.
Memory
Knowledge graph-based persistent memory system.
Template MCP Server
A CLI tool to create a new Model Context Protocol server project with TypeScript support, dual transport options, and an extensible structure
автор: mcpdotdirectCompare JSON RPC Protocol with
Не уверен что выбрать?
Найди свой стек за 60 секунд
Автор?
Embed-бейдж для README
Похожее
Все в категории development
