Skip to main content

mcs-hooks

Tool-call lifecycle hooks decorator for the Model Context Standard (MCS).

HooksDecorator wraps a ToolDriver and emits observability events around execute_tool:

  • pre -- before execution: handler(tool_name, arguments)
  • post -- after success: handler(tool_name, arguments, result)
  • on_failure -- after an exception (then re-raised): handler(tool_name, arguments, exc)

Hooks are observers (return values ignored). To gate a call (confirm/deny) use mcs-permission; for auth challenges use mcs-auth. All three stack freely: Hooks(Permission(Auth(RealToolDriver))).

Installation

pip install mcs-hooks

Usage

from mcs.hooks.decorator import HooksDecorator

def audit(name, args):
    log.info("tool %s args=%s", name, args)

hooks = HooksDecorator(MyToolDriver(...), pre=[audit])
hooks.add_post_hook(lambda n, a, r: metrics.observe(n))   # multiple observers
orchestrator.add_driver(hooks, label="mail")

Multiple handlers per phase (observer pattern): pass lists at construction and/or add_*_hook / remove_*_hook at runtime. Advertises the "hooks" capability; reachable via DriverMeta.resolve_capability(driver, SupportsHooks).

License

Apache-2.0

Metadata

Release files for mcs-hooks 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcs-hooks 0.1.0
File Size Uploaded
mcs_hooks-0.1.0.tar.gz 8.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mcs-hooks 0.1.0
File Interpreter ABI Platform
mcs_hooks-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / mcs_hooks-0.1.0.tar.gz

Download URL mcs_hooks-0.1.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
cb032a42f0ca31b1f7163acef8bd9551fa88bc29fd0809855db06678d3aa379e
BLAKE2b-256 checksum
How to use checksums
654efc9574a890795a20b6c617e4283c0ad71ecab98926882d8303dfbb7d0827
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / mcs_hooks-0.1.0-py3-none-any.whl

Download URL mcs_hooks-0.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e4db134df3a2134cb5e8091e9877da30cddbc7d65f27200af3e6ae9ddc8f83f
BLAKE2b-256 checksum
How to use checksums
8555c245cf5524447cb05a3ad392c8e3751bb25d5846d6ec68502be115805e6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page