Skill + CLI over MCP: Replacing Sentry MCP with a multi-profile CLI wrapper

2026-02-22 12:38 (3 hours ago) ytyng

Background

I wanted to use Sentry's CLI tool sentry-cli across multiple organizations, but it lacks native multi-profile support like AWS CLI's --profile.

Installing sentry-cli

brew install getsentry/tools/sentry-cli

Configuration Priority

According to the official docs, configuration is loaded in this priority:

  1. Command-line arguments (-o, -p, --auth-token)
  2. Environment variables (SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT)
  3. .sentryclirc file (searched upward from current directory)
  4. ~/.sentryclirc (global default)

The .sentryclirc filename is fixed — renamed files like .sentryclirc-staging won't be loaded (ref).

What About Sentry MCP Server?

Sentry provides an MCP server for direct AI agent integration with Sentry. However, it has several drawbacks:

In the end, a CLI wrapper + AI agent skill is a lighter and more flexible approach.

Solution: zsh Wrapper Function

A zsh function always takes priority over a same-named binary in PATH, so defining a function called sentry-cli automatically wraps the brew-installed binary.

Profile Storage

~/.config/sentry-cli/profiles/<name>.env

Simple env file format:

SENTRY_AUTH_TOKEN=sntrys_xxx...
SENTRY_ORG=my-org
SENTRY_URL=https://my-org.sentry.io/

SENTRY_PROJECT should not be fixed in the profile — specify it with -p at runtime since orgs typically contain multiple projects.

The Wrapper Function

Add this to your ~/.zshrc or shell aliases file:

function sentry-cli () {
  local _sentry_cli
  # whence -p: skip functions, return only binary paths
  _sentry_cli=$(whence -p sentry-cli) || { echo "sentry-cli not found" >&2; return 1; }
  local profile_dir="${HOME}/.config/sentry-cli/profiles"
  local profile=""
  local setup=0
  local args=()

  while [[ $# -gt 0 ]]; do
    case "$1" in
      --profile=*) profile="${1#--profile=}"; shift ;;
      --profile)   profile="$2"; shift 2 ;;
      --profiles)
        if [[ -d "$profile_dir" ]]; then
          for f in "$profile_dir"/*.env(N); do echo "${f:t:r}"; done
        else
          echo "No profiles directory: $profile_dir" >&2
        fi
        return 0 ;;
      --setup) setup=1; shift ;;
      *) args+=("$1"); shift ;;
    esac
  done

  if [[ $setup -eq 1 ]]; then
    [[ -z "$profile" ]] && { echo "Usage: sentry-cli --profile=<name> --setup" >&2; return 1; }
    mkdir -p "$profile_dir"
    local pfile="${profile_dir}/${profile}.env"
    if [[ ! -f "$pfile" ]]; then
      cat > "$pfile" <<TMPL
SENTRY_AUTH_TOKEN=
SENTRY_ORG=${profile}
SENTRY_URL=https://${profile}.sentry.io/
TMPL
    fi
    ${EDITOR:-vim} "$pfile"
    return 0
  fi

  if [[ -z "$profile" ]]; then
    "$_sentry_cli" "${args[@]}"
    return $?
  fi

  local pfile="${profile_dir}/${profile}.env"
  [[ ! -f "$pfile" ]] && { echo "Profile not found: $pfile" >&2; return 1; }

  # Run in subshell to avoid polluting current environment
  ( set -a; source "$pfile"; set +a; "$_sentry_cli" "${args[@]}" )
}

Gotcha: The command -v Trap

My initial implementation used command -v sentry-cli to find the binary path, but zsh's command -v also returns functions — causing infinite recursion and the dreaded maximum nested function level reached; increase FUNCNEST? error.

Use whence -p instead, which skips functions and returns only binary paths. This is a zsh built-in.

Usage

# Create a profile (opens editor)
sentry-cli --profile=myorg --setup

# Check connection
sentry-cli --profile=myorg info

# List projects
sentry-cli --profile=myorg projects list

# List releases for a specific project
sentry-cli --profile=myorg releases list -p my-project

# List all profiles
sentry-cli --profiles

# Without profile (normal sentry-cli passthrough)
sentry-cli info

Registering as a Claude Code Skill

I also registered this wrapper as a Claude Code skill with a SKILL.md file, enabling the AI agent to naturally use sentry-cli --profile=xxx for Sentry operations.

Here's the full skill definition:

---
name: sentry-cli
description: Multi-profile wrapper for Sentry CLI. Release management, sourcemap uploads, event sending, etc.
allowed-tools: Bash(sentry-cli:*)
---

# Sentry CLI (multi-profile wrapper)

A zsh wrapper for using Sentry CLI with multiple profiles.

## Important: Check help before operations

If unsure about subcommands or arguments, read the help first.

  sentry-cli --help
  sentry-cli <subcommand> --help

## Profile Management

- Create/edit: sentry-cli --profile=<name> --setup
- List profiles: sentry-cli --profiles
- Run with profile: sentry-cli --profile=<name> <subcommand> [options]
- Run without profile: sentry-cli <subcommand> [options]

## Common Subcommands

- info: Check connection and auth status
- releases: List, create, finalize releases
- sourcemaps: Upload sourcemaps
- send-event: Send test events
- deploys: Record deployments
- issues: List and resolve issues
- projects: List projects

Key design decisions:

Summary

Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.

Archive

2026
2025
2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011