Skip to main content

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

Project description

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

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

mcs_hooks-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

mcs_hooks-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcs_hooks-0.1.0.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mcs_hooks-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb032a42f0ca31b1f7163acef8bd9551fa88bc29fd0809855db06678d3aa379e
MD5 4c9215960d7f8677992fdb9cd25c1176
BLAKE2b-256 654efc9574a890795a20b6c617e4283c0ad71ecab98926882d8303dfbb7d0827

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcs_hooks-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for mcs_hooks-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e4db134df3a2134cb5e8091e9877da30cddbc7d65f27200af3e6ae9ddc8f83f
MD5 e6872cf205d4b125b76d53777ef83792
BLAKE2b-256 8555c245cf5524447cb05a3ad392c8e3751bb25d5846d6ec68502be115805e6d

See more details on using hashes here.

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