Files
archived-orca/src/shared/mcp-server-inspection.ts
T
Neil 991a3fe963 chore(lint): update oxlint to 1.77 and enable no-op cleanup rules (#13901)
Enable eleven oxlint rules that simplify code without changing behavior, and fix
every existing violation. Each candidate was gated on measured cost rather than
assumption, so rules that regressed runtime performance or type checking were
dropped instead of suppressed.

typescript/no-redundant-type-constituents is the largest addition: 113 sites, no
autofix. Dead constituents are deleted. Where the redundant literal existed to
document intent (`string | 'all'`), it is preserved as `(string & {})`, which
keeps the autocomplete hint the original code was reaching for instead of
flattening it away. The rule also caught a broken import —
remote-shared-control-retirement-probe.ts pulled RuntimeStatus from
src/shared/types, which does not export it, so the type silently degraded to
`any`; no tsconfig covers that file, so tsc never saw it.

oxlint stays at 1.77.0 rather than 1.78.0 because .npmrc sets
minimum-release-age=4320 and 1.78.0 is younger than that window.

Rules evaluated and rejected, with what disqualified each:
- prefer-string-raw: String.raw is a runtime call, not a literal (184x slower)
- prefer-string-replace-all: 26% slower
- text-encoding-identifier-case: ~5% slower, reproducible
- prefer-spread: [...str] is 110% slower than split('') and differs on surrogates
- no-implicit-coercion: `!!x` narrows types and `Boolean(x)` does not (22 tsc errors)
- prefer-arrow-callback: arrows are not constructible, breaking `new` on mocks
- object-shorthand: rewrites source text asserted by a tracked reliability gate
- switch-case-braces: pushes ten files past max-lines, which cannot be suppressed
- no-useless-switch-case: drops `case undefined:` that switch-exhaustiveness-check needs
- arrow-body-style: 115 violations have no fix, and it breaks max-lines
- newline-after-import: false-positives on the leading-semicolon ASI idiom

electron-vite-output-contract asserted on the literal
Object.prototype.hasOwnProperty.call text; retarget it to Object.hasOwn, which
rejects inherited keys identically.
2026-08-11 18:19:43 -07:00

140 lines
4.2 KiB
TypeScript

import {
isMcpConfigInspectionFieldWithinLimit,
isMcpConfigInspectionNameWithinLimit,
MCP_CONFIG_INSPECTION_MAX_ENV_FIELDS
} from './mcp-config-inspection-limits'
import type { McpServerSummary, McpServerTransport } from './mcp-config'
const SENSITIVE_ENV_KEY_PATTERN =
/(api[_-]?key|auth|bearer|cookie|credential|password|private[_-]?key|secret|session|token)/i
const SENSITIVE_ENV_VALUE_PATTERN =
/(sk-[A-Za-z0-9_-]{12,}|gh[pousr]_[A-Za-z0-9_]{12,}|xox[baprs]-[A-Za-z0-9-]{12,})/
type BoundedString = { value?: string; oversized: boolean }
type BoundedEnv = { value?: Record<string, string>; oversized: boolean }
export function summarizeMcpServer(name: string, entry: unknown): McpServerSummary {
if (!entry || typeof entry !== 'object' || Array.isArray(entry)) {
return invalidServer(name, 'Server entry must be an object.')
}
const raw = entry as Record<string, unknown>
const command = readCommand(raw)
const url = readUrl(raw)
const env = inspectMcpEnv(raw.env)
if (command.oversized) {
return invalidServer(name, 'Command exceeds the MCP inspection field limit.')
}
if (url.oversized) {
return invalidServer(name, 'URL exceeds the MCP inspection field limit.')
}
if (env.oversized) {
return invalidServer(name, 'Environment exceeds the MCP inspection field limits.')
}
const transport = resolveTransport(raw, command.value, url.value)
const enabled = raw.enabled !== false && raw.disabled !== true
if (transport === 'unknown') {
return invalidServer(name, 'Missing command or URL.', env.value)
}
if (transport === 'http' && !url.value) {
return invalidServer(name, 'Missing URL.', env.value, transport)
}
if (transport === 'stdio' && !command.value) {
return invalidServer(name, 'Missing command.', env.value, transport)
}
return {
name,
transport,
status: enabled ? 'enabled' : 'disabled',
command: command.value,
url: url.value,
env: env.value
}
}
export function maskMcpEnv(env: unknown): Record<string, string> | undefined {
return inspectMcpEnv(env).value
}
function inspectMcpEnv(env: unknown): BoundedEnv {
if (!env || typeof env !== 'object' || Array.isArray(env)) {
return { oversized: false }
}
const masked: Record<string, string> = {}
let fields = 0
for (const key in env) {
if (!Object.hasOwn(env, key)) {
continue
}
fields += 1
if (
fields > MCP_CONFIG_INSPECTION_MAX_ENV_FIELDS ||
!isMcpConfigInspectionNameWithinLimit(key)
) {
return { oversized: true }
}
const rawValue = (env as Record<string, unknown>)[key]
const value = typeof rawValue === 'string' ? rawValue : String(rawValue)
if (!isMcpConfigInspectionFieldWithinLimit(value)) {
return { oversized: true }
}
masked[key] =
SENSITIVE_ENV_KEY_PATTERN.test(key) || SENSITIVE_ENV_VALUE_PATTERN.test(value)
? '••••••••'
: value
}
return { value: masked, oversized: false }
}
function readCommand(raw: Record<string, unknown>): BoundedString {
const value =
typeof raw.command === 'string'
? raw.command
: Array.isArray(raw.command) && typeof raw.command[0] === 'string'
? raw.command[0]
: undefined
return boundedString(value)
}
function readUrl(raw: Record<string, unknown>): BoundedString {
const value =
typeof raw.url === 'string'
? raw.url
: typeof raw.httpUrl === 'string'
? raw.httpUrl
: undefined
return boundedString(value)
}
function boundedString(value: string | undefined): BoundedString {
return value === undefined || isMcpConfigInspectionFieldWithinLimit(value)
? { value, oversized: false }
: { oversized: true }
}
function invalidServer(
name: string,
issue: string,
env?: Record<string, string>,
transport: McpServerTransport = 'unknown'
): McpServerSummary {
return { name, transport, status: 'invalid', env, issue }
}
function resolveTransport(
raw: Record<string, unknown>,
command: string | undefined,
url: string | undefined
): McpServerTransport {
if (raw.type === 'http' || raw.type === 'remote' || url) {
return 'http'
}
if (raw.type === 'local' || command) {
return 'stdio'
}
return 'unknown'
}