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

Function makeRejectingPlugin

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

1349 * token works") is what lets a test assert that the RETRY succeeded — the
1350 * re-minted token is simply one the upstream never revoked. */
1351const makeRejectingPlugin = (state: {
1352 revoked: Set<string>;
1353 /** Reject every token, even a freshly minted one — a dead grant. */
1354 rejectEverything?: boolean;
1355 calls: string[];
1356}) =>
1357 definePlugin(() => ({
1358 id: "acme" as const,
1359 storage: () => ({}),
1360 resolveTools: () =>
1361 Effect.succeed({ tools: [{ name: ToolName.make("whoami"), description: "whoami" }] }),
1362 describeAuthMethods: () => [
1363 {
1364 id: "oauth",
1365 label: "OAuth2",
1366 kind: "oauth" as const,
1367 template: String(TEMPLATE),
1368 oauth: { scopes: [] },
1369 },
1370 ],
1371 invokeTool: ({ credential }) => {
1372 const token = credential.value;
1373 state.calls.push(String(token));
1374 if (token !== null && !state.rejectEverything && !state.revoked.has(token)) {
1375 return Effect.succeed(ToolResult.ok({ token }));
1376 }
1377 return Effect.succeed(
1378 authToolFailure({
1379 code: "connection_rejected",
1380 status: 401,
1381 message: "Upstream rejected credentials with HTTP 401.",
1382 integration: { id: String(credential.integration) },
1383 credential: { kind: "upstream", label: String(credential.connection) },
1384 }),
1385 );
1386 },
1387 extension: (ctx) => ({
1388 seed: () => ctx.core.integrations.register({ slug: INTEG, description: "Acme", config: {} }),
1389 }),
1390 }))();
1391
1392/** Mint a connection against `server` and return the harness + call log. */
1393const 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