Skip to content

Commit 1d0dfd1

Browse files
feat: Implement the initial sysmetrics-mcp Go server including configuration, handlers, and project infrastructure.
0 parents  commit 1d0dfd1

15 files changed

Lines changed: 1411 additions & 0 deletions

File tree

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: [raythurman2386]

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main", "master" ]
6+
pull_request:
7+
branches: [ "main", "master" ]
8+
9+
jobs:
10+
build:
11+
name: Build and Test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v5
19+
with:
20+
go-version: '1.25.6'
21+
check-latest: true
22+
23+
- name: Format
24+
run: go fmt ./...
25+
26+
- name: Vet
27+
run: go vet ./...
28+
29+
- name: Lint
30+
uses: golangci/golangci-lint-action@v6
31+
with:
32+
version: latest
33+
install-mode: goinstall
34+
35+
- name: Test
36+
run: go test -v ./...

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Binaries for programs and plugins
2+
bin/
3+
*.exe
4+
*.exe~
5+
*.dll
6+
*.so
7+
*.dylib
8+
9+
# Test binary, built with `go test -c`
10+
*.test
11+
12+
# Output of the go coverage tool, specifically when used with LiteIDE
13+
*.out
14+
15+
# Dependency directories (remove the comment below to include it)
16+
# vendor/
17+
18+
# Go workspace file
19+
go.work
20+
21+
# IDEs
22+
.idea/
23+
.vscode/
24+
*.swp
25+
*.swo

.golangci.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
run:
2+
timeout: 5m
3+
go: '1.25'
4+
5+
linters:
6+
enable:
7+
- errcheck
8+
- gosimple
9+
- govet
10+
- ineffassign
11+
- staticcheck
12+
- unused
13+
- gocritic
14+
- revive
15+
- gosec
16+
- goconst
17+
- bodyclose
18+
- nilerr
19+
- noctx
20+
21+
linters-settings:
22+
revive:
23+
rules:
24+
- name: exported
25+
- name: package-comments
26+
- name: argument-limit
27+
arguments: [5]
28+
- name: function-result-limit
29+
arguments: [3]
30+
31+
issues:
32+
exclude-use-default: false
33+
max-issues-per-linter: 0
34+
max-same-issues: 0

GEMINI.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# SysMetrics MCP Server - Project Context
2+
3+
A lightweight [Model Context Protocol (MCP)](https://modelcontextprotocol.io) server written in Go that provides comprehensive Linux system metrics to AI models. It is optimized for both generic Linux distributions and Raspberry Pi systems.
4+
5+
## Project Overview
6+
7+
- **Core Functionality**: Exposes system metrics (CPU, Memory, Disk, Network, Processes, Thermal) as MCP tools.
8+
- **Main Technologies**:
9+
- **Language**: Go 1.25.6+
10+
- **MCP Framework**: `github.com/mark3labs/mcp-go`
11+
- **Metrics Library**: `github.com/shirou/gopsutil/v3`
12+
- **License**: MIT
13+
- **Architecture**:
14+
- `cmd/sysmetrics-mcp/main.go`: Entry point and server lifecycle management.
15+
- `internal/config/config.go`: CLI flag parsing and validation.
16+
- `internal/handlers/handlers.go`: Core logic for fetching system metrics.
17+
- `bin/sysmetrics-mcp`: The compiled binary (ignored by git).
18+
19+
## Building and Running
20+
21+
The project includes a `Makefile` for common development tasks.
22+
23+
### Key Commands
24+
25+
- **Build**: `make build` (Produces the `sysmetrics-mcp` binary)
26+
- **Test**: `make test` (Runs all unit tests with verbose output)
27+
- **Lint**: `make lint` (Runs `go vet` and checks code quality)
28+
- **Install**: `make install` (Builds and copies the binary to `/usr/local/bin`)
29+
- **Clean**: `make clean` (Removes compiled binaries and temporary files)
30+
- **Dependencies**: `make deps` (Downloads and tidies Go modules)
31+
32+
### Development Loop
33+
34+
To run the server locally during development (using stdio transport):
35+
```bash
36+
go run . [flags]
37+
```
38+
39+
## Configuration
40+
41+
The server is configured via CLI flags, which are handled in `config.go`.
42+
43+
| Flag | Default | Description |
44+
|------|---------|-------------|
45+
| `--temp-unit` | `celsius` | `celsius`, `fahrenheit`, or `kelvin` |
46+
| `--max-processes` | `10` | Limit for process list (1-50) |
47+
| `--mount-points` | `""` | Comma-separated list of mount points to monitor |
48+
| `--interfaces` | `""` | Comma-separated list of network interfaces to monitor |
49+
| `--enable-gpu` | `true` | Enable Raspberry Pi GPU metrics via `vcgencmd` |
50+
51+
## Development Conventions
52+
53+
- **Go Standards**: Adheres to standard Go idioms and project structure.
54+
- **Error Handling**: Handlers return structured error messages via `mcp.NewToolResultError` instead of crashing the server.
55+
- **Testing**:
56+
- Uses table-driven tests for logic (see `config_test.go`).
57+
- Handlers are unit tested by mocking/calling them directly with context (see `handlers_test.go`).
58+
- **Raspberry Pi Specialization**: The code detects Raspberry Pi hardware to provide additional metrics (GPU temp, throttling status) while falling back gracefully on generic Linux systems.
59+
- **Linting**: Pre-configured for `golangci-lint` (see `.golangci.yml`), including linters like `revive`, `gosec`, and `gocritic`.
60+
61+
## MCP Tools
62+
63+
The following tools are available to the AI:
64+
65+
1. `get_system_info`: Hostname, OS, kernel, uptime.
66+
2. `get_cpu_metrics`: Usage, per-core load, temperature.
67+
3. `get_memory_metrics`: Virtual memory and Swap usage.
68+
4. `get_disk_metrics`: Disk usage per mount point.
69+
5. `get_network_metrics`: Interface statistics and IP addresses.
70+
6. `get_process_list`: Top processes by CPU/Memory.
71+
7. `get_thermal_status`: Advanced thermal and throttling info (Pi-optimized).

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Raymond Thurman
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.PHONY: build clean install test
2+
3+
BINARY_NAME=sysmetrics-mcp
4+
INSTALL_PATH=/usr/local/bin
5+
6+
build:
7+
go build -o bin/$(BINARY_NAME) ./cmd/sysmetrics-mcp
8+
9+
clean:
10+
rm -f bin/$(BINARY_NAME)
11+
go clean
12+
13+
install: build
14+
sudo cp bin/$(BINARY_NAME) $(INSTALL_PATH)/
15+
sudo chmod +x $(INSTALL_PATH)/$(BINARY_NAME)
16+
17+
uninstall:
18+
sudo rm -f $(INSTALL_PATH)/$(BINARY_NAME)
19+
20+
test:
21+
go test -v ./...
22+
23+
lint:
24+
go vet ./...
25+
26+
deps:
27+
go mod download
28+
go mod tidy

README.md

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# SysMetrics MCP Server
2+
3+
A lightweight MCP (Model Context Protocol) server that exposes Linux system metrics through MCP tools. Works on any Linux system including Raspberry Pi.
4+
5+
## Features
6+
7+
- **7 MCP Tools**: System info, CPU, memory, disk, network, processes, and thermal status
8+
- **Configurable**: CLI arguments for temperature units, process limits, mount points, and interfaces
9+
- **Cross-Platform**: Works on any Linux system (enhanced metrics for Raspberry Pi)
10+
- **AI-Ready**: Designed for integration with Claude Desktop, Cursor, or any MCP client
11+
12+
## Installation
13+
14+
### Prerequisites
15+
16+
- Go 1.25.6 or higher
17+
- Linux system (tested on Ubuntu, Debian, Raspberry Pi OS)
18+
19+
### Build from Source
20+
21+
The project uses a `Makefile` for common tasks.
22+
23+
```bash
24+
git clone <repository>
25+
cd sysmetrics-mcp
26+
make build
27+
```
28+
29+
The compiled binary will be located in `bin/sysmetrics-mcp`.
30+
31+
### Install to PATH
32+
33+
```bash
34+
# Option 1: System-wide (installs to /usr/local/bin)
35+
sudo make install
36+
37+
# Option 2: User-local
38+
mkdir -p ~/.local/bin
39+
cp bin/sysmetrics-mcp ~/.local/bin/
40+
# Add to PATH if not already: export PATH="$HOME/.local/bin:$PATH"
41+
```
42+
43+
### Verify Installation
44+
45+
```bash
46+
sysmetrics-mcp --help
47+
```
48+
49+
## Configuration
50+
51+
### Local AI Agents (Gemini CLI / Personal Agents)
52+
53+
Add to your agent's configuration file:
54+
55+
```json
56+
{
57+
"sysmetrics": {
58+
"type": "stdio",
59+
"command": "sysmetrics-mcp",
60+
"args": [
61+
"--temp-unit", "celsius",
62+
"--max-processes", "10"
63+
]
64+
}
65+
}
66+
```
67+
68+
### Available CLI Flags
69+
70+
| Flag | Default | Description |
71+
|------|---------|-------------|
72+
| `--temp-unit` | `celsius` | Temperature unit: `celsius`, `fahrenheit`, or `kelvin` |
73+
| `--max-processes` | `10` | Default maximum processes to list (1-50) |
74+
| `--mount-points` | `""` | Comma-separated mount points (empty = all) |
75+
| `--interfaces` | `""` | Comma-separated interfaces (empty = all, excludes `lo`) |
76+
| `--enable-gpu` | `true` | Attempt to read GPU metrics (Raspberry Pi only) |
77+
78+
## MCP Tools
79+
80+
### `get_system_info`
81+
Returns system information including hostname, OS, uptime, and platform details.
82+
83+
### `get_cpu_metrics`
84+
Returns CPU usage, temperature, core count, and load average.
85+
86+
**Optional Arguments:**
87+
- `temp_unit`: Override temperature unit
88+
89+
### `get_memory_metrics`
90+
Returns RAM and swap usage statistics with both bytes and human-readable formats.
91+
92+
### `get_disk_metrics`
93+
Returns disk usage for all or specified mount points.
94+
95+
**Optional Arguments:**
96+
- `mount_points`: Comma-separated mount points to check
97+
- `human_readable`: Include human-readable sizes (default: true)
98+
99+
### `get_network_metrics`
100+
Returns network interface statistics including bytes sent/received and IP addresses.
101+
102+
**Optional Arguments:**
103+
- `interfaces`: Comma-separated interface names to check
104+
105+
### `get_process_list`
106+
Returns list of running processes sorted by resource usage.
107+
108+
**Optional Arguments:**
109+
- `limit`: Maximum number of processes (1-50)
110+
- `sort_by`: Sort by `cpu`, `memory`, or `pid` (default: `cpu`)
111+
112+
### `get_thermal_status`
113+
Returns thermal status including CPU/GPU temperatures and throttling information (Raspberry Pi).
114+
115+
**Optional Arguments:**
116+
- `temp_unit`: Override temperature unit
117+
118+
## Example Usage
119+
120+
Once configured, you can ask your AI assistant:
121+
122+
- "What's my CPU temperature?"
123+
- "Show me disk usage for / and /home"
124+
- "List the top 5 processes by memory usage"
125+
- "What's my network usage on eth0?"
126+
- "Check if my Raspberry Pi is throttling"
127+
128+
## Raspberry Pi Enhancements
129+
130+
On Raspberry Pi systems, the server provides additional metrics:
131+
132+
- **CPU Temperature**: Reads from `/sys/class/thermal/thermal_zone0/temp`
133+
- **GPU Temperature**: Uses `vcgencmd measure_temp`
134+
- **Throttling Status**: Uses `vcgencmd get_throttled` to detect:
135+
- Under-voltage conditions
136+
- Frequency capping
137+
- Thermal throttling
138+
- Soft temperature limits
139+
140+
On non-Pi systems, these metrics return `"not_available"` gracefully.
141+
142+
## Development
143+
144+
Use the included `Makefile` for development tasks:
145+
146+
```bash
147+
# Run tests
148+
make test
149+
150+
# Run linter (go vet)
151+
make lint
152+
153+
# Clean build artifacts
154+
make clean
155+
156+
# Download and tidy dependencies
157+
make deps
158+
```
159+
160+
## Requirements
161+
162+
- Go 1.25.6+
163+
- Linux system
164+
- For Pi features: Raspberry Pi OS with `vcgencmd` available
165+
166+
## License
167+
168+
MIT

0 commit comments

Comments
 (0)