Claude Desktop + MCP で自動許可
Claude Desktop + MCP、毎回MCPサーバーの利用許可を求めてきてクソうざいですよね~。
と思っていたらこんな記事を発見。
https://kahunam.com/articles/blog/how-to-make-claude-desktop-auto-approve-mcp-tools-a-power-users-guide/
ふむふむ。開発者モードになってコンソールからSnippet をぶん回して許可ボタンを押しまくる仕組みか。。。
という事で、この手順通りやってみたがいまいちうまくいかない。
よくよくスニペットを眺めてみると、なるほど。日本語版 Claude Desktop では動かないのね。
ということで、日本語化したソースコードをこちらに置いておきます。
さらに、魔改造しており、元々のコードは導入済のMCPサーバーの機能別に許可を入れないといけなかったのが、このコードはMCPに登録しているサーバー名称単位で許可するので、例えば puppeteer なら puppeteer の諸機能をマルっとスルーする危険仕様となっています。
つにでに、あまり参考資料の出ていないWindows+WSL2で私がやっているclaude_desktop_config.json もおいておきます。
ネットで拾ってきたもので私腹を肥やす行儀悪い人にはなりたくないので、全部無料でお楽しみください。お礼いただける方、お待ちしております :)
4/26 元々のコードの無限LOOP仕様が気に入らなかったので、ChatGPT先生と相談してちょいと変更。一定時間に一度、ユーザーにループからの脱出手段をご提供。(ただし、ユーザーが反応しない場合はそのままループに戻る)
日本語版 自動許可スクリプト(ザル魔改造仕様)
2025.4.26 Claude Desktop UI 変更にともないコード修正
const trustedTools = [
'list-allowed-directories', 'list-denied-directories', 'ls',
'claude_code', 'brave-search', 'github', 'mcp-server-commands',
'slack', 'sequential-thinking', 'puppeteer', 'memory', 'filesystem-wsl',
'fetch', 'figma'
];
let lastClickTime = 0;
const COOLDOWN_MS = 1000; // 1秒クールダウン
const PAUSE_INTERVAL_MS = 5 * 60 * 1000; // 5分ごとに休止
const USER_RESPONSE_TIMEOUT_MS = 10 * 1000; // 10秒でタイムアウト
let observer;
let pauseTimer;
let userResponseTimer;
let colorInterval;
// 監視対象設定
const observerCallback = (mutations) => {
const now = Date.now();
if (now - lastClickTime < COOLDOWN_MS) {
console.log('🕒 Cooldown active, skipping...');
return;
}
const dialog = document.querySelector('[role="dialog"]');
if (!dialog) return;
const requestTag = dialog.querySelector('h2');
if (!requestTag) return;
const buttonWithDiv = dialog.querySelector('button div span');
if (!buttonWithDiv) return;
const toolName = buttonWithDiv.textContent;
if (!toolName) return;
if (trustedTools.includes(toolName)) {
const allowButton = Array.from(dialog.querySelectorAll('button'))
.find(button => button.textContent.includes('このチャットで許可する'));
if (allowButton) {
observer.disconnect(); // 一時停止
allowButton.click();
lastClickTime = now;
setTimeout(startObserving, 500); // クリック後に再開
}
}
};
// 監視開始
function startObserving() {
if (observer) observer.disconnect();
observer = new MutationObserver(observerCallback);
observer.observe(document.body, {
childList: true,
subtree: true
});
console.log('👀 Observer started');
clearTimeout(pauseTimer);
pauseTimer = setTimeout(pauseForUser, PAUSE_INTERVAL_MS);
}
// 一時停止してユーザーに選択肢を出す
function pauseForUser() {
console.log('⏸️ Pausing observer for user confirmation.');
observer.disconnect();
const existing = document.getElementById('resume-overlay');
if (existing) existing.remove();
const overlay = document.createElement('div');
overlay.id = 'resume-overlay';
overlay.style.position = 'fixed';
overlay.style.top = '0';
overlay.style.left = '0';
overlay.style.width = '100vw';
overlay.style.height = '100vh';
overlay.style.backgroundColor = 'rgba(0,0,0,0.85)';
overlay.style.display = 'flex';
overlay.style.flexDirection = 'column';
overlay.style.alignItems = 'center';
overlay.style.justifyContent = 'center';
overlay.style.zIndex = '9999';
overlay.innerHTML = `
<h1 style="color: white; margin-bottom: 20px; font-size: 32px;">⏳ 監視を続行しますか?</h1>
<div id="progress-bar-container" style="width: 300px; height: 24px; background: grey; margin-bottom: 40px; overflow: hidden; border-radius: 12px;">
<div id="progress-bar" style="width: 100%; height: 100%; background: limegreen; transition: width ${USER_RESPONSE_TIMEOUT_MS}ms ease-in-out;"></div>
</div>
<div style="display: flex; gap: 20px;">
<button id="continue-btn" style="
font-size: 28px;
padding: 16px 32px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
transition: background-color 0.3s ease;
">続行する</button>
<button id="stop-btn" style="
font-size: 28px;
padding: 16px 32px;
background-color: #ff4d4d;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
transition: background-color 0.3s ease;
">停止する</button>
</div>
`;
document.body.appendChild(overlay);
// プログレスバーを縮める
setTimeout(() => {
const bar = document.getElementById('progress-bar');
if (bar) bar.style.width = '0%';
}, 100);
// 色変化を開始
setTimeout(() => startColorChange(), USER_RESPONSE_TIMEOUT_MS - 3000);
// 続行ボタン
document.getElementById('continue-btn').onclick = () => {
clearTimeout(userResponseTimer);
clearInterval(colorInterval);
document.getElementById('resume-overlay').remove();
console.log('✅ User chose to continue.');
startObserving();
};
// 停止ボタン
document.getElementById('stop-btn').onclick = () => {
clearTimeout(userResponseTimer);
clearInterval(colorInterval);
document.getElementById('resume-overlay').remove();
console.log('🛑 User chose to stop observer.');
clearTimeout(pauseTimer);
};
// 10秒後に自動続行
userResponseTimer = setTimeout(() => {
clearInterval(colorInterval);
const overlay = document.getElementById('resume-overlay');
if (overlay) {
overlay.remove();
console.log('⏳ No response, automatically resuming.');
startObserving();
}
}, USER_RESPONSE_TIMEOUT_MS);
}
// 色変化処理
function startColorChange() {
const bar = document.getElementById('progress-bar');
if (!bar) return;
const startTime = Date.now();
const duration = 3000; // 3秒
colorInterval = setInterval(() => {
const elapsed = Date.now() - startTime;
const progress = Math.min(elapsed / duration, 1);
// 緑 (limegreen: #32CD32) → 黄 (yellow: #FFFF00) → 赤 (red: #FF0000)
let r, g, b;
if (progress < 0.5) {
// 緑→黄
const ratio = progress / 0.5;
r = Math.round(50 + (255 - 50) * ratio); // 50→255
g = 205; // 固定
b = Math.round(50 + (0 - 50) * ratio); // 50→0
} else {
// 黄→赤
const ratio = (progress - 0.5) / 0.5;
r = 255; // 固定
g = Math.round(205 - 205 * ratio); // 205→0
b = 0;
}
bar.style.backgroundColor = `rgb(${r},${g},${b})`;
if (progress >= 1) {
clearInterval(colorInterval);
}
}, 50);
}
// 最初の起動
startObserving();
claude_desktop_config.json
{
"globalShortcut": "",
"mcpServers": {
"claude_code": {
"command": "C:\\Windows\\System32\\wsl.exe",
"args": [
"bash",
"-ic",
"/home/fcukoksan/.anyenv/envs/nodenv/shims/claude mcp serve"
],
"env": {}
},
"filesystem-wsl": {
"command": "C:\\Windows\\System32\\wsl.exe",
"args": [
"bash",
"-c",
"/home/fcukoksan/.anyenv/envs/nodenv/shims/npx -y @modelcontextprotocol/server-filesystem /home/fcukoksan/dev /mnt/c/Users/fcukoksan/AppData/Local/AnthropicClaude"
]
},
"brave-search": {
"command": "C:\\Program Files\\nodejs\\node.exe",
"args": [
"C:\\Users\\fcukoksan\\AppData\\Roaming\\npm\\node_modules\\@modelcontextprotocol\\server-brave-search\\dist\\index.js"
],
"env": {
"BRAVE_API_KEY": "hogehogehogehogehoge"
}
},
"sequential-thinking": {
"command": "C:\\Program Files\\nodejs\\node.exe",
"args": [
"C:\\Users\\fcukoksan\\AppData\\Roaming\\npm\\node_modules\\@modelcontextprotocol\\server-sequential-thinking\\dist\\index.js"
]
},
"github": {
"command": "C:\\Windows\\System32\\wsl.exe",
"args": [
"bash",
"-c",
"GITHUB_PERSONAL_ACCESS_TOKEN=ghp_hogehogehogehogehoge /home/fcukoksan/.anyenv/envs/nodenv/shims/npx -y @modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_hogehogehogehogehoge"
}
},
"puppeteer": {
"command": "C:\\Windows\\System32\\wsl.exe",
"args": [
"bash",
"-c",
"/home/fcukoksan/.anyenv/envs/nodenv/shims/npx -y @modelcontextprotocol/server-puppeteer"
]
},
"fetch": {
"command": "C:\\Users\\fcukoksan\\.local\\bin\\uvx.exe",
"args": [
"mcp-server-fetch"
]
},
"mcp-server-commands": {
"command": "C:\\Windows\\System32\\wsl.exe",
"args": [
"bash",
"-c",
"/home/fcukoksan/.anyenv/envs/nodenv/shims/npx -y mcp-server-commands"
]
},
"aws-management": {
"command": "C:\\Users\\fcukoksan\\AppData\\Roaming\\npm\\npm.cmd",
"args": [
"--silent",
"--prefix",
"C:\\dev\\tools\\aws-mcp",
"start"
],
"env": {
"AWS_PROFILE": "default",
"AWS_REGION": "ap-northeast-1"
}
},
"slack": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-slack"
],
"env": {
"SLACK_BOT_TOKEN": "hogehogehogehogehoge",
"SLACK_TEAM_ID": "hogehogehogehogehoge"
}
}
}
}