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

Function makeRejectingPlugin

packages/core/sdk/src/oauth-flow.test.ts:2366–2405  ·  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

2364 * token works") is what lets a test assert that the RETRY succeeded — the
2365 * re-minted token is simply one the upstream never revoked. */
2366const makeRejectingPlugin = (state: {
2367 revoked: Set<string>;
2368 /** Reject every token, even a freshly minted one — a dead grant. */
2369 rejectEverything?: boolean;
2370 calls: string[];
2371}) =>
2372 definePlugin(() => ({
2373 id: "acme" as const,
2374 storage: () => ({}),
2375 resolveTools: () =>
2376 Effect.succeed({ tools: [{ name: ToolName.make("whoami"), description: "whoami" }] }),
2377 describeAuthMethods: () => [
2378 {
2379 id: "oauth",
2380 label: "OAuth2",
2381 kind: "oauth" as const,
2382 template: String(TEMPLATE),
2383 oauth: { scopes: [] },
2384 },
2385 ],
2386 invokeTool: ({ credential }) => {
2387 const token = credential.value;
2388 state.calls.push(String(token));
2389 if (token !== null && !state.rejectEverything && !state.revoked.has(token)) {
2390 return Effect.succeed(ToolResult.ok({ token }));
2391 }
2392 return Effect.succeed(
2393 authToolFailure({
2394 code: "connection_rejected",
2395 status: 401,
2396 message: "Upstream rejected credentials with HTTP 401.",
2397 integration: { id: String(credential.integration) },
2398 credential: { kind: "upstream", label: String(credential.connection) },
2399 }),
2400 );
2401 },
2402 extension: (ctx) => ({
2403 seed: () => ctx.core.integrations.register({ slug: INTEG, description: "Acme", config: {} }),
2404 }),
2405 }))();
2406
2407/** Mint a connection against `server` and return the harness + call log. */
2408const 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