adding-api-scopes
БесплатноБез исполняемых скриптовНе проверенGuidance for adding an API scope object to the posthog/scopes/ package and making it work for personal API keys, OAuth tokens and MCP clients. Use when adding…
от PostHog★ 41 278 звёзд на GitHubОб этом скилле
Adding an API scope
A scope has two parts: an object and an action, as in feature_flag:read.
Adding a scope means adding a scope object, such as feature_flag. It gives tokens feature_flag:read and feature_flag:write.
posthog/scopes/catalog.py is the source of the object list. The posthog/scopes/__init__.py docstring says what each module of the package holds.
The frontend type and the MCP OAuth list are generated from it.
Each object a picker offers also has a ScopeDoc: its name, plural, one-sentence description, group, docs link, the levels a picker offers, whether it reaches the whole organization, and any scope its writes also need.
The owning product declares it in products/<name>/backend/scopes.py, and core objects are in CORE_SCOPE_DOCS in posthog/scope_docs.py.
The web app's API_SCOPES and API_SCOPE_GROUPS are built from those declarations, so the frontend keeps no copy.
Decide if you need a new scope
Most endpoints fit an existing scope, for example insight:read.
Add a new scope only for a product area that a person wants to grant or withhold on its own, on a key or an OAuth app.
Name its object with a snake_case singular noun, such as feature_flag.
Decide what kind of scope it is
- Public: OAuth lists it, MCP can request it, and the key picker offers it. This is the default.
- Internal: only the server creates tokens with it. Use
INTERNAL_API_SCOPE_OBJECTS. - OAuth-hidden: a person can paste it into a personal API key, but OAuth clients do not see it. Use this for staff-only or unreleased surfaces. Use
OAUTH_HIDDEN_SCOPE_OBJECTS. - Privileged: only PostHog staff can give it to an OAuth app, through Django admin or a data migration. An app that registers itself cannot get it, and the CLI login and the key picker presets never include it. Use this for a scope that a partner app must not grant to itself, such as
llm_gateway. UsePRIVILEGED_SCOPES. The picker row reads it from the generated scope docs.
Then decide two more things, separately from the kind:
- Project secret API keys: a project secret API key is a project credential with no user, for server-to-server calls. Allow the scope on it only when such a caller needs it. The allowed list is
PROJECT_SECRET_API_KEY_ALLOWED_API_SCOPE_ACTION, in bothposthog/scopes/project_secret_api_key.pyandfrontend/src/lib/scopes.tsx. Read/adding-project-secret-api-key-authfirst. - Access control: if an organization must be able to restrict the resource per role or per object, add it to
ACCESS_CONTROL_RESOURCESinproducts/access_control/backend/facade/user_access_control.py. Access control resources use scope object names by design, so a viewset'sscope_objectnames both its token scope and its access control resource. Do not give access control a naming or a type of its own. Theresourcefields of the access control serializers takeGRANTABLE_API_SCOPE_OBJECTSas their choices, and the frontendAPIScopeObjecttype is generated from those fields (be careful: the personal API key modal, the OAuth consent screen, CLI login and the key presets also use that type).
To add the scope
- Declare it in Python. Add the object to the
APIScopeObjectliteral inposthog/scopes/catalog.py. If you chose internal, OAuth-hidden or privileged above, also add it to that set inposthog/scopes/exposure.py.- Add the same value to
ResourceTypeinproducts/authorization/backend/facade/enums.py. The shared permission check names the scope with that type, so a scope without one returns a 500 on its endpoints.
- Add the same value to
- Connect it to its endpoints. Set
scope_object = "<object>"on each viewset the scope covers.- Standard actions need no extra work:
listandretrieveneed:read, andcreate,updateanddestroyneed:write. - A custom
@actionneedsrequired_scopes, for examplerequired_scopes=["<object>:write"]. Use:readif it only reads data, and:writeif it changes data. Without it, token requests get a 403. - An endpoint set to
scope_object = "INTERNAL"accepts only logged-in sessions. Change it to the new object to open it to tokens. - Then call each custom action with a personal API key that has only the new scope. No test checks this.
- Standard actions need no extra work:
- Regenerate. Run
hogli build:openapi, which carries the object to the frontend type, andhogli build:projections, which updates the OAuth lists of the MCP server and the web app. DO NOT EDIT GENERATED FILES BY HAND. - Explain it. Skip this step for an OAuth-hidden object: no picker shows it, and the tests do not ask for a doc or a group.
- Add a
ScopeDoctoSCOPE_DOCSinproducts/<name>/backend/scopes.py, or toCORE_SCOPE_DOCSfor a core object. Give it a sentence-case name, a plural that is lowercase except for proper nouns and acronyms, and one sentence under 120 characters on what the scope covers, without "read" or "write" (/writing-user-facing-copy). Link the
- Add a
Установить adding-api-scopes в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл adding-api-scopes?
Guidance for adding an API scope object to the posthog/scopes/ package and making it work for personal API keys, OAuth tokens and MCP clients. Use when adding a scope object, exposing a viewset or MCP tool to tokens, moving a viewset off scope_object = "INTERNAL", deciding if a scope is internal, OAuth-hidden or privileged, choosing a scope group, renaming or splitting a scope object, reading the scope list in Python, the frontend or the MCP server, or when a scope test fails in scopes.test.ts, test_scopes.py or tool-filtering.test.ts. Trigger terms: new scope, APIScopeObject, ScopeObjectEnumApi, scope_object, required_scopes, API_SCOPES, API_SCOPE_GROUPS, mcp scopes, OAuth scopes, personal API key scope.
Как установить скилл adding-api-scopes?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл adding-api-scopes запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic