← Back to Pull requests

fix(mcp-kernel-server): write audit entries from deciding tools #4626

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 23, 2026 15:26 UTC
Author

Related Issue


None. Problem & Solution, Impact and Alternatives are completed below.

Problem & Solution


Problem: GetAuditLogTool.log_entry is the only writer to the audit log, but nothing in the server calls it, and _read_audit returns a hard-coded empty list. get_audit_log and audit://<agent>/log are therefore always empty, even after kernel_execute blocks an action.

Solution:

| File | What changed |
|------|-------------|
| src/mcp_kernel_server/tools.py | Add _record_audit. kernel_execute, verify_code_safety and iatp_verify record allowed/blocked; cmvk_verify, cmvk_review and reputation slashes record their own types. Entries hold identifiers, verdicts and sizes, never submitted code, claim text or the caller's slash reason (logged as reason_length). allowed_total counts only allowed entries. log_entry copies its argument. The type filter enum and tool description list the new entry types. |
| src/mcp_kernel_server/server.py | audit://<agent_id>/log reads the same in-memory log, filtered by agent_id. |
| tests/test_audit_writes.py | New: each deciding tool leaves a trace, no code, claim or slash-reason text is logged, queries write nothing, stats are correct, audit:// is per agent. |
| tests/test_integration.py | The end-to-end test relies on the server's own entry instead of calling log_entry by hand. |
| CHANGELOG.md | Unreleased > Fixed entry, including that allowed_total now counts allowed entries only. |

The reason fields kept on kernel_execute and iatp_verify entries are server-generated messages (policy and trust-check templates), not caller text.

Impact on Your Work


I maintain a Windows-focused fork of this repository and use the MCP kernel server's audit trail to check what an agent was allowed or blocked from doing. It was always empty, so there was no way to review decisions after the fact.

Timeline


None.

Alternatives Considered


Writing entries from a decorator or middleware around every tool. I chose explicit calls in the deciding tools so that each entry type carries only the fields that are safe to log (identifiers, verdicts, sizes), and query tools such as get_audit_log itself write nothing.

Type of Change


  • Bug fix (non-breaking change that fixes an issue)

  • New feature (non-breaking change that adds functionality)

  • Breaking change (fix or feature that would cause existing functionality to change)

  • Documentation update

  • Maintenance (dependency updates, CI/CD, refactoring)

  • Security fix
  • Package(s) Affected


    Core & runtime:
  • agent-os
  • Testing

    Unit Testing


    tests/test_audit_writes.py (new, 9 tests): each deciding tool records allowed/blocked or its own entry type; no submitted code, claim text or slash-reason text appears in any entry (test_reputation_slash_audit_records_reason_length_not_text uses a ~10 KB reason); query tools write nothing; allowed_total and the other stats are correct; audit:// returns only the requested agent's entries. tests/test_integration.py: the end-to-end test now relies on the server's own entry. The new and reworked tests fail against the unfixed source (9 failed).

    Manual Testing


    From agent-governance-python/agent-os/modules/mcp-kernel-server, in an isolated venv with pip install -e ".[dev]": python -m pytest tests -q gives 151 passed. ruff check on the changed files reports no new findings. cspell (as in spell-check.yml) reports nothing on the new lines; no-custom-crypto.sh, no-stubs.sh and check_no_public_preview.sh exit 0. TestCMVKReviewCodeTool::test_detects_eval_usage / test_detects_sql_injection fail intermittently on main too (3 of 25 runs), unrelated to this change.

    Checklist


  • I have linked a related issue above, or completed "Problem & Solution", "Impact on Your Work", and "Alternatives Considered"

  • My code follows the project style guidelines (ruff check)

  • I have added tests that prove my fix/feature works

  • All new and existing tests pass (pytest)

  • I have updated documentation as needed

  • I have signed the Microsoft CLA
  • Attribution & Prior Art


  • This contribution does not contain code copied or derived from other projects without attribution

  • Any external projects that inspired this design are credited in code comments or documentation

  • If this PR implements functionality similar to an existing open-source project, I have listed it below
  • Prior art / related projects (if any):

    AI Assistance


  • I can explain every meaningful change in this PR: what it does, why, and what tradeoffs were considered

  • I have run tests and verification appropriate for this change

  • No part of this PR was autonomously submitted by an AI agent without my review

  • I have not used AI to generate review comments on others' PRs
  • If AI tools materially shaped this change, briefly note what was used:
    Claude Code (Anthropic) found the empty audit log while auditing my fork, wrote the fix and tests, ran the verification above, and opened this PR at my request.

    IP, Patents, and Licensing


  • This contribution does not implement patent-pending or patent-encumbered techniques

  • This contribution does not require an NDA or licensing agreement to understand or use

  • Any AI tools used have terms compatible with the MIT License
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: MohammadHaroonAbuomar Review duration: 10517m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4626"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%