Skip to main content

Shared utilities for token-efficient MCP servers — RBAC, audit logging, lean response shaping, TLS config

Project description

node804-mcp-toolkit

CI PyPI Python License: MIT

Shared utilities for building token-efficient, security-conscious MCP servers for IT operations. Provides the cross-cutting concerns every ops MCP needs — permission gating, audit logging, response shaping, TLS config — so each server in a suite implements them the same way.

Installation

pip install node804-mcp-toolkit

What's in here

Module Purpose
rbac Hierarchical permission modes (read / standard / full / admin); a gate decorator that only registers tools with the MCP server when the active mode qualifies — ungated tools are invisible to the AI client, not just blocked
audit JSON-lines audit logging of every tool call with timing, success/error state, sensitive-key redaction, and long-value truncation
lean Pure response-shaping helpers: field whitelisting, internal-key stripping, pagination, server-side pattern filtering
tls Verify-by-default TLS config from env vars, with custom CA bundle support for internal PKI
params Shared Pydantic parameter types (VerboseFlag, FieldsList, Pagination, Pattern) so every tool uses the same names, defaults, and descriptions

Quick start

Gate tools by permission mode, with audit logging composed in:

from mcp.server.fastmcp import FastMCP
from node804_mcp_toolkit import Mode, ModeGate, open_sink

mcp = FastMCP("panos-mcp")

# Audit sink: writes JSONL when PANOS_AUDIT_LOG is set, no-op otherwise.
sink = open_sink(env_var="PANOS_AUDIT_LOG")

# Mode comes from env. Missing or invalid values fail safe to read-only.
gate = ModeGate.from_env(env_var="PANOS_MODE", audit_sink=sink)

@gate.tool(mcp, required=Mode.READ)
async def get_security_rules(...): ...

@gate.tool(mcp, required=Mode.ADMIN)
async def commit(...): ...  # not registered at all unless PANOS_MODE=admin

Shape responses for token efficiency:

from node804_mcp_toolkit import filter_by_pattern, paginate, strip_keys, whitelist

rules = strip_keys(raw_rules, ["@uuid", "@loc"])          # drop SDK internals
rules = filter_by_pattern(rules, pattern, name_field="name")
rules = paginate(rules, limit=100, offset=0)
rules = whitelist(rules, ["name", "action", "source", "destination"])

Resolve TLS settings from environment (verify-by-default):

from node804_mcp_toolkit import resolve_tls_config
import httpx, os

tls = resolve_tls_config(dict(os.environ), prefix="PRTG")
# PRTG_TLS_VERIFY=false  → verify off, with a loud stderr warning
# PRTG_TLS_CA=/path.pem  → custom CA bundle for internal PKI
client = httpx.Client(verify=str(tls.ca_path) if tls.ca_bundle else tls.verify)

Design philosophy

  • One toolkit, one set of patterns. A user who learns the parameter conventions in any one MCP — verbose, fields, limit, offset, pattern — gets the same conventions in all of them.
  • Default deny. Unset or misconfigured mode env vars fall back to read-only. Tools above the active mode are never registered, so the AI client can't even see them.
  • Token-lean by default. Responses expose the fields the AI actually reasons over; verbose=true opts into the full payload.
  • Best-effort observability. Audit logging never breaks a tool call — sink failures warn once to stderr and move on.

Used by

Development

pip install -e ".[dev]"
pytest
ruff check .
mypy src

Requires Python 3.11+. Fully typed (py.typed included), mypy --strict clean.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

node804_mcp_toolkit-0.1.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

node804_mcp_toolkit-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file node804_mcp_toolkit-0.1.0.tar.gz.

File metadata

  • Download URL: node804_mcp_toolkit-0.1.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for node804_mcp_toolkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 250b26bb6a434ea906641c9a17cecc84c804a6237fd151c2f3effecfab7a7e44
MD5 78155dc042589c0eea27f0789fd0fc1a
BLAKE2b-256 bcb45def9338b8978a403ed68decce10ad0387905287f969238b438adf20b92c

See more details on using hashes here.

Provenance

The following attestation bundles were made for node804_mcp_toolkit-0.1.0.tar.gz:

Publisher: publish.yml on Node804/node804-mcp-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file node804_mcp_toolkit-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for node804_mcp_toolkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ac47ea1e4a3b43b130dec6834bb7dc6d79563500a7ae2c2448d01b5ec73b4de
MD5 d4382fe38f3f8050902b9f6301907f23
BLAKE2b-256 8307ceb3648b9798bff9ddcac50a7b6f1a8600de56273a802f4aa8286beae6fd

See more details on using hashes here.

Provenance

The following attestation bundles were made for node804_mcp_toolkit-0.1.0-py3-none-any.whl:

Publisher: publish.yml on Node804/node804-mcp-toolkit

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page