MCPcopy
hub / github.com/garrytan/gstack / runContentFilters

Function runContentFilters

browse/src/content-security.ts:284–320  ·  view source on GitHub ↗
(
  content: string,
  url: string,
  command: string,
)

Source from the content-addressed store, hash-verified

282 * Returns aggregated result with all warnings.
283 */
284export function runContentFilters(
285 content: string,
286 url: string,
287 command: string,
288): ContentFilterResult {
289 const mode = getFilterMode();
290 if (mode === 'off') {
291 return { safe: true, warnings: [] };
292 }
293
294 const allWarnings: string[] = [];
295 let blocked = false;
296
297 for (const filter of registeredFilters) {
298 const result = filter(content, url, command);
299 if (!result.safe) {
300 allWarnings.push(...result.warnings);
301 if (mode === 'block') {
302 blocked = true;
303 }
304 }
305 }
306
307 if (blocked && allWarnings.length > 0) {
308 return {
309 safe: false,
310 warnings: allWarnings,
311 blocked: true,
312 message: `Content blocked: ${allWarnings.join('; ')}`,
313 };
314 }
315
316 return {
317 safe: allWarnings.length === 0,
318 warnings: allWarnings,
319 };
320}
321
322// ─── Built-in URL Blocklist Filter ──────────────────────────────
323

Callers 4

handleSaveFunction · 0.90

Calls 2

getFilterModeFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected