Skip to content

Commit bbc427a

Browse files
committed
fix(mcp): a read-only discovery preserves the OAuth grant
1 parent 26a5ae4 commit bbc427a

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

‎.agents/skills/add-tools/SKILL.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ search that returns no email or phone, and an email verifier.
220220
`read`, fails the audit unless the `effect` line carries `// tool-effect: <reason>` on one of the
221221
two lines above it; use it only for a genuine exception such as a GET that writes in `postProcess`.
222222
- A factory that builds tools from definitions takes `effect` per definition and passes it through.
223-
- Prove the labels with a dry run: put the block in a workflow and run
223+
- Prove the labels with a dry run, against a test account or test resource (a `read` runs for real,
224+
so a write mislabelled `read` is sent): put the block in a workflow and run
224225
`sim workflows run <workflowId> --dry --input '{…}'`. Each `write` call must appear in the result's
225226
`sideEffects.stubbed` with the request you expect (an HTTP tool's `method`, `url` and `body`, or an
226227
in-process operation's input, credentials redacted), and each `read` must run for real and return

‎apps/sim/lib/mcp/service.test.ts‎

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -607,27 +607,38 @@ describe('McpService best-effort discovery', () => {
607607
expectNoSharedStateWrites()
608608
})
609609

610-
it('connects an authorized OAuth server with a grant-preserving provider and writes nothing when it is rejected', async () => {
611-
mockGetWorkspaceServersRows.mockResolvedValue([dbRow('mcp-a', 'A', { authType: 'oauth' })])
612-
mcpOauthMockFns.mockHasDecryptableOauthTokens.mockResolvedValue(true)
613-
mcpOauthMockFns.mockGetOrCreateOauthRow.mockResolvedValue({
614-
id: 'oauth-row-1',
615-
tokens: { access_token: 'expired', token_type: 'bearer' },
616-
})
617-
mockListTools.mockRejectedValueOnce(new UnauthorizedError('refresh rejected'))
618-
MockMcpClient.mockClear()
619-
620-
await expect(
621-
mcpService.discoverServerTools(MEMBER_B, 'mcp-a', WORKSPACE_ID, 'cache-aside', undefined, {
622-
bestEffort: true,
610+
it.each([
611+
['a best-effort', { bestEffort: true }],
612+
['a read-only', { readOnly: true }],
613+
])(
614+
'connects an authorized OAuth server in %s discovery with a grant-preserving provider and writes nothing when it is rejected',
615+
async (_kind, options) => {
616+
mockGetWorkspaceServersRows.mockResolvedValue([dbRow('mcp-a', 'A', { authType: 'oauth' })])
617+
mcpOauthMockFns.mockHasDecryptableOauthTokens.mockResolvedValue(true)
618+
mcpOauthMockFns.mockGetOrCreateOauthRow.mockResolvedValue({
619+
id: 'oauth-row-1',
620+
tokens: { access_token: 'expired', token_type: 'bearer' },
623621
})
624-
).rejects.toThrow('refresh rejected')
622+
mockListTools.mockRejectedValueOnce(new UnauthorizedError('refresh rejected'))
623+
MockMcpClient.mockClear()
625624

626-
expect(MockMcpClient.mock.calls[0]?.[0]).toMatchObject({
627-
oauthCredentials: { initialProvider: { preserveGrant: true } },
628-
})
629-
expectNoSharedStateWrites()
630-
})
625+
await expect(
626+
mcpService.discoverServerTools(
627+
MEMBER_B,
628+
'mcp-a',
629+
WORKSPACE_ID,
630+
'cache-aside',
631+
undefined,
632+
options
633+
)
634+
).rejects.toThrow('refresh rejected')
635+
636+
expect(MockMcpClient.mock.calls[0]?.[0]).toMatchObject({
637+
oauthCredentials: { initialProvider: { preserveGrant: true } },
638+
})
639+
expectNoSharedStateWrites()
640+
}
641+
)
631642

632643
it('warms the shared tool cache on success without stamping status', async () => {
633644
mockGetWorkspaceServersRows.mockResolvedValue([dbRow('mcp-a', 'A')])

‎apps/sim/lib/mcp/service.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,7 @@ class McpService {
12981298
onResolvedSecretTraceProvenance,
12991299
signal,
13001300
requireComplete,
1301-
bestEffort
1301+
bestEffort || readOnly
13021302
)
13031303
logger.info(`Discovered ${tools.length} tools from server ${config.name}`, { requestId })
13041304
if (readOnly) return tools

0 commit comments

Comments
 (0)