Route stdio MCP tool calls to the stored account that knows the org
Maintainer thường phản hồi trong vòng 1 ngày
Một pull request liên quan đã được merge.
- #1802 của @sentry-junior — đã merge
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 38/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- node.js, typescript
- Lĩnh vực
- api, authentication, cli
Hướng nghiên cứu
Start with the dependency-direction rule in AGENTS.md, then read ServerContext in packages/mcp-core/src/types.ts, apiServiceFromContext(), and the CLI host in packages/cli/src/lib/mcp.ts. Trace selectAccountForOrg in packages/cli/src/lib/db/auth.ts and region handling in packages/cli/src/lib/region.ts and internal/tool-helpers/resolve-region-url.ts. Run the relevant MCP and CLI tests; done means org-scoped calls use the owning account safely, cross-org tools merge results, and hosted/static-token behavior remains unchanged.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Problem
The CLI stores several accounts and picks the right one for each command based on the targeted organization (selectAccountForOrg in packages/cli/src/lib/db/auth.ts, called from resolveOrgRegion in packages/cli/src/lib/region.ts). The stdio MCP server (@sentry/mcp-server and sentry mcp, which share the CLI's credential store after #1731) does not.
The server resolves one effective account at startup and uses it for every tool call. A token refresh after a 401 stays on that same account. Asking about an org that belongs to another stored login fails. The only workarounds are sentry auth switch plus a restart, or configuring a second MCP server with a different SENTRY_HOST or a static SENTRY_ACCESS_TOKEN.
Why it doesn't work today
ServerContextin mcp-core carries a singleaccessToken: string(packages/mcp-core/src/types.ts). All tools build their API client withapiServiceFromContext()(about 63 call sites), and the region cache (internal/tool-helpers/resolve-region-url.ts) reads the same token.- MCP tools use mcp-core's API client, not the CLI's, so the CLI's org-based selection never runs.
- mcp-core must not import the CLI (see the dependency-direction rule in
AGENTS.md), and the hosted MCP has one OAuth grant per session. So this has to be an optional capability that only the stdio host provides.
Proposed approach
- mcp-core: add an optional resolver to
ServerContext, e.g.resolveCredential({ organizationSlug }) => Promise<{ accessToken, sentryHost, sentryProtocol }>.apiServiceFromContext()takes the org and uses the resolver when present; otherwise it usesaccessToken. Key the region cache by the resolved credential. The hosted MCP stays unchanged. - CLI host (
packages/cli/src/lib/mcp.ts): implement the resolver with theselectAccountForOrgrules, running each call insidewithStoredAccount(). That function already isolates account scope per call throughwithEnvand AsyncLocalStorage, so overlapping tool calls are safe. Refresh-on-401 targets the account that made the call. An unknown org falls back to the active account. One tool call never mixes identities. - Cross-org tools (
find_organizations,whoami): query every usable account and merge the results, assentry org listdoes withlistUsableAccountsInScope(). The CLI already records which account saw each org in the regions cache (packages/cli/src/lib/db/regions.ts), so later calls route automatically. - Opt-outs and pins:
--access-token/SENTRY_ACCESS_TOKENdisables routing.--organization-slugpicks the account once at startup. An explicit server (SENTRY_HOST/SENTRY_URL) limits candidates to accounts on that server, matching the CLI.
An alternative would route inside an injected fetch by parsing /organizations/{slug}/ from request URLs. It touches fewer files, but it is implicit and misses endpoints whose paths do not include the org. The explicit resolver is preferred.
Scope
- First version: route only between accounts on the same server.
- Later: mixing self-hosted and sentry.io accounts in one server needs a host per account and the region-URL validation (
validateRegionUrl) checked against the right server.
Acceptance
- With two stored sentry.io accounts that each own a different org, one running stdio server can call org-scoped tools on both orgs without
auth switchor a restart. find_organizationslists orgs from all usable accounts.- A 401 refreshes only the account that made the call.
- The hosted MCP and static-token setups behave as before.
- Tests cover concurrent tool calls for different orgs and verify that each call sends its own account's token.
Related
- #1731:
@sentry/mcp-serveras a slim bundle that shares CLI auth (prerequisite) - #1669: shared API layer proposal; task group 11 (task 11.4, CLI capabilities injected into mcp-core) is the natural home
- #1396: CLI multi-account mode (done)
- #845: earlier
--profilerequest for the stdio transport, closed as not planned; this approach needs no per-process profiles
via BYK.
--
- Ngôn ngữ chính
- TypeScript
- Star
- 949
- Fork
- 171
- Merge trung bình
- 1 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 284
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của getsentry/toolkit
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
getsentry/toolkit#1844 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Docs MCP URL normalization retains query strings and fragmentsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởbug MCP
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
getsentry/toolkit#1618 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
getsentry/toolkit#1471 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
No way to create a cron monitor, so agents send users to the UICó thể đã có người làm @Chipagosfinest đã nhận hôm nay. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 15/100
getsentry/toolkit#1845 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Generate CLI output schemas from command output typesCó thể đã có người làm @sentry-junior đã nhận hôm nay. Đang mởCLI
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 12/100
getsentry/toolkit#1824 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của getsentry/toolkit
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
pingdotgg/t3code#30228 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
ci-cd desktop size:low telemetry-improvement telemetry-round-1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
vfarcic/dot-agent-deck#2079 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Broken links in the docsĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày