WeKnora/internal/handler/dto
Leo Dawn a3c7be10ca
fix(agent): scope the @Skill and @MCP pickers to the agent that will run (#3475)
* fix(agent): scope the @Skill and @MCP pickers to the agent that will run

Both pickers listed the caller's own workspace, but a shared agent invokes its
OWNER's skills and MCP services. The two never line up, so for every shared
agent:

  * @Skill was always empty, in every skills mode. GET /skills resolves the
    sandbox config with (tenant, id), and the agent's config id does not exist
    in the borrower's workspace - effectiveTenantSkills short-circuits before
    it reads a single skill row. The response still reported
    skills_available: true, so the category appeared with nothing under it.
  * @MCP in "selected" mode was empty for the same reason: the preset holds the
    owner's service ids, which match nothing in the borrower's catalog.
  * @MCP in "all" mode was worse than empty. isMCPAllowedByAgent returns true
    for every enabled service, so the picker offered the BORROWER's own
    services; resolvePerRequestMCPScope then intersected the mention against
    the agent's preset, found nothing, and dropped it with only a warning.

Resolve the agent when the request carries agent_id + agent_source_tenant_id
and read its resources where they live. Only an explicit source workspace takes
the share path, so an own-agent request is byte-for-byte unchanged; built-in
agent ids exist in every workspace, and falling back to a share lookup without
one would let an org member take over the caller's default agent, exactly as
session.Handler.resolveAgent already documents.

Both endpoints serve only what the agent can actually invoke:

  * skills: the sandbox config comes from the agent, never from the query, so a
    borrower cannot name another config in the owner's workspace and enumerate
    it; "selected" narrows to the configured names and a disabled picker never
    reaches the owner's inventory at all.
  * MCP: the agent's explicit preset and nothing else, because that is exactly
    what resolvePerRequestMCPScope accepts for a shared agent. "all" therefore
    offers nothing rather than offering services every mention would drop.
    Whether "all" should become mentionable is a separate decision about that
    guard, not about the picker.

The cross-workspace MCP rows use a narrowed response built field by field.
NewMCPServiceResponse reveals endpoint URL, headers, env vars and stdio command
to an Admin, and a borrower can be an Admin of their own workspace - that shape
must be narrow by construction, not by role.

On the client the two lists now follow the selected agent: their cache keys
carry it, and the chat input refetches on a switch behind a request token, so a
slow response for the agent the user just left cannot overwrite the picker with
another workspace's services.

* fix(agent): check the c.Error return on the shared-agent picker paths

golangci-lint judges pull requests on the lines they introduce, so the
repository's older bare c.Error calls are grandfathered while these three are
not. Match the _ = c.Error form already used in mcp_service.go.
2026-09-21 13:02:34 +08:00
..
auth.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
auth_test.go fix(api-keys): enforce scope from request context after attach 2026-07-07 12:00:13 +08:00
datasource.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
datasource_test.go fix(datasource): harden RSS connector and editor UX after review 2026-06-23 17:30:38 +08:00
mcp.go fix(agent): scope the @Skill and @MCP pickers to the agent that will run (#3475) 2026-09-21 13:02:34 +08:00
mcp_test.go feat(mcp)!: persist tool catalogs and add guided configuration (#3118) 2026-09-09 13:34:56 +08:00
model.go refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
model_test.go refactor(models): rebuild vendor integration on protocol + catalog + vendor layers (#3470) 2026-09-20 21:28:23 +08:00
role.go test(api-keys): add unit tests for tenant API key validation 2026-07-07 12:00:13 +08:00
role_test.go test(api-keys): add unit tests for tenant API key validation 2026-07-07 12:00:13 +08:00
tenant.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
tenant_test.go fix(api-keys): enforce scope from request context after attach 2026-07-07 12:00:13 +08:00
test_helpers.go fix(security): redact integration secrets from viewer-accessible endpoints 2026-07-02 14:41:42 +08:00
web_search_provider.go feat(memory): add cross-session long-term memory 2026-08-13 18:00:02 +08:00
web_search_provider_test.go fix(security): redact integration secrets from viewer-accessible endpoints 2026-07-02 14:41:42 +08:00