Skip to content

The platform for continuously improving AI agents.

Make create_api_key project optional. (#233)

Pritam Soni809e22a9d50f
diff --git a/.agents/skills/backend-architecture/SKILL.md b/.agents/skills/backend-architecture/SKILL.md
index fd805afb..04d8ea14 100644
--- a/.agents/skills/backend-architecture/SKILL.md
+++ b/.agents/skills/backend-architecture/SKILL.md
@@ -140,7 +140,7 @@ Clerk when `CLERK_API_SECRET_KEY` is set; blank secret is self-hosted local JWT
- Console: `VITE_SELF_HOSTED=true` and a blank `VITE_CLERK_PUBLISHABLE_KEY` skip `ClerkProvider` and show the local login form; otherwise Clerk.
- Project invites: with Clerk, an invitation email is sent; without Clerk the `ProjectInvite` row is stored and claimed on first local (or Clerk) sign-in for that email.
- Commercial billing (remaining-credit 402s, the Free seat limit, Stripe Checkout) injects when `STRIPE_SECRET_KEY` is set (`overbae/services/billing_provider.py`). Ledger charges always run. Empty key → uncapped OSS: spend is recorded and shown, gates and grants no-op.
-- API keys are either `scope=account` (every project the user belongs to) or `scope=project` with one `resourceIds` entry. Creating a key with `project` always mints project scope. REST and MCP `create_api_key` share `APIToken.create_for_user` and accept the Console dialog's name, description and expiry (30, 90, 180, 365 days, or 0 for never). The plaintext is returned once. A project-scoped credential cannot mint an account key.
+- API keys are either `scope=account` (every project the user belongs to) or `scope=project` with one `resourceIds` entry. Creating a key with `project` always mints project scope. REST and MCP `create_api_key` share `APIToken.create_for_user` and accept the Console dialog's name, description and expiry (30, 90, 180, 365 days, or 0 for never). MCP omits `project_id` for an account key and passes it for a project key. The plaintext is returned once. A project-scoped credential cannot mint an account key.
## Training preparation
diff --git a/.agents/skills/mcp/SKILL.md b/.agents/skills/mcp/SKILL.md
index 97ab2b3e..eaa539fc 100644
--- a/.agents/skills/mcp/SKILL.md
+++ b/.agents/skills/mcp/SKILL.md
@@ -6,10 +6,11 @@ description: End-to-end workflow for adding or changing Overmind MCP tools, reso
# Adding or changing MCP
Contract 7.12.0 adds `create_api_key`. It accepts the Console dialog's name,
-description, expiry (30, 90, 180 or 365 days, or 0 for never) and project or
-account scope. The plaintext is returned only in that response. A project
-connection can mint a key only for its own project. An account connection can
-mint either scope. Guests cannot create keys. The secret is not readable again.
+description and expiry (30, 90, 180 or 365 days, or 0 for never). Omit
+`project_id` for an account key; pass `project_id` for a project key. The
+plaintext is returned only in that response. A project connection can mint a
+key only for its own project. An account connection can mint either scope.
+Guests cannot create keys. The secret is not readable again.
Contract 7.11.0 removes automatic OCR language detection. `ocr_languages=[]`
uses English; explicit language choices remain MCP-ready through `update_dataset`.
diff --git a/AGENTS.md b/AGENTS.md
index 70dbae81..c01df1f3 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -59,7 +59,7 @@ Each line is the invariant; the named skill section carries the mechanics.
- Datasets are sources and step-by-step chains of cells; displayed versions are derived. Native agents must upload retained Python packages and save immutable project-level revisions with `save_dataset_pipeline(package=...)`; inline operations are not accepted and package-free historical revisions are read-only. They reuse them across compatible project sources, or save attributed `derived_from` variants. Packages execute only in the isolated sandbox service through interactive workers, never API/Celery Python; external imports remain lineage-bound and attributed. Preview does not publish. Successful runs atomically append one cell per step; failures and cancellation preserve readable source and consumer versions. Explicitly enabled bindings rebuild source snapshots with a pinned revision and commit checkpoints with publication. Shared REST/MCP services own metadata, request-key conflicts, provenance and measured impact. Semantic quality stays unmeasured without attributable evidence; technical compatibility is not semantic correctness. Preserve probability targets, option order, weights, duplicates, blank states and declared groups. `use.use(dataset, intent, cell=)` freezes exact versions. Training pins train/validation/eval cells atomically and performs model-specific preprocessing only. Modal preparation transfers compressed sources once, verifies ordered row fingerprints and reuses the exact token artifact. Detail: data-workshop skill; backend-architecture § Training preparation.
-- Tenancy is project-scoped, no org layer. Auth is Clerk when `CLERK_API_SECRET_KEY` is set; blank secret plus Console `VITE_SELF_HOSTED=true` uses local JWT: email/password (`POST /api/auth/local/`, create-on-first-use, no verification) only. ChatGPT login, account linking and credentials are removed. A guest holds one project and can only read and claim; a view that accepts guest writes opts in with `guest_allowed = True` — never a permission class or middleware. API keys are `scope=account` or `scope=project`. MCP `create_api_key` mints one with the Console dialog's name, description, expiry (30, 90, 180, 365 days or never) and project or account scope; the plaintext is returned once, and a project key cannot mint an account key. Detail: backend-architecture § Auth and tenancy.
+- Tenancy is project-scoped, no org layer. Auth is Clerk when `CLERK_API_SECRET_KEY` is set; blank secret plus Console `VITE_SELF_HOSTED=true` uses local JWT: email/password (`POST /api/auth/local/`, create-on-first-use, no verification) only. ChatGPT login, account linking and credentials are removed. A guest holds one project and can only read and claim; a view that accepts guest writes opts in with `guest_allowed = True` — never a permission class or middleware. API keys are `scope=account` or `scope=project`. MCP `create_api_key` mints one with the Console dialog's name, description and expiry (30, 90, 180, 365 days or never). Omitting `project_id` mints an account key; passing it mints a project key. The plaintext is returned once, and a project key cannot mint an account key. Detail: backend-architecture § Auth and tenancy.
- Compute estimates use live provider rates with fetch timestamps and durable worker usage receipts; they never create ledger charges. Training forecasts use compatible completed execution measurements, with evidence, uncertainty and missing components explicit. Current GPU hourly rates remain visible when duration and total cost are unmeasured; one quote uses one fetched rate snapshot. Native progress reports elapsed time and a remaining-time range rather than a single countdown or finish timestamp. Detail: backend-architecture § Native decision training.
diff --git a/overbae/services/mcp/contracts/projects.py b/overbae/services/mcp/contracts/projects.py
index d7e4a356..7f0a99ee 100644
--- a/overbae/services/mcp/contracts/projects.py
+++ b/overbae/services/mcp/contracts/projects.py
@@ -16,7 +16,7 @@ class CreateApiKeyInput(MCPModel):
name: str = Field(default="", max_length=255)
description: str = Field(default="", max_length=2_000)
expires_in_days: ExpiryDays = 365
- project_scoped: bool = True
+ project_id: str | None = None
class CreateApiKeyOutput(MCPModel):
diff --git a/overbae/services/mcp/tools_projects.py b/overbae/services/mcp/tools_projects.py
index 51110b99..f9ab587c 100644
--- a/overbae/services/mcp/tools_projects.py
+++ b/overbae/services/mcp/tools_projects.py
@@ -1,3 +1,5 @@
+from uuid import UUID
+
from asgiref.sync import sync_to_async
from django.conf import settings
from pydantic import BaseModel, ConfigDict, Field
@@ -57,21 +59,38 @@ def list_projects(payload, context):
)
-def _create_api_key(payload: CreateApiKeyInput, context) -> CreateApiKeyOutput:
- if context.user.is_guest:
- raise MCPError("permission_denied", "Create an account to continue.")
- if context.project is None:
- raise MCPError("project_required", "Pass project_id from list_projects for this operation.")
+def _key_project(payload: CreateApiKeyInput, context):
scope = context.token.scope if isinstance(context.token.scope, dict) else {}
- if not payload.project_scoped and scope.get("scope") != "account":
+ account = scope.get("scope") == "account"
+ if payload.project_id is None:
+ if account:
+ return None
+ raise MCPError(
+ "permission_denied",
+ "A project API key can only create a key for its own project.",
+ )
+ if not account and str(payload.project_id) != str(context.project.id):
raise MCPError(
"permission_denied",
"A project API key can only create a key for its own project.",
)
+ try:
+ selected = UUID(str(payload.project_id))
+ except ValueError:
+ raise MCPError("invalid_input", "project_id must be a UUID.") from None
+ project = accessible_projects(context).filter(pk=selected).first()
+ if project is None:
+ raise MCPError("project_required", "The project is not accessible to this connection.")
+ return project
+
+
+def _create_api_key(payload: CreateApiKeyInput, context) -> CreateApiKeyOutput:
+ if context.user.is_guest:
+ raise MCPError("permission_denied", "Create an account to continue.")
raw, instance = APIToken.create_for_user(
context.user,
name=payload.name,
- project=context.project if payload.project_scoped else None,
+ project=_key_project(payload, context),
description=payload.description,
expires_in_days=payload.expires_in_days,
)
@@ -96,9 +115,10 @@ def register_project_tools(catalog):
name="create_api_key",
title="Create API key",
description=(
- "Create an API key. name, description, expires_in_days (0, 30, 90, 180, 365; "
- "0 does not expire) and project_scoped match the Console dialog. The plaintext "
- "is returned once. A project connection cannot create an account key."
+ "Create an API key. name, description and expires_in_days (0, 30, 90, 180, 365; "
+ "0 does not expire) match the Console dialog. Omit project_id for an account key; "
+ "pass project_id for a project key. The plaintext is returned once. A project "
+ "connection can only create a key for its own project."
),
input_model=CreateApiKeyInput,
output_model=CreateApiKeyOutput,
@@ -108,6 +128,7 @@ def register_project_tools(catalog):
required_scopes=frozenset({"overmind:account:write"}),
cost_class="free",
async_mode="sync",
+ project_scoped=False,
),
sync_to_async(_create_api_key, thread_sensitive=True),
)
diff --git a/overmind/skills/overmind/SKILL.md b/overmind/skills/overmind/SKILL.md
index a4039059..14e038be 100644
--- a/overmind/skills/overmind/SKILL.md
+++ b/overmind/skills/overmind/SKILL.md
@@ -107,7 +107,7 @@ coding environment with `overmind connection check --project-id PROJECT --json`;
configuration alone is not readiness. Follow the Datasets skill for durable
upload recovery and scoped host approvals.
-Use the connected catalog and `overmind://interface/current` as the authority for available operations and the current contract version. OAuth/account API keys discover projects with `list_projects` and pass `project_id` on every operation and resource; project API keys retain narrower scope. Never put credentials in chat. `create_api_key` returns a new secret once; do not write it into the repository, a prompt, or another tool argument.
+Use the connected catalog and `overmind://interface/current` as the authority for available operations and the current contract version. OAuth/account API keys discover projects with `list_projects` and pass `project_id` on every operation and resource; project API keys retain narrower scope. Never put credentials in chat. `create_api_key` returns a new secret once; omit `project_id` for an account key and pass it for a project key. Do not write the secret into the repository, a prompt, or another tool argument.
Data-first projects do not require repository scanning, capabilities or instrumentation. Use `develop-model-from-data` when starting with uploaded data. Repository discovery remains a local workflow only for code-backed projects. Installed skills assist discovery; they are not a correctness prerequisite.
diff --git a/tests/test_mcp_api_keys.py b/tests/test_mcp_api_keys.py
index 22808343..75edc36f 100644
--- a/tests/test_mcp_api_keys.py
+++ b/tests/test_mcp_api_keys.py
@@ -49,7 +49,7 @@ def test_create_api_key_returns_the_secret_once_and_stores_the_dialog_fields():
name="CLI",
description="api key for overmind",
expires_in_days=30,
- project_scoped=True,
+ project_id=str(context.project.id),
)
assert result.isError is False
@@ -71,7 +71,12 @@ def test_create_api_key_returns_the_secret_once_and_stores_the_dialog_fields():
def test_account_connection_can_mint_an_account_key_that_does_not_expire():
context = _context(account=True)
- result = _call(context, name="root", expires_in_days=0, project_scoped=False)
+ result = _call(context, name="root", expires_in_days=0)
+ pinned = _call(context, name="pinned", project_id=str(context.project.id))
+ assert pinned.isError is False
+ pinned_token = APIToken.objects.get(id=pinned.structuredContent["id"])
+ assert pinned_token.project_id == context.project.id
+ assert pinned_token.scope["scope"] == "project"
assert result.isError is False
body = result.structuredContent
@@ -83,7 +88,12 @@ def test_account_connection_can_mint_an_account_key_that_does_not_expire():
def test_project_key_cannot_mint_an_account_key():
- result = _call(_context(), project_scoped=False)
+ context = _context()
+ result = _call(context)
+ other = make_project(member=context.user)
+ foreign = _call(context, project_id=str(other.id))
+ assert foreign.isError is True
+ assert foreign.structuredContent["error"]["code"] == "permission_denied"
assert result.isError is True
assert result.structuredContent["error"]["code"] == "permission_denied"