Skip to content

feat: tag MCP health check requests with BifrostContextKeyMCPHealthCheckRequest context marker - #4207

Merged
Pratham-Mishra04 merged 1 commit into
devfrom
06-09-feat_adds_healthcheck_info_in_ctx_for_mcp_pings
Jun 9, 2026
Merged

feat: tag MCP health check requests with BifrostContextKeyMCPHealthCheckRequest context marker#4207
Pratham-Mishra04 merged 1 commit into
devfrom
06-09-feat_adds_healthcheck_info_in_ctx_for_mcp_pings

Conversation

@Pratham-Mishra04

@Pratham-Mishra04 Pratham-Mishra04 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Introduces a new context key, BifrostContextKeyMCPHealthCheckRequest, that marks MCP ping and list_tools requests as internally generated by Bifrost's health monitor. This allows plugins, hooks, and other middleware to distinguish these internal probes from caller-initiated requests.

Changes

  • Added BifrostContextKeyMCPHealthCheckRequest context key ("bifrost-mcp-health-check-request") to the set of reserved Bifrost context keys.
  • In performHealthCheck, the timeout context is now wrapped in a BifrostContext with the new key set to true before being passed to runPingWithHooks / runListToolsWithHooks, ensuring the marker propagates through the entire health check call chain.
  • The key is reserved (added to reservedKeys) so it cannot be overridden externally — the comment explicitly notes it should not be set manually.

Type of change

  • Bug fix
  • Feature
  • Refactor
  • Documentation
  • Chore/CI

Affected areas

  • Core (Go)
  • Transports (HTTP)
  • Providers/Integrations
  • Plugins
  • UI (React)
  • Docs

How to test

Write a plugin or hook that inspects the incoming context for BifrostContextKeyMCPHealthCheckRequest. Trigger a health check cycle and verify the key is present and set to true for ping/list_tools probes, while being absent for normal caller-initiated requests.

go test ./...

Breaking changes

  • Yes
  • No

Security considerations

The new context key is reserved and explicitly documented as not to be set manually, preventing external callers from spoofing health check requests to bypass plugin logic that gates on this marker.

Checklist

  • I read docs/contributing/README.md and followed the guidelines
  • I added/updated tests where appropriate
  • I updated documentation where needed
  • I verified builds succeed (Go and UI)
  • I verified the CI pipeline passes locally if applicable

Summary by CodeRabbit

  • Refactor
    • Improved internal health monitoring to distinguish health check requests from normal operations, enhancing system reliability through better request tracking and handling.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5c9e10bf-dcbc-4157-a72f-eb94dbe34826

📥 Commits

Reviewing files that changed from the base of the PR and between 37020bf and 1ab318f.

📒 Files selected for processing (3)
  • core/mcp/healthmonitor.go
  • core/schemas/bifrost.go
  • core/schemas/context.go

📝 Walkthrough

Walkthrough

This PR adds a context flag to distinguish internal MCP health-check requests from regular caller-initiated requests. The constant is defined, protected as a reserved key to prevent caller overwrites, and applied when performing health checks to propagate the indicator through hooks.

Changes

Health-check request context flag

Layer / File(s) Summary
Health-check request flag definition and use
core/schemas/bifrost.go, core/schemas/context.go, core/mcp/healthmonitor.go
BifrostContextKeyMCPHealthCheckRequest constant is defined and added to reservedKeys for protection. The flag is set to true on the bifrost context during performHealthCheck so downstream plugins and hooks can distinguish health-check pings and list-tools probes from caller-initiated requests.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Suggested reviewers

  • danpiths
  • roroghost17
  • akshaydeo

Poem

🐰 A flag for the health, a mark in the way,
So hooks know which pings are just checks for the day,
Reserved and protected, no overwrite fears,
Internal probes whisper through bifrost frontiers! 🌲

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 06-09-feat_adds_healthcheck_info_in_ctx_for_mcp_pings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands and usage tips.

Pratham-Mishra04 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge — the change is purely additive plumbing with no mutations to existing request paths or plugin ordering.

The BifrostContext wrapper is created correctly: the timeout deadline propagates via parent lookup, the watchCancellation goroutine exits promptly when defer cancel() fires, and the marker is visible to plugin hooks through the standard parent-delegation chain inside gateCtx.Value(). The reservedKeys addition follows the established pattern. No existing call sites are altered beyond the context construction in performHealthCheck.

No files require special attention.

Important Files Changed

Filename Overview
core/mcp/healthmonitor.go Wraps the timeout context in a BifrostContext and stamps BifrostContextKeyMCPHealthCheckRequest=true before calling runPingWithHooks/runListToolsWithHooks; value propagates via parent lookup in derived gateCtx objects. Cancel chain is correct.
core/schemas/bifrost.go Adds BifrostContextKeyMCPHealthCheckRequest constant with a clear doc comment and DO NOT SET MANUALLY annotation, consistent with BifrostContextKeyMCPLogID and similar internal keys.
core/schemas/context.go Adds BifrostContextKeyMCPHealthCheckRequest to reservedKeys, preventing plugins from overwriting it once blockRestrictedWrites is active.

Reviews (3): Last reviewed commit: "feat: adds healthcheck info in ctx for m..." | Re-trigger Greptile

@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-09-feat_adds_healthcheck_info_in_ctx_for_mcp_pings branch from 560574c to b8e13bb Compare June 9, 2026 11:15
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-09-docs_semantic_cache_docs_revamp branch from 1b7031f to 21740c1 Compare June 9, 2026 11:15

Pratham-Mishra04 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

Merge activity

  • Jun 9, 12:11 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Jun 9, 12:13 PM UTC: Graphite rebased this pull request as part of a merge.
  • Jun 9, 12:13 PM UTC: @Pratham-Mishra04 merged this pull request with Graphite.

@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from 06-09-docs_semantic_cache_docs_revamp to graphite-base/4207 June 9, 2026 12:12
@Pratham-Mishra04
Pratham-Mishra04 changed the base branch from graphite-base/4207 to dev June 9, 2026 12:12
@Pratham-Mishra04
Pratham-Mishra04 force-pushed the 06-09-feat_adds_healthcheck_info_in_ctx_for_mcp_pings branch from b8e13bb to 1ab318f Compare June 9, 2026 12:12
@Pratham-Mishra04
Pratham-Mishra04 merged commit f19dd63 into dev Jun 9, 2026
12 of 15 checks passed
@Pratham-Mishra04
Pratham-Mishra04 deleted the 06-09-feat_adds_healthcheck_info_in_ctx_for_mcp_pings branch June 9, 2026 12:13
akshaydeo pushed a commit that referenced this pull request Jun 12, 2026
…heckRequest` context marker (#4207)

## Summary

Introduces a new context key, `BifrostContextKeyMCPHealthCheckRequest`, that marks MCP ping and `list_tools` requests as internally generated by Bifrost's health monitor. This allows plugins, hooks, and other middleware to distinguish these internal probes from caller-initiated requests.

## Changes

- Added `BifrostContextKeyMCPHealthCheckRequest` context key (`"bifrost-mcp-health-check-request"`) to the set of reserved Bifrost context keys.
- In `performHealthCheck`, the timeout context is now wrapped in a `BifrostContext` with the new key set to `true` before being passed to `runPingWithHooks` / `runListToolsWithHooks`, ensuring the marker propagates through the entire health check call chain.
- The key is reserved (added to `reservedKeys`) so it cannot be overridden externally — the comment explicitly notes it should not be set manually.

## Type of change

- [ ] Bug fix
- [x] Feature
- [ ] Refactor
- [ ] Documentation
- [ ] Chore/CI

## Affected areas

- [x] Core (Go)
- [ ] Transports (HTTP)
- [ ] Providers/Integrations
- [x] Plugins
- [ ] UI (React)
- [ ] Docs

## How to test

Write a plugin or hook that inspects the incoming context for `BifrostContextKeyMCPHealthCheckRequest`. Trigger a health check cycle and verify the key is present and set to `true` for ping/list_tools probes, while being absent for normal caller-initiated requests.

```sh
go test ./...
```

## Breaking changes

- [ ] Yes
- [x] No

## Security considerations

The new context key is reserved and explicitly documented as not to be set manually, preventing external callers from spoofing health check requests to bypass plugin logic that gates on this marker.

## Checklist

- [ ] I read `docs/contributing/README.md` and followed the guidelines
- [ ] I added/updated tests where appropriate
- [ ] I updated documentation where needed
- [ ] I verified builds succeed (Go and UI)
- [ ] I verified the CI pipeline passes locally if applicable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants