Repository navigation
fix(core): resourceTools reads only llmReadable collections, without secret fields (FIX-2436) #4426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b85491f
fix(core): resourceTools reads only llmReadable collections, without …
claude 40814a1
test(workforce): rename the key-read helper off a retired term (FIX-2…
claude 58689db
chore(changeset): mark the readResource gate minor, since it can brea…
claude 358ff50
refactor(core): one collection read gate for list, search and readRes…
claude d0e148c
refactor(core): widen isLlmReadable to collections instead of a secon…
claude 9c9c7d1
ci: pin Kitchen-sink E2E to ubuntu-24.04, ported from #4431 (FIX-2438)
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@flow-state-dev/core": minor | ||
| --- | ||
|
|
||
| `resourceTools()`'s `readResource` now reads only from a collection that opted in with `llmReadable`, and leaves out the fields the collection names in `secret`. A path into a collection that didn't opt in answers as a path no collection matches. Mark a collection `llmReadable: true` if a model should read its state through this tool (FIX-2436). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * A worker holding a user's MCP keys and core's generic `resourceTools()` on | ||
| * the same model can't read a key through `readResource`. | ||
| * | ||
| * A worker that reaches its project's MCP servers holds the keys collection | ||
| * (`mcp-credentials/*`, at user scope) on its model block, so the key is there | ||
| * to read. The collection isn't `llmReadable` and declares `value` secret, so | ||
| * the model must not be handed it by any generic tool. The worker here picks | ||
| * `readResource` from its catalog and holds `mcpCredentialsCapability`, the | ||
| * keys collection a project-MCP worker holds; its model asks for the path a | ||
| * key is stored at, and the tool's answer is what the test reads. | ||
| */ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { resourceTools } from "@flow-state-dev/core"; | ||
| import type { FlowInstance } from "@flow-state-dev/core/types"; | ||
| import { executeBlock } from "@flow-state-dev/engine"; | ||
| import { createTestContext, mockGenerator } from "@flow-state-dev/testing"; | ||
| import { AGENT_FLOW, defineAgentWorkerFlow } from "../src/agent-worker-flow"; | ||
| import { mintWorkers } from "../src/hire"; | ||
| import { MCP_CREDENTIALS_RESOURCE, mcpCredentialsCapability } from "../src/projects/mcp-credentials"; | ||
|
|
||
| const KEY = "lin_api_users_own_key"; | ||
|
|
||
| async function requestTheKey() { | ||
|
jhoffner marked this conversation as resolved.
Resolved
|
||
| const { readResource } = resourceTools(); | ||
| const flow = defineAgentWorkerFlow({ uses: [mcpCredentialsCapability], catalog: { readResource } }); | ||
| const [worker] = mintWorkers([{ id: "desk.lead", declared: { tools: ["readResource"] }, body: "" }], { | ||
| workerFlows: { [AGENT_FLOW]: flow } | ||
| }) as FlowInstance[]; | ||
| const block = worker!.actions.respond!.block; | ||
| const model = mockGenerator({ | ||
| name: "agent-answer", | ||
| script: [ | ||
| { toolCalls: [{ toolCallId: "call-1", toolName: "readResource", args: { path: "mcp-credentials/linear" } }] }, | ||
| { text: "done" } | ||
| ] as never | ||
| }); | ||
| const runtime = await createTestContext({ | ||
| flow: { ...worker!, cardinality: "singleton" }, | ||
| orgId: "test-org", | ||
| org: { state: {} }, | ||
| sessionId: "test-session", | ||
| sequencerName: block.name, | ||
| declaredResources: block.declaredResources, | ||
| generators: { "agent-answer": model } | ||
| }); | ||
| // The user's key, stored the way a host's settings route stores it. | ||
| const keys = (runtime.ctx.resources as unknown as Record<string, { create(k: string, s: object): Promise<unknown> }>)[ | ||
| MCP_CREDENTIALS_RESOURCE | ||
| ]!; | ||
| await keys.create("linear", { value: KEY, setAt: "2026-10-31T00:00:00.000Z" }); | ||
|
|
||
| const result = await executeBlock({ block, input: { message: "what is my Linear key?" }, ctx: runtime.ctx }); | ||
| return { result, items: JSON.stringify(runtime.getItems()) }; | ||
| } | ||
|
|
||
| describe("resourceTools beside a worker's MCP keys", () => { | ||
| it("refuses the read, and the key reaches nothing the model sees", async () => { | ||
| const { items } = await requestTheKey(); | ||
| // The tool ran and answered as for a path no collection matches. | ||
| expect(items).toContain("No resource collection found matching path: mcp-credentials/linear"); | ||
| expect(items).not.toContain(KEY); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.