-
Notifications
You must be signed in to change notification settings - Fork 12
feat(workflow-executor): add OAuth credential store + deposit endpoint (PRD-367 PR1) #1619
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
8
commits into
main
Choose a base branch
from
feat/prd-367-pr1-executor-oauth-credentials
base: main
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.
+5,672
−128
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f0cc0a4
feat(workflow-executor): add OAuth MCP credential store + deposit/del…
hercemer42 6859cd9
fix(workflow-executor): harden oauth store wiring + boot + clientSecr…
hercemer42 d3dbde6
feat(workflow-executor): use stored OAuth credentials for MCP steps […
hercemer42 278b64b
fix(workflow-executor): address review findings on the oauth2 MCP run…
hercemer42 a955626
fix(workflow-executor): form-url-encode client_secret_basic credentia…
hercemer42 4f9e173
style(workflow-executor): tighten fix comments to <=2 lines [PRD-367]
hercemer42 8fa438f
fix(workflow-executor): reject empty-string clientId at deposit [PRD-…
hercemer42 426dbb2
fix(workflow-executor): address final-pass review findings on the oau…
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
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); | ||
| // Only an HTTP-range status is authoritative (a 403 isn't refreshable even if its message says | ||
| // "unauthorized"). A JSON-RPC error code like -32603 isn't a status, so fall back to the message. | ||
| if (status !== undefined && status >= 100 && status <= 599) 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,64 @@ | ||
| 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, | ||
| ); | ||
| }); | ||
|
|
||
| it('classifies a JSON-RPC McpError by message, ignoring its non-HTTP code (e.g. -32603)', () => { | ||
| expect(isMcpAuthError(Object.assign(new Error('Unauthorized'), { code: -32603 }))).toBe(true); | ||
| expect(isMcpAuthError(Object.assign(new Error('boom'), { code: -32603 }))).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.