Skip to main content

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_call for every tool call.
  • post_tool_call after success.
  • security_check when inbound or outbound scanning finds violations.
  • tool_error when tool execution raises.

Manual audit_log events can be emitted from your application code.

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

kavach_mcp_events-0.0.3.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

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

kavach_mcp_events-0.0.3-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

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

Hashes for kavach_mcp_events-0.0.3.tar.gz
Algorithm Hash digest
SHA256 94fe304d930418a6a322769d4b2845415d8daf888b113e370ed399685b293ba9
MD5 05c69f4266a83bc1c10b6b6d2410c4cc
BLAKE2b-256 131ca9ff3f0edc0c8141e5466d42f27c07ce3d5727f4b69f6a5116271ec35a16

See more details on using hashes here.

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

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

File details

Details for the file kavach_mcp_events-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for kavach_mcp_events-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e95e839750bed3f4194194de61917e7067857d417e161d316793c2d7567ef3ef
MD5 e0fa7ba8b16bece4414414c41a2aebe8
BLAKE2b-256 2f0730f57a987e1198df2113b7fa1a6fba2a7483930be618acb8f1cab8bb6002

See more details on using hashes here.

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

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