Files
wehub-resource-sync d48cda4081
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Failing after 15m1s
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Failing after 17m13s
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Failing after 18m42s
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Failing after 15m0s
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Failing after 49m44s
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Failing after 51m55s
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Failing after 21m57s
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Failing after 37m39s
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Failing after 34m7s
CI / Validate Components (push) Failing after 37m15s
CI / Python Tests (push) Failing after 10m1s
CI / Security Scan (push) Failing after 10m1s
CI / Lint (push) Failing after 17m12s
CI / Coverage (push) Failing after 20m19s
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:55 +08:00

74 lines
1.9 KiB
JavaScript

'use strict';
const fs = require('fs');
const os = require('os');
const path = require('path');
// Claude Code stores MCP servers under "mcpServers" in ~/.claude.json (user
// scope) and in project-local .mcp.json files (project scope). Each entry:
// { type: "stdio"|"http"|"sse", command, args[], env{}, url }
function mapClaudeServer(name, raw, source) {
if (!raw || typeof raw !== 'object') {
return null;
}
return {
name,
type: typeof raw.type === 'string' ? raw.type : (raw.url ? 'http' : 'stdio'),
command: raw.command || null,
args: Array.isArray(raw.args) ? raw.args : [],
url: raw.url || null,
env: raw.env && typeof raw.env === 'object' ? raw.env : {},
enabled: raw.disabled === true ? false : true,
source
};
}
function readMcpServersBlock(filePath, scope) {
if (!fs.existsSync(filePath) || !fs.statSync(filePath).isFile()) {
return [];
}
let parsed;
try {
parsed = JSON.parse(fs.readFileSync(filePath, 'utf8'));
} catch {
return [];
}
const block = parsed && typeof parsed.mcpServers === 'object' && parsed.mcpServers
? parsed.mcpServers
: {};
return Object.entries(block)
.map(([name, raw]) => mapClaudeServer(name, raw, {
harness: 'claude-code',
scope,
configPath: filePath
}))
.filter(Boolean);
}
function readClaudeCodeMcp(options = {}) {
const homeDir = options.homeDir || os.homedir();
const userConfig = options.userConfigPath || path.join(homeDir, '.claude.json');
const projectConfigPaths = Array.isArray(options.projectConfigPaths)
? options.projectConfigPaths
: [];
const records = [
...readMcpServersBlock(userConfig, 'user')
];
for (const projectPath of projectConfigPaths) {
records.push(...readMcpServersBlock(projectPath, 'project'));
}
return records;
}
module.exports = {
readClaudeCodeMcp,
mapClaudeServer
};