DEV Community

intothewild
intothewild

Posted on Edited on

Can an MCP Server Actually Help Prevent AI Agents From Leaking Secrets?

I've been experimenting with MCP servers and AI coding agents while building an open-source project called StagedSec.

One thing I've been thinking about is where security checks should happen when an AI agent works with a developer's repository.

Most secret scanners operate on files, Git history, or commits. These are useful, but with AI agents, there's another interesting point: the moment an agent attempts to write something.

Imagine an agent generating a configuration file containing:

API_KEY=sk_live_...
DATABASE_PASSWORD=...
Enter fullscreen mode Exit fullscreen mode

A scanner can find these values later, but what if we could inspect the content before allowing the write?

That's one of the ideas behind StagedSec.

What I'm experimenting with

StagedSec currently has:

  • A Go-based secret detection engine.
  • An MCP server that exposes scanning capabilities to AI agents.
  • An agent hook that checks tool-call content.
  • A CLI, Git integration, and VS Code extension.

The goal is to make secret detection available closer to the point where the content is generated.

But there are still difficult problems

I'm particularly interested in a few questions:

  1. What happens when an agent splits a secret across multiple tool calls?
  2. How should a security hook handle repeated retries without making the agent workflow unusable?
  3. Can we detect encoded or obfuscated secrets without storing sensitive content?
  4. How much should an MCP server be responsible for enforcing security versus simply reporting findings?

These aren't completely solved problems in my implementation. I'm exploring them as I develop the project.

I'd like to hear from people working with MCP and AI agents

If you're building MCP servers, AI coding tools, or developer security tooling, I'd genuinely like to hear how you're approaching these problems.

I'm also looking for a few people willing to test the MCP integration and report what works or doesn't.

Project: https://gitlab.com/stagedsec/stagedsec

MCP package: https://www.npmjs.com/package/stagedsec-mcp-server

This is an early open-source project, and I'm interested in technical criticism just as much as positive feedback.

Top comments (0)