A lightweight MCP API JSON-RPC 2.0 server implemented in Python using the standard library with JWT authentication.
- Simple HTTP server implementation
- JSON-RPC 2.0 protocol support
- JWT token-based authentication
- Supports
get_time
,echo
, andpurchase_token
methods - No external dependencies (except PyJWT)
Clone this repository:
git clone https://github.com/yourusername/json-rpc-server.git
cd json-rpc-server
Install the required PyJWT package:
pip install pyjwt
Run the server with Python 3:
python3 simple_server.py
The server will start listening on 0.0.0.0:8080
.
Generates and returns a new JWT token that expires after 1 hour.
Example request:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "purchase_token", "id": 1}' http://localhost:8080
Returns the current time in GMT format. Requires a valid JWT token.
Example request:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "get_time", "token": "your-jwt-token", "id": 2}' http://localhost:8080
Alternatively, you can provide the token as the first parameter:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "get_time", "params": ["your-jwt-token"], "id": 2}' http://localhost:8080
Returns a greeting with the provided message. Requires a valid JWT token.
Example request with token in body:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "echo", "params": {"message": "Hello server!"}, "token": "your-jwt-token", "id": 3}' http://localhost:8080
Example request with token as first parameter:
curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "echo", "params": ["your-jwt-token", "Hello server!"], "id": 3}' http://localhost:8080
Response will be: "Dear User, Hello server!"
The server uses JWT tokens for authentication. To use protected methods:
- First obtain a token using the
purchase_token
method - Include the token either:
- In the request body as a
token
field - As the first item in the
params
array
- In the request body as a
Tokens expire after 1 hour.
simple_server.py
- The main server implementationInstructions for Simple HTTP Server.md
- Detailed instructions for running and testing the server