THINKINGOS
A I L a b o r a t o r y
Blog materials reflect our practical experience and R&D hypotheses. Where effects are mentioned, outcomes depend on project context, data quality, architecture, and implementation process.
Back to blog
Security
October 24, 2026 14 min
MCP Security AI Agents Secrets IDE

How We Made Coding Agents Safer : Automatic Secret Extraction from MCP and REST API Configs

AI coding agents store API keys in configs in plaintext. We implemented automatic secret extraction and OAuth 2.0 with PKCE for REST API — built-in protection at the IDE level.

How We Made Coding Agents Safer: Automatic Secret Extraction from MCP and REST API Configs

AI coding agents work with external tools through MCP servers and REST API connections. These server configurations store API keys and tokens — almost always in plaintext. According to GitGuardian, 29 million hardcoded secrets were found in public GitHub commits in 2025, with approximately 24,000 of those in MCP configuration files specifically. Commits involving AI assistants leak credentials at twice the rate of regular commits.

We faced this problem directly and implemented automatic secret extraction — a built-in mechanism for protecting configs at the IDE level. The mechanism works uniformly for both types of connections: MCP servers and REST API. Below is a breakdown of the problem, a market comparison, and the architecture of our solution.

1) The Scale of the Problem: Secrets in Configs Are Not a Theoretical Risk

AI coding agents (Cursor, Windsurf, Cline, Roo Code, Claude Desktop) work with external services through configuration files — MCP servers and REST API connections. These files store API keys, tokens, and other secrets — in plaintext.

When a developer sets up an MCP server or REST API connection, they paste the key directly into the config:

// MCP server (mcp_settings.json)
{
  "mcpServers": {
    "my-server": {
      "command": "npx",
      "args": ["-y", "@my/mcp-server"],
      "env": {
        "API_KEY": "sk-ant-api07-very-secret-key-here"
      }
    }
  }
}

// REST API connection (restApiServers.json)
{
  "restApiServers": {
    "github_api": {
      "baseUrl": "https://api.github.com",
      "headers": {
        "Authorization": "Bearer ghp_very_secret_token_here"
      }
    }
  }
}

These files can end up in Git, be read by another extension, or simply sit on disk in plaintext.

GitGuardian’s data (“State of Secrets Sprawl 2026” report) shows the scale:

  • 28.65 million new hardcoded secrets in public GitHub commits in 2025 (+34% year-over-year)
  • 24,008 unique secrets found specifically in MCP configuration files
  • 2,117 of those were valid credentials that actually worked
  • AI service secrets: 1,275,105 leaks (+81% year-over-year)
  • 3.2% of commits with AI assistants contain leaks — vs. 1.5% baseline across all of GitHub

Notably, MCP documentation itself encourages insecure patterns. Setup guides recommend putting API keys directly into configuration files.

2) How Others Handle It: Plaintext Everywhere

We checked the major AI coding agents and IDEs:

ToolConfig FileApproach to Secrets
Cursor.cursor/mcp.json (project) + ~/.cursor/mcp.json (user)Plaintext in env/headers
Windsurfmcp_config.jsonPlaintext, same approach
Cline (original)mcp_settings.jsonPlaintext, no extraction mechanism
Roo CodeCline forkNo improvements in this area
Claude Desktopclaude_desktop_config.jsonPlaintext; login token in OS keychain (macOS), but MCP secrets — in file
VS Code Copilot~/.copilot/mcp-config.jsonSupports inputs (prompt at runtime), but no automatic extraction from configs

Third-party solutions (1Password, GitGuardian, Knostic) offer vault management or post-facto leak detection. But no IDE automatically extracts secrets from configs at the editor level.

The problem is compounded by the fact that existing controls (repository scanners, IdP/IAM/PAM, secrets managers) don’t see the endpoint level. When a developer adds an MCP server in minutes, security review simply can’t keep up with the pace of change.

3) Our Approach: Automatic Secret Extraction for MCP and REST API

We implemented SecretExtractor — the industry’s first built-in mechanism for protecting configs at the IDE level. The mechanism works uniformly for both types of connections: MCP servers and REST API.

The principle is simple: the user shouldn’t have to do anything to protect their keys. Enter a key in config → it’s automatically protected.

How It Works

User enters API key in config (plaintext)
    ↓
SecretExtractor automatically extracts the value
    ↓
Key is saved to VS Code SecretStorage (OS-level encryption)
    ↓
Config gets a placeholder: {{SECRET:my-server_env_0}}
    ↓
UI shows a mask: [🔒 my-server_env_0]
    ↓
On request execution — runtime resolver automatically substitutes the real value
    ↓
Server receives the real key and works normally

Key Properties

  1. Automatic — the user doesn’t need to do anything. Enter the key → it’s already protected.
  2. Unified mechanism — works for MCP (env vars) and REST API (headers).
  3. Deduplication — if the same value is already saved, the existing key is reused. No duplicates in storage.
  4. Secure storage — VS Code SecretStorage uses OS-level encryption (Keychain on macOS, DPAPI on Windows).
  5. UI mask — the JSON editor shows [🔒 key_name] instead of the real value. The key isn’t visible when browsing the config.
  6. Runtime resolver — on request execution, {{SECRET:KEY}} placeholders are automatically replaced with real values. The server is unaware of the substitution.
  7. Backward compatibility — existing plaintext configs are automatically migrated on first connection.
  8. Leak-free logging — only counters and server names go into logs, never secret values.

4) Architecture: What’s Under the Hood

The system consists of several components, each responsible for its part of the pipeline:

┌─────────────────────────────────────────────────────────────┐
│  Configs (mcp_settings.json / restApiServers.json)          │
│  "env"/"headers": { "API_KEY": "{{SECRET:my-server_env_0}}" }│
└──────────────────────────┬──────────────────────────────────┘
                           │
              ┌────────────▼────────────┐
              │   SecretExtractor       │
              │   (MCP + REST API)      │
              │   extraction + dedup    │
              └────────────┬────────────┘
                           │
              ┌────────────▼────────────┐
              │   VS Code SecretStorage │
              │   (OS encryption)       │
              └────────────┬────────────┘
                           │
              ┌────────────▼────────────┐
              │   SecretsResolver       │
              │   (runtime substitution)│
              └────────────┬────────────┘
                           │
              ┌────────────┴────────────┐
              │                         │
    ┌─────────▼─────────┐    ┌─────────▼─────────┐
    │   MCP Server      │    │   REST API Server │
    │   (stdio/sse)     │    │   (HTTP requests) │
    └───────────────────┘    └───────────────────┘

SecretExtractor (MCP: 331 lines, REST API: ~300 lines) — scans env vars (stdio transport) and headers (sse/streamableHttp/REST API), generates key names, deduplicates via StateManager.getSecretKey().

SecretsResolver — recursive replacement of {{SECRET:KEY}} with real values from StateManager. Works transparently for servers.

McpHub — integration point for MCP: extraction triggers on updateServerConnections() and connectToServer().

RestApiHub — integration point for REST API: calls resolveSecretsInObject() before each HTTP request.

saveMcpSettingsJson — extraction on config write to disk. If a user manually adds a plaintext key, it will be extracted on the next save.

UI components — maskSecretsForDisplay() and unmaskSecretsForSave() for MCP and REST API JSON editors. The user sees masks, but placeholders are handled correctly on save.

5) OAuth 2.0 for REST API: Secure Authentication Without Storing Passwords

Beyond API keys, TaoCoder supports OAuth 2.0 with PKCE for REST API connections — a modern authentication standard that doesn’t require storing the user’s password.

How OAuth Works in TaoCoder

User configures REST API with OAuth config
    ↓
TaoCoder generates PKCE code_verifier + code_challenge (S256)
    ↓
Opens browser with authorization URL + state + code_challenge
    ↓
User authenticates on the provider's site
    ↓
Provider redirects to callback with authorization code
    ↓
TaoCoder exchanges code + code_verifier for access_token
    ↓
Tokens are saved to SecretStorage (OS encryption)
    ↓
On each request — token is automatically inserted into Authorization header
    ↓
On expiry — automatic refresh via refresh_token

Key Properties of OAuth Implementation

  1. PKCE (Proof Key for Code Exchange) — protection against interception attacks. A cryptographic code_verifier (32 bytes) is generated, its SHA-256 hash is sent as code_challenge.
  2. State parameter — CSRF protection. A random 32-byte state is verified on callback.
  3. Automatic refresh — when access_token expires, the system automatically uses refresh_token to obtain a new one.
  4. Secure storage — all tokens are stored in SecretStorage, never end up in config or logs.
  5. Per-server isolation — each REST API server has its own token set, identified by SHA-256 hash of name+URL.

OAuth Configuration

{
  "restApiServers": {
    "github_api": {
      "baseUrl": "https://api.github.com",
      "oauth": {
        "authorizationUrl": "https://github.com/login/oauth/authorize",
        "tokenEndpoint": "https://github.com/login/oauth/access_token",
        "scopes": ["repo", "user"],
        "clientId": "your_client_id",
        "clientSecret": "your_client_secret"
      }
    }
  }
}

OAuth Architecture

┌─────────────────────────────────────────────────────────────┐
│  REST API config with OAuth settings                        │
│  (authorizationUrl, tokenEndpoint, scopes, clientId)        │
└──────────────────────────┬──────────────────────────────────┘
                           │
              ┌────────────▼────────────┐
              │   RestApiOAuthManager   │
              │   • PKCE generation     │
              │   • State management    │
              │   • Token exchange      │
              │   • Auto-refresh        │
              └────────────┬────────────┘
                           │
              ┌────────────▼────────────┐
              │   VS Code SecretStorage │
              │   (access_token,        │
              │    refresh_token,       │
              │    code_verifier)       │
              └────────────┬────────────┘
                           │
              ┌────────────▼────────────┐
              │   RestApiHub            │
              │   (inserts token into   │
              │    Authorization)       │
              └────────────┬────────────┘
                           │
              ┌────────────▼────────────┐
              │   REST API Server       │
              │   (receives request     │
              │    with Bearer token)   │
              └─────────────────────────┘

What’s Under the Hood of OAuth

RestApiOAuthManager (364 lines) — full OAuth 2.0 + PKCE implementation:

  • startOAuthFlow() — PKCE generation, state, browser opening
  • completeOAuthFlow() — state validation, code-to-tokens exchange
  • getValidTokens() — expiry check, automatic refresh
  • refreshTokens() — token renewal via refresh_token
  • clearServerAuth() — OAuth data cleanup on server deletion

schemas.ts — OAuthConfigSchema with URL, scopes, clientId/clientSecret validation.

getServerAuthHash() — SHA-256 hash of serverName:serverUrl for data isolation.

OAuth Implementation Security

ThreatProtection
Interception attacksPKCE (S256) — code_verifier known only to client
CSRFState parameter (32 bytes, verified on callback)
Token leakageStorage in SecretStorage (OS encryption)
Token expiryAutomatic refresh via refresh_token
Replay attacksState timestamp (10 minutes expiry)

6) Five Layers of MCP Risk and Where This Protection Fits

Aembit’s MCP security guide (2026) identifies five layers of risk:

  1. Transport & communications — missing TLS/mTLS, DNS rebinding, replay attacks
  2. Authentication & identity — static API keys, long-lived tokens in configs, hardcoded secrets
  3. Context integrity — agent context poisoning, data leakage into unrelated workflows
  4. Authorization & privileges — excessive permissions, privilege escalation
  5. Supply chain — malicious tool descriptors, repository pollution, shadow servers

Our solution covers the second layer — authentication & identity. This is a critical area: it’s where secrets end up in configs and from there — in Git, logs, cloud syncs.

But it’s important to understand: secret extraction is necessary but not sufficient. Full MCP protection requires:

  • transport control (TLS, mTLS);
  • context validation at every boundary;
  • least privilege for each MCP server;
  • runtime anomaly monitoring;
  • supply chain verification (signed artifacts, integrity hashes).

We’re working on extending protection in these directions — as part of the overall execution layer architecture (see our TaoBridge execution layer breakdown).

7) Test Coverage

We don’t trust security without tests. SecretExtractor is covered by:

  • 46 unit tests for MCP SecretExtractor — all extraction, deduplication, and naming scenarios
  • 28 unit tests for REST API SecretExtractor
  • 14 integration tests for the MCP secrets pipeline — full cycle from config write to runtime resolution
  • 232 lines of integration tests for StateManager custom secrets
  • Full cycle: Save → Extract → Placeholders → Load → Resolve → Real values → Round-trip

Every commit passes CI with these tests. If something breaks — deployment is blocked.

8) Why This Matters

Three factors make this problem especially relevant right now:

MCP and REST API are the standards. Every AI agent connects to external tools through MCP and REST API. Every server may require an API key or OAuth. The number of secrets in configs grows linearly with the number of integrations.

Configs end up in Git. Developers often commit mcp.json and restApiServers.json alongside the project. Even if the file is in .gitignore, it can be read by another extension, synced through the cloud, or simply sit on disk in plaintext.

AI agents double the risk. According to GitGuardian, commits with AI assistants leak at twice the rate. Shadow AI scales faster than security policy: teams add agents and MCP servers in minutes, while security review operates on a different timescale.

Conclusion

TAO·CODER is the first coding agent that natively prevents secret leaks from MCP and REST API configs. Users get protection out of the box — no need to configure vaults, hooks, or third-party tools.

Additionally, OAuth 2.0 with PKCE is implemented for REST API — a modern authentication standard that doesn’t require storing the user’s password and automatically refreshes tokens.

This isn’t marketing — this is engineering. Secrets shouldn’t live in plaintext. Period.

Key numbers:

  • 29 million hardcoded secrets in public GitHub commits in 2025
  • 24,000 secrets in MCP configs
  • 46 unit tests for MCP + 28 for REST API + 14 integration tests
  • 0 lines of plaintext after automatic extraction

Technical details:

  • MCP SecretExtractor: vendor/cline/src/services/mcp/SecretExtractor.ts
  • REST API SecretExtractor: vendor/cline/src/services/rest-api/SecretExtractor.ts
  • SecretsResolver: vendor/cline/src/taocoder/runtime/secretsResolver.ts
  • RestApiOAuthManager: vendor/cline/src/services/rest-api/RestApiOAuthManager.ts
  • OAuth schemas: vendor/cline/src/services/rest-api/schemas.ts
  • StateManager custom secrets: vendor/cline/src/core/storage/StateManager.ts
  • UI mask: vendor/cline/webview-ui/src/components/mcp/configuration/tabs/JsonEditorScreen.tsx

References

AI Security

Need a similar system?

Share the task, and we will suggest an architecture, control layer, and rollout path.

Discuss a project