MCPcopy
hub / github.com/upstash/context7 / setupAgent

Function setupAgent

packages/cli/src/commands/setup.ts:293–385  ·  view source on GitHub ↗
(
  agentName: SetupAgent,
  auth: AuthOptions,
  transport: Transport,
  scope: Scope
)

Source from the content-addressed store, hash-verified

291}
292
293async function setupAgent(
294 agentName: SetupAgent,
295 auth: AuthOptions,
296 transport: Transport,
297 scope: Scope
298): Promise<{
299 agent: string;
300 mcpStatus: string;
301 mcpPath: string;
302 ruleStatus: string;
303 rulePath: string;
304 skillStatus: string;
305 skillPath: string;
306}> {
307 const agent = getAgent(agentName);
308
309 const mcpCandidates =
310 scope === "global" || agent.mcp.projectPaths.length === 0
311 ? agent.mcp.globalPaths
312 : agent.mcp.projectPaths.map((p) => join(process.cwd(), p));
313 const mcpPath = await resolveMcpPath(mcpCandidates);
314
315 let mcpStatus: string;
316 try {
317 if (mcpPath.endsWith(".toml")) {
318 const existingTomlEntry =
319 transport === "stdio" ? await readTomlServerEntry(mcpPath, "context7") : undefined;
320 const entry = resolveEntryToWrite(agent, auth, transport, existingTomlEntry);
321 const { alreadyExists } = await appendTomlServer(mcpPath, "context7", entry);
322 mcpStatus = alreadyExists
323 ? `reconfigured with ${AUTH_MODE_LABELS[auth.mode]}`
324 : `configured with ${AUTH_MODE_LABELS[auth.mode]}`;
325 } else {
326 const existing = await readJsonConfig(mcpPath);
327 const existingJsonEntry =
328 transport === "stdio"
329 ? getJsonServerEntry(existing, agent.mcp.configKey, "context7")
330 : undefined;
331 const entry = resolveEntryToWrite(agent, auth, transport, existingJsonEntry);
332 const { config, alreadyExists } = mergeServerEntry(
333 existing,
334 agent.mcp.configKey,
335 "context7",
336 entry
337 );
338 mcpStatus = alreadyExists
339 ? `reconfigured with ${AUTH_MODE_LABELS[auth.mode]}`
340 : `configured with ${AUTH_MODE_LABELS[auth.mode]}`;
341 await writeJsonConfig(mcpPath, config);
342 }
343 } catch (err) {
344 mcpStatus = `failed: ${err instanceof Error ? err.message : String(err)}`;
345 }
346
347 let ruleStatus: string;
348 let rulePath: string;
349 try {
350 const result = await installRule(agentName, "mcp", scope);

Callers 1

setupMcpFunction · 0.85

Calls 12

getAgentFunction · 0.85
resolveMcpPathFunction · 0.85
readTomlServerEntryFunction · 0.85
resolveEntryToWriteFunction · 0.85
appendTomlServerFunction · 0.85
readJsonConfigFunction · 0.85
getJsonServerEntryFunction · 0.85
mergeServerEntryFunction · 0.85
writeJsonConfigFunction · 0.85
installRuleFunction · 0.85
downloadSkillFunction · 0.85
installSkillFilesFunction · 0.85

Tested by

no test coverage detected