Skip to content

refactor(resource): ensure post-fetch hooks receive resolved gateway content#2655

Merged
crivetimihai merged 1 commit intomainfrom
issue-2648_post_fetch_plugin_resource_invoke
Feb 7, 2026
Merged

refactor(resource): ensure post-fetch hooks receive resolved gateway content#2655
crivetimihai merged 1 commit intomainfrom
issue-2648_post_fetch_plugin_resource_invoke

Conversation

@TS0713
Copy link
Copy Markdown
Collaborator

@TS0713 TS0713 commented Feb 2, 2026

Summary

Fixes Issue 2648 by invoking resources before running post-fetch hooks.

Changes

  1. Execute RESOURCE_POST_FETCH hooks after gateway invocation
  2. Refactor read_resource to resolve content first
  3. Add explicit DB commit before network calls
  4. Added test case under - mcp-context-forge/tests/unit/plugins/test_secrets_detection.py
    • to verify resolved content.text is passed to post-fetch hook

@TS0713 TS0713 force-pushed the issue-2648_post_fetch_plugin_resource_invoke branch from d78dfd9 to 5eb1aa2 Compare February 3, 2026 09:05
@TS0713 TS0713 marked this pull request as ready for review February 3, 2026 12:34
@crivetimihai
Copy link
Copy Markdown
Member

Good fix, @TS0713 — post-fetch hooks should definitely receive resolved content, not template URIs. The refactored control flow with a single return path and null checks on invoke_resource is also an improvement.

Two things to address:

1. Removed db.commit() — potential performance regression:
The original code had an explicit db.commit() with the comment "Release transaction before network calls to avoid idle-in-transaction during invoke_resource". Removing it means the DB transaction stays open during potentially slow gateway calls. On PostgreSQL under load, this can cause connection pool exhaustion. Can you confirm this is safe, or re-add the commit before the gateway calls?

2. Unrelated files from incorrect rebase:
12 files under plugins/unified_pdp/ and tests/unit/plugins/ only add # -*- coding: utf-8 -*- headers — these likely came from an incorrect rebase picking up changes from another branch. Please rebase cleanly against main and remove them:

git checkout origin/main -- plugins/unified_pdp/ tests/unit/plugins/test_unified_pdp.py tests/unit/plugins/test_unified_pdp_plugin.py
git commit -s -m "chore: remove unrelated files from rebase"

@TS0713
Copy link
Copy Markdown
Collaborator Author

TS0713 commented Feb 4, 2026

. Removed db.commit() — potential performance regression:
The original code had an explicit db.commit() with the comment "Release transaction before network calls to avoid idle-in-transaction during invoke_resource". Removing it means the DB transaction stays open during potentially slow gateway calls. On PostgreSQL under load, this can cause connection pool exhaustion. Can you confirm this is safe, or re-add the commit before the gateway calls?

Thanks for flagging this — read_resource was holding the DB transaction until invoke_resource. I’ll add an explicit commit immediately before gateway invocation so connections aren’t held across plugin or network calls, then rebase, re-test, and update the PR.

@crivetimihai crivetimihai self-assigned this Feb 4, 2026
@crivetimihai crivetimihai added this to the Release 1.0.0-RC1 milestone Feb 7, 2026
…content

Move RESOURCE_POST_FETCH hook invocation to after invoke_resource()
resolves content from the gateway. Previously, post-fetch plugins
(e.g. secrets_detection) received raw template URIs instead of actual
content, allowing secrets to pass through unredacted.

Also adds null-checks before setting blob/text from invoke_resource()
response, and normalizes the content resolution into a single
if/elif/else chain with one return point.

Closes #2648

Signed-off-by: Satya <tsp.0713@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai force-pushed the issue-2648_post_fetch_plugin_resource_invoke branch from 79495e0 to fd76484 Compare February 7, 2026 12:26
@crivetimihai
Copy link
Copy Markdown
Member

Review & Rebase Summary

Rebased onto main, squashed 6 commits into 1 clean commit (original author preserved), and fixed minor issues.

Changes made during rebase

  • Removed 12 unrelated files (plugins/unified_pdp/ encoding header removals) that leaked in from a prior rebase
  • Fixed flake8 E302 — missing blank line before TestAwsSecretPattern class in test_secrets_detection.py
  • Squashed all commits into a single clean commit with conventional commit message

Review notes

Logic — Correct. Moves RESOURCE_POST_FETCH hooks to after invoke_resource() resolves actual content from the gateway. Previously, plugins like secrets_detection received raw template URIs and couldn't redact secrets.

Consistency — Matches the existing TOOL_POST_INVOKE pattern in tool_service.py, where post-invocation hooks run after the actual result is available.

Security — This is a security improvement: closes a gap where resolved secrets could bypass plugin redaction.

Performance — No impact; hook invocation is moved, not duplicated.

Tests — All 21 related tests pass. Full unit suite passes (1 pre-existing flaky cache timing test unrelated to this PR).

Structural improvements in the PR:

  • Refactored early-return branches into a single if/elif/else chain with one return point
  • Added defensive if resource_response: null-checks before overwriting blob/text
  • db.commit() placement preserved before network calls

@crivetimihai crivetimihai merged commit 1c451f1 into main Feb 7, 2026
51 checks passed
@crivetimihai crivetimihai deleted the issue-2648_post_fetch_plugin_resource_invoke branch February 7, 2026 12:38
kcostell06 pushed a commit to kcostell06/mcp-context-forge that referenced this pull request Feb 24, 2026
…content (IBM#2655)

Move RESOURCE_POST_FETCH hook invocation to after invoke_resource()
resolves content from the gateway. Previously, post-fetch plugins
(e.g. secrets_detection) received raw template URIs instead of actual
content, allowing secrets to pass through unredacted.

Also adds null-checks before setting blob/text from invoke_resource()
response, and normalizes the content resolution into a single
if/elif/else chain with one return point.

Closes IBM#2648

Signed-off-by: Satya <tsp.0713@gmail.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
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