Credential cache file for mcp subprocess
Skill kjuhwa/skills-hub/skills/agent-sdk/credential-cache-file-for-mcp-subprocess
Self-correcting knowledge corpus for Claude Code — 9 stable shape clusters, bias-correction pipeline baked into contribution flow. 47 papers, 45 techniques, 1.1k skills.
npx -y skills add kjuhwa/skills-hub --skill credential-cache-file-for-mcp-subprocessAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Write decrypted per-source credentials to a session-scoped .credential-cache.json on disk so MCP stdio subprocesses can read them without the parent passing secrets via env (which shows up in ps).
SKILL.md
2.9 KB, as published. Nobody here has run it
Credential cache file for MCP subprocesses
When to use
- Spawning MCP subprocesses that each need per-source credentials (GitHub token, Slack bearer, etc.).
- Don't want secrets in
env(visible viaps -e, leakable through logging). - Secrets rotate or expire; the subprocess must re-read on each call rather than snapshot at start.
How it works
- Parent (Electron main) maintains the encrypted credential store.
- When a session starts and a source is activated, parent decrypts the relevant credential and writes it to:
<workspaceRoot>/sources/<sourceSlug>/.credential-cache.json - File format:
{ "value": "<secret>", "expiresAt": 1732000000000 } - Permissions: restrict to user (
0600). Clean up on session end. - Subprocess reads this file per tool call (not per session start) - handles rotation and expiry naturally.
- Subprocess checks
expiresAt; if expired, sends a__CALLBACK__stderr message asking the parent to refresh. - Keep file outside the session dir (under
sources/) so the same cache is shared across sessions that use the same source.
Example
// Parent
function refreshCache(workspaceRoot, sourceSlug, cred) {
const path = join(workspaceRoot, 'sources', sourceSlug, '.credential-cache.json');
writeFileSync(path, JSON.stringify({ value: cred.accessToken, expiresAt: cred.expiresAt }));
chmodSync(path, 0o600);
}
// Subprocess
function getCredential(workspaceRoot, sourceSlug) {
const p = join(workspaceRoot, 'sources', sourceSlug, '.credential-cache.json');
if (!existsSync(p)) return null;
const { value, expiresAt } = JSON.parse(readFileSync(p, 'utf8'));
if (expiresAt && Date.now() > expiresAt) {
console.error(`__CALLBACK__${JSON.stringify({ type:'credential_expired', sourceSlug })}`);
return null;
}
return value;
}
Gotchas
- Always
chmod 0600- writing credentials world-readable is the dumb version of this. - Don't rely on
.gitignoreto keep these out of repos; they're under workspace dirs that users may zip and share. - On Windows, permission bits don't map cleanly; combine with ACL or keep the parent dir write-protected.
- Add to session cleanup: delete stale caches on session close.
- Subprocess reading per tool call has a small perf cost but wins on rotation safety.