MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / makeRejectingPlugin

Function makeRejectingPlugin

packages/core/sdk/src/oauth-flow.test.ts:2494–2533  ·  view source on GitHub ↗
(state: {
  revoked: Set<string>;
  /** Reject every token, even a freshly minted one — a dead grant. */
  rejectEverything?: boolean;
  calls: string[];
})

Source from the content-addressed store, hash-verified

2492 * token works") is what lets a test assert that the RETRY succeeded — the
2493 * re-minted token is simply one the upstream never revoked. */
2494const makeRejectingPlugin = (state: {
2495 revoked: Set<string>;
2496 /** Reject every token, even a freshly minted one — a dead grant. */
2497 rejectEverything?: boolean;
2498 calls: string[];
2499}) =>
2500 definePlugin(() => ({
2501 id: "acme" as const,
2502 storage: () => ({}),
2503 resolveTools: () =>
2504 Effect.succeed({ tools: [{ name: ToolName.make("whoami"), description: "whoami" }] }),
2505 describeAuthMethods: () => [
2506 {
2507 id: "oauth",
2508 label: "OAuth2",
2509 kind: "oauth" as const,
2510 template: String(TEMPLATE),
2511 oauth: { scopes: [] },
2512 },
2513 ],
2514 invokeTool: ({ credential }) => {
2515 const token = credential.value;
2516 state.calls.push(String(token));
2517 if (token !== null && !state.rejectEverything && !state.revoked.has(token)) {
2518 return Effect.succeed(ToolResult.ok({ token }));
2519 }
2520 return Effect.succeed(
2521 authToolFailure({
2522 code: "connection_rejected",
2523 status: 401,
2524 message: "Upstream rejected credentials with HTTP 401.",
2525 integration: { id: String(credential.integration) },
2526 credential: { kind: "upstream", label: String(credential.connection) },
2527 }),
2528 );
2529 },
2530 extension: (ctx) => ({
2531 seed: () => ctx.core.integrations.register({ slug: INTEG, description: "Acme", config: {} }),
2532 }),
2533 }))();
2534
2535/** Mint a connection against `server` and return the harness + call log. */
2536const connectRejecting = (options?: { readonly tokenExpiresInSeconds?: number }) =>

Callers 1

connectRejectingFunction · 0.85

Calls 3

definePluginFunction · 0.90
authToolFailureFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected