Mcp2grule
MCP Server for Grule.
Installation
npx mcp2gruleAsk AI about Mcp2grule
Powered by Claude Β· Grounded in docs
I know everything about Mcp2grule. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
mcp2grule
mcp2grule is a production-ready, high-performance Go server that exposes the Grule rule engine to Large Language Models (LLMs) and other AI applications via the Model Context Protocol (MCP).
Quick start
-
Clone and build:
git clone https://github.com/hungpdn/mcp2grule.git cd mcp2grule go mod tidy go build -o mcp2grule -
Run the server (defaults to stdio transport):
./mcp2grule server -
Or run with HTTP transport for easy testing (streamable-HTTP):
MCP_TRANSPORT=streamable-http DATABASE_TYPE=memory ./mcp2grule server
Configuration
All configuration is provided via environment variables (see internal/config/config.go). The minimal values you may set locally are in .env.example:
MCP_TRANSPORT=streamable-http
DATABASE_TYPE=memory
Key env vars
MCP_TRANSPORT:stdio,sse, orstreamable-http(default:stdio)DATABASE_TYPE:memory,sqlite, orpostgresql(default:memory)HTTP_HOST/HTTP_PORT: used for SSE / streamable-http transports
Project Structure
mcp2grule/
ββ cmd/ # CLI entrypoint (wires services and starts server)
ββ internal/
β ββ api/
β β ββ server.go # MCP transport selection (stdio / sse / streamable-http), tool registration, graceful shutdown
β β ββ tool.go # MCP tool registration (grule.evaluate, grule.create, ...)
β β ββ handler/ # MCP handlers that map requests to domain DTOs
β ββ grule/
β β ββ grule.go # Domain service: constructs grule engine, Evaluate/Create/Update/Delete logic
β ββ storage/
β β ββ storage.go # IRulesetStorage interface and common errors
β β ββ memory.go # In-memory ruleset storage (default for local dev)
β β ββ postgres.go # Postgres driver (optional; implements IRulesetStorage)
β ββ config/
β β ββ config.go # Environment variable parsing and typed config
β ββ pkg/
β ββ exitcode/ # Canonical exit codes for CLI/startup failures
β ββ logger/ # Logging helpers and context wiring
ββ ...
ββ README.md
MCP tools provided
The server registers these MCP tools (exact names used by clients):
grule.evaluate- Evaluate facts against a named rulesetgrule.create- Create a new rulesetgrule.update- Update an existing rulesetgrule.delete- Delete ruleset by namegrule.list- List all rulesetsgrule.detail- Get ruleset details by name
See internal/api/tool.go for the registration and internal/api/handler/mcp.go for request/response handling examples.
Linters & formatting
This repo uses golangci-lint. A starter config is present at .golangci.yml. Run:
golangci-lint run
Docker
A multi-stage Dockerfile is included. It builds a static binary and copies it into a minimal distroless runtime image. Example build:
docker build -t mcp2grule:latest .
docker run -e MCP_TRANSPORT=streamable-http -e DATABASE_TYPE=memory -p 9000:9000 mcp2grule:latest
Security note: builder images can contain OS-level CVEs. Consider scanning images in CI and using patched base images.
Testing
There are currently no unit tests in the repo. Recommended next steps:
- Add unit tests for
internal/storageandinternal/grule(happy path + error conditions). - Add a CI workflow to run
go test ./...andgolangci-lint runon PRs.
TODO
- Add tests.
- Add CI.
- Add pprofing.
- Add middleware for auth, metrics and logging.
- Add postgres storage.
- Add migration.
