@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
61 lines • 2.4 kB
JavaScript
import { openBrowser } from "../../../../../utils/open-browser.js";
import { createMcpLogger } from "../log.js";
import { runAuth, runAuthComplete, runAuthStart, runLogout } from "./commands-auth.js";
// Bridges the /mcp slash command to the pure auth flow runners in
// commands-auth.ts, sourcing config/agentDir/env from the running service.
export async function handleMcpAuthCommand(subcommand, args, ctx, pi, service) {
const name = args[0] ?? "";
const target = service.getAuthTarget(name);
if (name.length === 0 || target === undefined) {
ctx.ui.notify(`Unknown MCP server: ${name || "<missing>"}`, "error");
return;
}
const deps = {
agentDir: target.agentDir,
callbackUrl: target.callbackUrl,
config: target.config,
env: target.env,
hasUI: ctx.hasUI,
logger: createMcpLogger(name),
notify: (message, type) => {
if (ctx.hasUI)
pi.appendEntry("mcp-auth", message);
else
ctx.ui.notify(message, type);
},
onReconnect: async () => {
try {
await service.reconnectServer(name);
}
catch {
// A needs_auth/degraded state after logout is expected; status shows it.
}
await service.attachSession({ type: "session_start", reason: "reload" }, ctx, pi).catch(() => undefined);
},
openBrowser: (url) => openBrowser(url.toString()),
pending: service.getPendingAuth(),
interactiveGuard: {
begin: (serverName) => service.beginInteractiveAuth(serverName),
end: (serverName) => service.endInteractiveAuth(serverName),
},
serverName: name,
};
if (subcommand === "auth")
return runAuth(deps);
if (subcommand === "auth-start") {
await runAuthStart(deps);
return;
}
if (subcommand === "auth-complete") {
const redirect = args[1] ?? "";
if (redirect.length === 0) {
ctx.ui.notify(`Usage: /mcp auth-complete ${name} <redirect-url>`, "error");
return;
}
return runAuthComplete(deps, redirect);
}
if (subcommand === "logout")
return runLogout(deps);
ctx.ui.notify(`Unknown MCP auth subcommand: ${subcommand}`, "error");
}
//# sourceMappingURL=commands-auth-dispatch.js.map