Kavach MCP Events
Zero-dependency async event bus for MCP lifecycle hooks.
Install
pip install kavach-mcp-events
For local development:
pip install -e .
Hooks
MCP_HOOKS defines the standard event names used by kavach-shield:
| Hook | Meaning |
|---|---|
PRE_TOOL_CALL |
Before a tool runs. |
POST_TOOL_CALL |
After a tool succeeds. |
SECURITY_CHECK |
A security rule matched. |
TOOL_ERROR |
Tool execution failed. |
AUDIT_LOG |
Manual audit event. |
Quick Use
from kavach_events import MCP_HOOKS, event_manager
@event_manager.subscribe([MCP_HOOKS.PRE_TOOL_CALL], tools=["*"])
async def before_any_tool(payload):
print(payload["tool_name"])
@event_manager.subscribe([MCP_HOOKS.SECURITY_CHECK], tools=["db_query"])
def on_db_security_event(payload):
print(payload.get("violations", []))
await event_manager.emit(
MCP_HOOKS.SECURITY_CHECK,
"db_query",
{"violations": [{"rule": "sql-injection"}]},
)
Sync callbacks are run in an executor. Async callbacks are awaited concurrently. Listener exceptions are isolated with asyncio.gather(..., return_exceptions=True).
Emit Forms
Explicit tool name:
await event_manager.emit("custom_event", "my_tool", {"value": 1})
Payload-only shorthand from inside a running event loop:
event_manager.emit("custom_event", {"value": 1})
If the payload is a dict, tool_name is added when missing.
Introspection
from kavach_events import MCP_HOOKS, event_manager
event_manager.has_listeners(MCP_HOOKS.SECURITY_CHECK, "db_query")
event_manager.get_registered_hooks()
event_manager.get_registered_hooks(MCP_HOOKS.PRE_TOOL_CALL)
With Kavach Shield
KavachMiddleware automatically emits:
pre_tool_callfor every tool call.post_tool_callafter success.security_checkwhen inbound or outbound scanning finds violations.tool_errorwhen tool execution raises.
Manual audit_log events can be emitted from your application code.
Metadata
Release files for kavach-mcp-events 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| kavach_mcp_events-0.0.3.tar.gz | 3.7 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kavach_mcp_events-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.9 kB
Release files / kavach_mcp_events-0.0.3.tar.gz
| Download URL | kavach_mcp_events-0.0.3.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
94fe304d930418a6a322769d4b2845415d8daf888b113e370ed399685b293ba9
|
|
BLAKE2b-256 checksum How to use checksums |
131ca9ff3f0edc0c8141e5466d42f27c07ce3d5727f4b69f6a5116271ec35a16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 13, 2026.
Transparency logRelease files / kavach_mcp_events-0.0.3-py3-none-any.whl
| Download URL | kavach_mcp_events-0.0.3-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e95e839750bed3f4194194de61917e7067857d417e161d316793c2d7567ef3ef
|
|
BLAKE2b-256 checksum How to use checksums |
2f0730f57a987e1198df2113b7fa1a6fba2a7483930be618acb8f1cab8bb6002
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 13, 2026.
Transparency logSecurity for kavach-mcp-events 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for kavach_mcp_events-0.0.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.