Event bus for Kavach security middleware lifecycle hooks
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kavach_mcp_events-0.0.3.tar.gz.
File metadata
- Download URL: kavach_mcp_events-0.0.3.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94fe304d930418a6a322769d4b2845415d8daf888b113e370ed399685b293ba9
|
|
| MD5 |
05c69f4266a83bc1c10b6b6d2410c4cc
|
|
| BLAKE2b-256 |
131ca9ff3f0edc0c8141e5466d42f27c07ce3d5727f4b69f6a5116271ec35a16
|
Provenance
The following attestation bundles were made for kavach_mcp_events-0.0.3.tar.gz:
Publisher:
upload_python_package.yml on shivamnamdeo0101/kavach-agent-ecosystem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kavach_mcp_events-0.0.3.tar.gz -
Subject digest:
94fe304d930418a6a322769d4b2845415d8daf888b113e370ed399685b293ba9 - Sigstore transparency entry: 1809121150
- Sigstore integration time:
-
Permalink:
shivamnamdeo0101/kavach-agent-ecosystem@2cb4114cdbd4907808bcd971a8287fd4538f8d90 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/shivamnamdeo0101
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
upload_python_package.yml@2cb4114cdbd4907808bcd971a8287fd4538f8d90 -
Trigger Event:
release
-
Statement type:
File details
Details for the file kavach_mcp_events-0.0.3-py3-none-any.whl.
File metadata
- Download URL: kavach_mcp_events-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e95e839750bed3f4194194de61917e7067857d417e161d316793c2d7567ef3ef
|
|
| MD5 |
e0fa7ba8b16bece4414414c41a2aebe8
|
|
| BLAKE2b-256 |
2f0730f57a987e1198df2113b7fa1a6fba2a7483930be618acb8f1cab8bb6002
|
Provenance
The following attestation bundles were made for kavach_mcp_events-0.0.3-py3-none-any.whl:
Publisher:
upload_python_package.yml on shivamnamdeo0101/kavach-agent-ecosystem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kavach_mcp_events-0.0.3-py3-none-any.whl -
Subject digest:
e95e839750bed3f4194194de61917e7067857d417e161d316793c2d7567ef3ef - Sigstore transparency entry: 1809121205
- Sigstore integration time:
-
Permalink:
shivamnamdeo0101/kavach-agent-ecosystem@2cb4114cdbd4907808bcd971a8287fd4538f8d90 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/shivamnamdeo0101
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
upload_python_package.yml@2cb4114cdbd4907808bcd971a8287fd4538f8d90 -
Trigger Event:
release
-
Statement type: