Skip to content

Commit 866f5b7

Browse files
Merge pull request #5 from raythurman2386/docs/add-agents-guidelines
docs: add AI agent guidelines (AGENTS.md)
2 parents 24b7a89 + 14ec0bf commit 866f5b7

1 file changed

Lines changed: 92 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# AI Agent Guidelines for SysMetrics MCP
2+
3+
This document provides essential instructions for autonomous coding agents (like Copilot, Cursor, OpenCode, Gemini, etc.) operating within the **SysMetrics MCP** repository.
4+
5+
## 1. Project Overview
6+
- **Name**: SysMetrics MCP
7+
- **Type**: Model Context Protocol (MCP) Server for Linux system metrics.
8+
- **Language**: Go 1.25.6+
9+
- **Architecture**: `cmd/sysmetrics-mcp` (entrypoint), `internal/config` (CLI/config parsing), `internal/handlers` (core metrics logic).
10+
- **Key Libraries**: `github.com/mark3labs/mcp-go` (MCP Framework), `github.com/shirou/gopsutil/v3` (System Metrics).
11+
12+
## 2. Build, Lint, and Test Commands
13+
14+
We use a `Makefile` for standard development tasks. Always prefer these targets to ensure consistency.
15+
16+
### Common Commands
17+
- **Build**: `make build`
18+
- Compiles the project to `bin/sysmetrics-mcp` with `CGO_ENABLED=0`.
19+
- **Run Locally**: `go run . [flags]`
20+
- **Format Code**: `make fmt` (runs `go fmt ./...`)
21+
- **Lint Code**: `make lint` (runs `golangci-lint run` and `go vet ./...`)
22+
- **Update Dependencies**: `make deps` (runs `go mod download` and `go mod tidy`)
23+
24+
### Testing Commands
25+
Tests are critical. Always verify your changes before finalizing them.
26+
27+
- **Run all tests**:
28+
```bash
29+
make test
30+
# Under the hood: CGO_ENABLED=0 go test -v ./...
31+
```
32+
- **Run tests in a specific package**:
33+
```bash
34+
CGO_ENABLED=0 go test -v ./internal/handlers
35+
```
36+
- **Run a single test** (highly recommended for TDD/debugging):
37+
```bash
38+
CGO_ENABLED=0 go test -v -run ^TestFunctionName$ ./internal/handlers
39+
```
40+
- **Run tests with coverage**:
41+
```bash
42+
CGO_ENABLED=0 go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out
43+
```
44+
45+
## 3. Code Style & Architecture Guidelines
46+
47+
Adhere strictly to standard Go idioms and the existing patterns in this repository.
48+
49+
### Formatting & Imports
50+
- **Formatter**: Use standard `go fmt`. Run `make fmt` before committing.
51+
- **Imports**: Group imports into three distinct blocks separated by a blank line:
52+
1. Standard library packages.
53+
2. Third-party packages (e.g., `github.com/shirou/gopsutil/v3/...`).
54+
3. Internal project packages (`sysmetrics-mcp/internal/...`).
55+
- **Linter Strictness**: The project uses `golangci-lint` with strict rules (e.g., `revive`, `gosec`, `gocritic`). Your code *must* pass `make lint` cleanly without adding `#nosec` or `nolint` pragmas unless absolutely necessary and documented.
56+
57+
### Naming Conventions
58+
- **General**: Use `camelCase` for variables and `PascalCase` for exported identifiers.
59+
- **Acronyms**: Keep initialisms uppercase (e.g., `HTTPClient`, `UserID`, not `HttpClient` or `UserId`).
60+
- **Interfaces**: Interface names should typically end in `-er` (e.g., `MetricFetcher`, `ConfigParser`).
61+
- **Packages**: Package names should be short, lowercase, and avoid snake_case or hyphens. Do not use generic names like `util` or `common`.
62+
63+
### Error Handling (CRITICAL)
64+
- **Do not panic**: The server must run continuously. Never use `panic()` or `log.Fatal()` inside handlers or internal packages.
65+
- **MCP Errors**: Handlers must return structured error messages via `mcp.NewToolResultError` instead of crashing the server or returning raw Go errors to the MCP transport.
66+
- **Contextual Errors**: When returning errors internally, wrap them to provide context:
67+
```go
68+
return fmt.Errorf("failed to fetch disk metrics for %s: %w", mountPoint, err)
69+
```
70+
- **Graceful Degradation**: If a specific metric fails to load (e.g., Raspberry Pi GPU temp on a standard Linux machine), log a warning or return `N/A` instead of failing the entire tool request.
71+
72+
### Types and Data Structures
73+
- Favor strong typing. Avoid `interface{}` (or `any`) unless implementing generic data structures.
74+
- Use pointers for structs only when they need to be mutated or when passing large configurations. Otherwise, pass by value.
75+
- Prefer explicit struct initialization over positional arguments.
76+
77+
### Testing Conventions
78+
- **Table-Driven Tests**: Use table-driven tests for complex logic (refer to existing tests in `config_test.go`).
79+
- **Mocking**: Handlers are unit tested by mocking or calling them directly with a context (`handlers_test.go`). Focus on testing the business logic independently of the MCP transport layer.
80+
- **Asserts**: Use standard library `testing` package patterns. Avoid heavy third-party assertion libraries unless already present in the `go.mod`.
81+
82+
### Project-Specific Rules
83+
- **Platform Awareness**: The code detects Raspberry Pi hardware to provide additional metrics (GPU temp, throttling). Keep fallback paths clean for generic Linux environments.
84+
- **Tools Addition**: When adding a new MCP tool, ensure it is properly registered in `cmd/sysmetrics-mcp/main.go` and its handler is implemented in `internal/handlers` with appropriate error handling and JSON serialization.
85+
86+
## 4. Agent Interaction Protocol
87+
88+
When acting on user requests in this repository:
89+
1. **Understand Context**: Read `Makefile`, `.golangci.yml`, and `GEMINI.md` to understand constraints. Use `grep` and `glob` to locate relevant handler files before writing code.
90+
2. **Plan**: Write out a concise plan including the exact files to be modified and tests to be written.
91+
3. **Execute**: Modify the code using absolute file paths.
92+
4. **Self-Verify**: ALWAYS run `make fmt`, `make lint`, and the specific `go test -run ...` command for the code you touched. Do not finalize until these pass.

0 commit comments

Comments
 (0)