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
74 lines
2.3 KiB
JavaScript
74 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
const fs = require('fs');
|
|
const os = require('os');
|
|
const path = require('path');
|
|
|
|
// OpenCode stores MCP servers under "mcp" in ~/.config/opencode/opencode.json.
|
|
// Shape differs from Claude/Codex:
|
|
// { type: "local"|"remote", command: ["npx","-y","pkg"], environment: {},
|
|
// enabled: bool, url: "https://..." }
|
|
// command is an ARRAY (binary + args combined); environment (not env) holds
|
|
// secrets; type "local" => stdio, "remote" => http/sse.
|
|
function mapOpencodeServer(name, raw, configPath) {
|
|
if (!raw || typeof raw !== 'object') {
|
|
return null;
|
|
}
|
|
|
|
const commandArray = Array.isArray(raw.command) ? raw.command.filter(item => typeof item === 'string') : [];
|
|
const [command, ...args] = commandArray;
|
|
|
|
return {
|
|
name,
|
|
type: typeof raw.type === 'string' ? raw.type : (raw.url ? 'remote' : 'local'),
|
|
command: command || (typeof raw.command === 'string' ? raw.command : null),
|
|
args: command ? args : (Array.isArray(raw.args) ? raw.args : []),
|
|
url: typeof raw.url === 'string' ? raw.url : null,
|
|
env: raw.environment && typeof raw.environment === 'object'
|
|
? raw.environment
|
|
: (raw.env && typeof raw.env === 'object' ? raw.env : {}),
|
|
enabled: raw.enabled === false ? false : true,
|
|
source: {
|
|
harness: 'opencode',
|
|
scope: 'user',
|
|
configPath
|
|
}
|
|
};
|
|
}
|
|
|
|
function readOpencodeMcp(options = {}) {
|
|
const homeDir = options.homeDir || os.homedir();
|
|
const candidatePaths = options.configPath
|
|
? [options.configPath]
|
|
: [
|
|
path.join(homeDir, '.config', 'opencode', 'opencode.json'),
|
|
path.join(homeDir, '.config', 'opencode', 'config.json'),
|
|
path.join(homeDir, '.opencode.json')
|
|
];
|
|
|
|
const configPath = candidatePaths.find(candidate => fs.existsSync(candidate) && fs.statSync(candidate).isFile());
|
|
if (!configPath) {
|
|
return [];
|
|
}
|
|
|
|
let parsed;
|
|
try {
|
|
parsed = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
} catch {
|
|
return [];
|
|
}
|
|
|
|
const block = parsed && typeof parsed.mcp === 'object' && parsed.mcp
|
|
? parsed.mcp
|
|
: (parsed && typeof parsed.mcpServers === 'object' && parsed.mcpServers ? parsed.mcpServers : {});
|
|
|
|
return Object.entries(block)
|
|
.map(([name, raw]) => mapOpencodeServer(name, raw, configPath))
|
|
.filter(Boolean);
|
|
}
|
|
|
|
module.exports = {
|
|
readOpencodeMcp,
|
|
mapOpencodeServer
|
|
};
|