-
Notifications
You must be signed in to change notification settings - Fork 12
feat(workflow-executor): use stored OAuth credentials for MCP steps [PRD-367] #1665
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
Open
hercemer42
wants to merge
19
commits into
feat/prd-367-pr1-executor-oauth-credentials
Choose a base branch
from
feat/prd-367-pr2-executor-oauth-runtime
base: feat/prd-367-pr1-executor-oauth-credentials
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,814
−69
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
99da0ab
feat(workflow-executor): use stored OAuth credentials for MCP steps
hercemer42 37dbf8d
fix(workflow-executor): write rotated refresh token to the current row
hercemer42 2dce276
fix(ai-proxy): treat only 401 (not 403) as a refreshable MCP auth error
hercemer42 b345697
feat(workflow-executor): support OAuth MCP steps in the in-memory exe…
hercemer42 b1de994
fix(workflow-executor): repoint token service at the relocated creden…
hercemer42 f50f18e
feat(workflow-executor): re-consent on decrypt failure after key rota…
hercemer42 c121cb6
feat(workflow-executor): add GET /list-mcp-tools design-time tool lis…
hercemer42 f77ba06
fix(workflow-executor): guard against non-object token-endpoint respo…
hercemer42 b6f316e
fix(workflow-executor): evict cached access token on credential disco…
hercemer42 a27a5c4
fix(workflow-executor): address PR review on oauth2 runtime [PRD-624]
hercemer42 6bc22e6
docs(workflow-executor): correct write-back-failure comment [PRD-624]
hercemer42 5b0ddb7
fix(workflow-executor): validate OAuth token endpoint against SSRF [P…
hercemer42 0da9298
fix(workflow-executor): block IPv4-mapped IPv6 in token-endpoint guar…
hercemer42 68886dc
docs(workflow-executor): use US spelling "defense" in refresh-grant c…
hercemer42 110ffb8
docs(workflow-executor): rewrite token-endpoint guard comment [PRD-624]
hercemer42 709576b
fix(workflow-executor): block the unspecified address in token-endpoi…
hercemer42 8de8888
fix(workflow-executor): reject localhost FQDN/.localhost aliases in t…
hercemer42 81b5607
test(workflow-executor): cover trailing-dot IP forms in token-endpoin…
hercemer42 5f1c6f3
fix(workflow-executor): address PR review — SSRF redirect, deposit ev…
hercemer42 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
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,61 @@ | ||
| // Classifies errors surfaced while connecting to or calling an MCP server. Only 401 (the token was | ||
| // rejected) is a refreshable auth failure; 403 is a permission/scope problem a token refresh or | ||
| // re-consent cannot resolve, so it is left to surface as an ordinary failure. The MCP SDK / HTTP | ||
| // transport reports failures in several shapes (a numeric status field, or only a message string), | ||
| // so the checks walk the cause chain and inspect both structured status and the message text. | ||
| const AUTH_STATUSES = new Set([401]); | ||
| const AUTH_PATTERN = /\b401\b|unauthorized/i; | ||
| const CONNECTION_PATTERN = | ||
| /econnrefused|econnreset|etimedout|enotfound|eai_again|fetch failed|network|socket|timeout|connect/i; | ||
|
|
||
| export type McpLoadFailureKind = 'auth' | 'connection' | 'unknown'; | ||
|
|
||
| function statusOf(value: unknown): number | undefined { | ||
| const candidate = value as { code?: unknown; status?: unknown; statusCode?: unknown }; | ||
|
|
||
| for (const field of [candidate?.code, candidate?.status, candidate?.statusCode]) { | ||
| if (typeof field === 'number') return field; | ||
| } | ||
|
|
||
| return undefined; | ||
| } | ||
|
|
||
| function messageOf(value: unknown): string { | ||
| if (value instanceof Error) return value.message; | ||
| if (typeof value === 'string') return value; | ||
|
|
||
| return ''; | ||
| } | ||
|
|
||
| function errorChain(error: unknown): unknown[] { | ||
| const links: unknown[] = []; | ||
| let current: unknown = error; | ||
|
|
||
| while (current && links.length < 10 && !links.includes(current)) { | ||
| links.push(current); | ||
| current = (current as { cause?: unknown }).cause; | ||
| } | ||
|
|
||
| return links; | ||
| } | ||
|
|
||
| export function isMcpAuthError(error: unknown): boolean { | ||
| return errorChain(error).some(link => { | ||
| const status = statusOf(link); | ||
| // An explicit status is authoritative — a 403 is not a refreshable auth error even if its | ||
| // message says "unauthorized". Fall back to the message only when no status is present. | ||
| if (status !== undefined) return AUTH_STATUSES.has(status); | ||
|
|
||
| return AUTH_PATTERN.test(messageOf(link)); | ||
| }); | ||
| } | ||
|
|
||
| export function classifyMcpLoadError(error: unknown): McpLoadFailureKind { | ||
| if (isMcpAuthError(error)) return 'auth'; | ||
|
|
||
| const isConnectionFailure = errorChain(error).some(link => | ||
| CONNECTION_PATTERN.test(messageOf(link)), | ||
| ); | ||
|
|
||
| return isConnectionFailure ? 'connection' : 'unknown'; | ||
| } | ||
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 |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| import type { McpServerLoadFailure } from './mcp-client'; | ||
| import type RemoteTool from './remote-tool'; | ||
|
|
||
| export interface ToolProvider { | ||
| loadTools(): Promise<RemoteTool[]>; | ||
| // Optional richer variant: providers that can classify per-server failures expose them here. | ||
| loadToolsWithFailures?(): Promise<{ tools: RemoteTool[]; failures: McpServerLoadFailure[] }>; | ||
| checkConnection(): Promise<true>; | ||
| dispose(): Promise<void>; | ||
| } |
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,59 @@ | ||
| import { classifyMcpLoadError, isMcpAuthError } from '../src/mcp-auth-error'; | ||
|
|
||
| function withCause(message: string, cause: unknown): Error { | ||
| const error = new Error(message); | ||
| (error as { cause?: unknown }).cause = cause; | ||
|
|
||
| return error; | ||
| } | ||
|
|
||
| describe('isMcpAuthError', () => { | ||
| it('detects a 401 numeric status field', () => { | ||
| expect(isMcpAuthError({ code: 401 })).toBe(true); | ||
| }); | ||
|
|
||
| it('detects 401 / unauthorized in the message', () => { | ||
| expect(isMcpAuthError(new Error('Request failed with status code 401'))).toBe(true); | ||
| expect(isMcpAuthError(new Error('Unauthorized'))).toBe(true); | ||
| }); | ||
|
|
||
| it('walks the cause chain', () => { | ||
| expect( | ||
| isMcpAuthError(withCause('wrapper', Object.assign(new Error('inner'), { status: 401 }))), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for 403 (forbidden), non-auth errors, and nullish input', () => { | ||
| expect(isMcpAuthError(Object.assign(new Error('denied'), { status: 403 }))).toBe(false); | ||
| expect(isMcpAuthError(new Error('403 Forbidden'))).toBe(false); | ||
| expect(isMcpAuthError(new Error('ECONNREFUSED'))).toBe(false); | ||
| expect(isMcpAuthError(new Error('500 Internal Server Error'))).toBe(false); | ||
| expect(isMcpAuthError(undefined)).toBe(false); | ||
| }); | ||
|
|
||
| it('lets an explicit status win over an "unauthorized" message (a 403 stays non-auth)', () => { | ||
| expect(isMcpAuthError(Object.assign(new Error('Unauthorized scope'), { status: 403 }))).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('classifyMcpLoadError', () => { | ||
| it("classifies a 401 as 'auth'", () => { | ||
| expect(classifyMcpLoadError(new Error('HTTP 401 Unauthorized'))).toBe('auth'); | ||
| expect(classifyMcpLoadError({ status: 401 })).toBe('auth'); | ||
| }); | ||
|
|
||
| it("classifies network failures as 'connection'", () => { | ||
| expect(classifyMcpLoadError(new Error('connect ECONNREFUSED 127.0.0.1:3000'))).toBe( | ||
| 'connection', | ||
| ); | ||
| expect(classifyMcpLoadError(new Error('fetch failed'))).toBe('connection'); | ||
| expect(classifyMcpLoadError(new Error('socket hang up'))).toBe('connection'); | ||
| }); | ||
|
|
||
| it("classifies a 403 (forbidden) and anything else as 'unknown'", () => { | ||
| expect(classifyMcpLoadError(new Error('HTTP 403 Forbidden'))).toBe('unknown'); | ||
| expect(classifyMcpLoadError(new Error('tool schema invalid'))).toBe('unknown'); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.