A Model Context Protocol (MCP) server implementation in Rust for managing a virtual lightbulb. This server provides tools to control and monitor a simulated lightbulb, with all actions logged to a file.
- Get Status: Check if the lightbulb is currently on or off
- Turn On: Turn the lightbulb on (with logging)
- Turn Off: Turn the lightbulb off (with logging)
- Event Logging: All state changes are logged to
lightbulb.log
with timestamps
- Description: Get the current status of the lightbulb
- Parameters: None
- Returns: String indicating whether the lightbulb is on or off
- Description: Turn on the lightbulb
- Parameters: None
- Returns: Success message or error if already on
- Side Effect: Logs the action to
lightbulb.log
- Description: Turn off the lightbulb
- Parameters: None
- Returns: Success message or error if already off
- Side Effect: Logs the action to
lightbulb.log
- Rust (latest stable version)
- Cargo
cargo build
cargo run
The server logs all lightbulb actions to lightbulb.log
in the following format:
[2025-08-02T14:24:27.652821025+00:00] Lightbulb turned ON
[2025-08-02T15:48:03.599625808+00:00] Lightbulb turned OFF
- Built using the
rmcp
crate for MCP protocol implementation - Uses
Arc<Mutex<bool>>
for thread-safe state management - Implements async tool handlers
- Uses
chrono
for RFC3339 timestamp formatting - File I/O for persistent logging
rmcp
- MCP protocol implementationtokio
- Async runtimechrono
- Date/time handlingserde
&serde_json
- Serialization
You can test the server manually by sending JSON-RPC requests via stdin:
{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {}}
{"jsonrpc": "2.0", "id": 2, "method": "tools/list"}
{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "turn_on_lightbulb"}}