MCPcopy Index your code
hub / github.com/ChinaSiro/claude-code-sourcemap / L15

Function L15

package/cli.js:16358–16383  ·  view source on GitHub ↗
(q)

Source from the content-addressed store, hash-verified

16356
16357`)}function arY(){rO({name:"claude-api",description:"Build apps with the Claude API or Anthropic SDK.\nTRIGGER when: code imports `anthropic`/`@anthropic-ai/sdk`/`claude_agent_sdk`, or user asks to use Claude API, Anthropic SDKs, or Agent SDK.\nDO NOT TRIGGER when: code imports `openai`/other AI SDK, general programming, or ML/data-science tasks.",allowedTools:["Read","Grep","Glob","WebFetch"],userInvocable:!0,async getPromptForCommand(q){let K=await Promise.resolve().then(() => (X15(),M15)),_=await irY();return[{type:"text",text:orY(_,q,K)}]}})}var nrY,W15='## Reference Documentation\n\nThe relevant documentation for your detected language is included below in `<doc>` tags. Each tag has a `path` attribute showing its original file path. Use this to find the right section:\n\n### Quick Task Reference\n\n**Single text classification/summarization/extraction/Q&A:**\n→ Refer to `{lang}/claude-api/README.md`\n\n**Chat UI or real-time response display:**\n→ Refer to `{lang}/claude-api/README.md` + `{lang}/claude-api/streaming.md`\n\n**Long-running conversations (may exceed context window):**\n→ Refer to `{lang}/claude-api/README.md` — see Compaction section\n\n**Prompt caching / optimize caching / "why is my cache hit rate low":**\n→ Refer to `shared/prompt-caching.md` + `{lang}/claude-api/README.md` (Prompt Caching section)\n\n**Function calling / tool use / agents:**\n→ Refer to `{lang}/claude-api/README.md` + `shared/tool-use-concepts.md` + `{lang}/claude-api/tool-use.md`\n\n**Batch processing (non-latency-sensitive):**\n→ Refer to `{lang}/claude-api/README.md` + `{lang}/claude-api/batches.md`\n\n**File uploads across multiple requests:**\n→ Refer to `{lang}/claude-api/README.md` + `{lang}/claude-api/files-api.md`\n\n**Agent with built-in tools (file/web/terminal) (Python & TypeScript only):**\n→ Refer to `{lang}/agent-sdk/README.md` + `{lang}/agent-sdk/patterns.md`\n\n**Error handling:**\n→ Refer to `shared/error-codes.md`\n\n**Latest docs via WebFetch:**\n→ Refer to `shared/live-sources.md` for URLs';var Z15=y(()=>{I7();WT();nrY={python:[".py","requirements.txt","pyproject.toml","setup.py","Pipfile"],typescript:[".ts",".tsx","tsconfig.json","package.json"],java:[".java","pom.xml","build.gradle"],go:[".go","go.mod"],ruby:[".rb","Gemfile"],csharp:[".cs",".csproj"],php:[".php","composer.json"],curl:[]}});function G15(){r65(),b65(),A85(),R65(),m65(),Q65(),B65(),F65(),N65(),c65();{let{registerLoopSkill:q}=(j85(),Eq(w85));q()}{let{registerScheduleRemoteAgentsSkill:q}=(X85(),Eq(M85));q()}{let{registerClaudeApiSkill:q}=(Z15(),Eq(f15));q()}if(xS6())E65()}var T15=y(()=>{WJ6();y65();L65();h65();x65();p65();g65();U65();d65();l65();o65();O85()});import{stat as srY}from"fs/promises";import{homedir as trY}from"os";import{join as v15,sep as erY}from"path";function V15(q){let K=[`This session was opened by an external deep link in ${_oY(q.cwd)}`];if(q.repo){let _=q.lastFetch?Kh(q.lastFetch):"never",z=!q.lastFetch||Date.now()-q.lastFetch.getTime()>qoY;K.push(`Resolved ${q.repo} from local clones · last fetched ${_}${z?" — CLAUDE.md may be stale":""}`)}if(q.prefillLength)K.push(q.prefillLength>KoY?`The prompt below (${mK(q.prefillLength)} chars) was supplied by the link — scroll to review the entire prompt before pressing Enter.`:"The prompt below was supplied by the link — review carefully before pressing Enter.");return K.join(`
16358`)}async function N15(q){let K=await Ap6(q);if(!K)return;let _=await ex(K),[z,Y]=await Promise.all([k15(v15(K,"FETCH_HEAD")),_?k15(v15(_,"FETCH_HEAD")):Promise.resolve(void 0)]);if(z&&Y)return z>Y?z:Y;return z??Y}async function k15(q){try{let{mtime:K}=await srY(q);return K}catch{return}}function _oY(q){let K=trY();if(q===K)return"~";if(q.startsWith(K+erY))return"~"+q.slice(K.length);return q}var qoY=604800000,KoY=1000;var mA7=y(()=>{U7();Hl();E5()});async function y15(q,K){let _=await NC(q),z=Dk8(K);for(let Y of _){if(Y.type!=="prompt")continue;d("tengu_skill_loaded",{_PROTO_skill_name:Y.name,skill_source:Y.source,skill_loaded_from:Y.loadedFrom,skill_budget:z,...Y.kind&&{skill_kind:Y.kind}})}}var E15=y(()=>{yA();k8();yO6()});function o3(q){if(q)console.error(q);process.exit(1);return}function gA(q){if(q)process.stdout.write(q+`
16359`);process.exit(0);return}function L15(q){q.command("add <name> <commandOrUrl> [args...]").description(`Add an MCP server to Claude Code.
16360
16361Examples:
16362 # Add HTTP server:
16363 claude mcp add --transport http sentry https://mcp.sentry.dev/mcp
16364
16365 # Add HTTP server with headers:
16366 claude mcp add --transport http corridor https://app.corridor.dev/api/mcp --header "Authorization: Bearer ..."
16367
16368 # Add stdio server with environment variables:
16369 claude mcp add -e API_KEY=xxx my-server -- npx my-mcp-server
16370
16371 # Add stdio server with subprocess flags:
16372 claude mcp add my-server -- my-command --some-flag arg1`).option("-s, --scope <scope>","Configuration scope (local, user, or project)","local").option("-t, --transport <transport>","Transport type (stdio, sse, http). Defaults to stdio if not specified.").option("-e, --env <env...>","Set environment variables (e.g. -e KEY=value)").option("-H, --header <header...>",'Set WebSocket headers (e.g. -H "X-Api-Key: abc123" -H "X-Custom: value")').option("--client-id <clientId>","OAuth client ID for HTTP/SSE servers").option("--client-secret","Prompt for OAuth client secret (or set MCP_CLIENT_SECRET env var)").option("--callback-port <port>","Fixed port for OAuth callback (for servers requiring pre-registered redirect URIs)").helpOption("-h, --help","Display help for command").addOption(new G3("--xaa","Enable XAA (SEP-990) for this server. Requires 'claude mcp xaa setup' first. Also requires --client-id and --client-secret (for the MCP server's AS).").hideHelp(!ir())).action(async(K,_,z,Y)=>{let $=_,A=z;if(!K)o3(`Error: Server name is required.
16373Usage: claude mcp add <name> <command> [args...]`);else if(!$)o3(`Error: Command is required when server name is provided.
16374Usage: claude mcp add <name> <command> [args...]`);try{let O=XN6(Y.scope),w=yR4(Y.transport);if(Y.xaa&&!ir())o3("Error: --xaa requires CLAUDE_CODE_ENABLE_XAA=1 in your environment");let j=Boolean(Y.xaa);if(j){let M=[];if(!Y.clientId)M.push("--client-id");if(!Y.clientSecret)M.push("--client-secret");if(!RU())M.push("'claude mcp xaa setup' (settings.xaaIdp not configured)");if(M.length)o3(`Error: --xaa requires: ${M.join(", ")}`)}let H=Y.transport!==void 0,J=$.startsWith("http://")||$.startsWith("https://")||$.startsWith("localhost")||$.endsWith("/sse")||$.endsWith("/mcp");if(d("tengu_mcp_add",{type:w,scope:O,source:"command",transport:w,transportExplicit:H,looksLikeUrl:J}),w==="sse"){if(!$)o3("Error: URL is required for SSE transport.");let M=Y.header?SB1(Y.header):void 0,X=Y.callbackPort?parseInt(Y.callbackPort,10):void 0,P=Y.clientId||X||j?{...Y.clientId?{clientId:Y.clientId}:{},...X?{callbackPort:X}:{},...j?{xaa:!0}:{}}:void 0,W=Y.clientSecret&&Y.clientId?await ja6():void 0,D={type:"sse",url:$,headers:M,oauth:P};if(await xq6(K,D,O),W)Ha6(K,D,W);if(process.stdout.write(`Added SSE MCP server ${K} with URL: ${$} to ${O} config
16375`),M)process.stdout.write(`Headers: ${g6(M,null,2)}
16376`)}else if(w==="http"){if(!$)o3("Error: URL is required for HTTP transport.");let M=Y.header?SB1(Y.header):void 0,X=Y.callbackPort?parseInt(Y.callbackPort,10):void 0,P=Y.clientId||X||j?{...Y.clientId?{clientId:Y.clientId}:{},...X?{callbackPort:X}:{},...j?{xaa:!0}:{}}:void 0,W=Y.clientSecret&&Y.clientId?await ja6():void 0,D={type:"http",url:$,headers:M,oauth:P};if(await xq6(K,D,O),W)Ha6(K,D,W);if(process.stdout.write(`Added HTTP MCP server ${K} with URL: ${$} to ${O} config
16377`),M)process.stdout.write(`Headers: ${g6(M,null,2)}
16378`)}else{if(Y.clientId||Y.clientSecret||Y.callbackPort||Y.xaa)process.stderr.write(`Warning: --client-id, --client-secret, --callback-port, and --xaa are only supported for HTTP/SSE transports and will be ignored for stdio.
16379`);if(!H&&J)process.stderr.write(`
16380Warning: The command "${$}" looks like a URL, but is being interpreted as a stdio server as --transport was not specified.
16381`),process.stderr.write(`If this is an HTTP server, use: claude mcp add --transport http ${K} ${$}
16382`),process.stderr.write(`If this is an SSE server, use: claude mcp add --transport sse ${K} ${$}
16383`);let M=Bj7(Y.env);await xq6(K,{type:"stdio",command:$,args:A,env:M},O),process.stdout.write(`Added stdio MCP server ${K} with command: ${$} ${A.join(" ")} to ${O} config
16384`)}gA(`File modified: ${xG(O)}`)}catch(O){o3(O.message)}})}var R15=y(()=>{a_7();k8();or();f0();NJ();Oa6();m8();l8()});function h15(q){let K=q.command("xaa").description("Manage the XAA (SEP-990) IdP connection");K.command("setup").description("Configure the IdP connection (one-time setup for all XAA-enabled servers)").requiredOption("--issuer <url>","IdP issuer URL (OIDC discovery)").requiredOption("--client-id <id>","Claude Code's client_id at the IdP").option("--client-secret","Read IdP client secret from MCP_XAA_IDP_CLIENT_SECRET env var").option("--callback-port <port>","Fixed loopback callback port (only if IdP does not honor RFC 8252 port-any matching)").action((_)=>{let z;try{z=new URL(_.issuer)}catch{return o3(`Error: --issuer must be a valid URL (got "${_.issuer}")`)}if(z.protocol!=="https:"&&!(z.protocol==="http:"&&(z.hostname==="localhost"||z.hostname==="127.0.0.1"||z.hostname==="[::1]")))return o3(`Error: --issuer must use https:// (got "${z.protocol}//${z.host}")`);let Y=_.callbackPort?parseInt(_.callbackPort,10):void 0;if(Y!==void 0&&(!Number.isInteger(Y)||Y<=0))return o3("Error: --callback-port must be a positive integer");let $=_.clientSecret?process.env.MCP_XAA_IDP_CLIENT_SECRET:void 0;if(_.clientSecret&&!$)return o3("Error: --client-secret requires MCP_XAA_IDP_CLIENT_SECRET env var");let A=RU(),O=A?.issuer,w=A?.clientId,{error:j}=W7("userSettings",{xaaIdp:{issuer:_.issuer,clientId:_.clientId,callbackPort:Y}});if(j)return o3(`Error writing settings: ${j.message}`);if(O){if(rr(O)!==rr(_.issuer))mq6(O),wE8(O);else if(w!==_.clientId)mq6(O),wE8(O)}if($){let{success:H,warning:J}=IR4(_.issuer,$);if(!H)return o3(`Error: settings written but keychain save failed${J?` — ${J}`:""}. Re-run with --client-secret once keychain is available.`)}gA(`XAA IdP connection configured for ${_.issuer}`)}),K.command("login").description("Cache an IdP id_token so XAA-enabled MCP servers authenticate silently. Default: run the OIDC browser login. With --id-token: write a pre-obtained JWT directly (used by conformance/e2e tests where the mock IdP does not serve /authorize).").option("--force","Ignore any cached id_token and re-login (useful after IdP-side revocation)").option("--id-token <jwt>","Write this pre-obtained id_token directly to cache, skipping the OIDC browser login").action(async(_)=>{let z=RU();if(!z)return o3("Error: no XAA IdP connection. Run 'claude mcp xaa setup' first.");if(_.idToken){let $=xR4(z.issuer,_.idToken);return gA(`id_token cached for ${z.issuer} (expires ${new Date($).toISOString()})`)}if(_.force)mq6(z.issuer);if(hw6(z.issuer)!==void 0)return gA(`Already logged in to ${z.issuer} (cached id_token still valid). Use --force to re-login.`);process.stdout.write(`Opening browser for IdP login at ${z.issuer}…
16385`);try{await HE8({idpIssuer:z.issuer,idpClientId:z.clientId,idpClientSecret:PN6(z.issuer),callbackPort:z.callbackPort,onAuthorizationUrl:($)=>{process.stdout.write(`If the browser did not open, visit:
16386 ${$}

Callers 1

fsYFunction · 0.85

Calls 15

irFunction · 0.85
o3Function · 0.85
XN6Function · 0.85
yR4Function · 0.85
RUFunction · 0.85
dFunction · 0.85
SB1Function · 0.85
ja6Function · 0.85
xq6Function · 0.85
Ha6Function · 0.85
g6Function · 0.85
Bj7Function · 0.85

Tested by

no test coverage detected