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

Function makeRejectingPlugin

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

1532 * token works") is what lets a test assert that the RETRY succeeded — the
1533 * re-minted token is simply one the upstream never revoked. */
1534const makeRejectingPlugin = (state: {
1535 revoked: Set<string>;
1536 /** Reject every token, even a freshly minted one — a dead grant. */
1537 rejectEverything?: boolean;
1538 calls: string[];
1539}) =>
1540 definePlugin(() => ({
1541 id: "acme" as const,
1542 storage: () => ({}),
1543 resolveTools: () =>
1544 Effect.succeed({ tools: [{ name: ToolName.make("whoami"), description: "whoami" }] }),
1545 describeAuthMethods: () => [
1546 {
1547 id: "oauth",
1548 label: "OAuth2",
1549 kind: "oauth" as const,
1550 template: String(TEMPLATE),
1551 oauth: { scopes: [] },
1552 },
1553 ],
1554 invokeTool: ({ credential }) => {
1555 const token = credential.value;
1556 state.calls.push(String(token));
1557 if (token !== null && !state.rejectEverything && !state.revoked.has(token)) {
1558 return Effect.succeed(ToolResult.ok({ token }));
1559 }
1560 return Effect.succeed(
1561 authToolFailure({
1562 code: "connection_rejected",
1563 status: 401,
1564 message: "Upstream rejected credentials with HTTP 401.",
1565 integration: { id: String(credential.integration) },
1566 credential: { kind: "upstream", label: String(credential.connection) },
1567 }),
1568 );
1569 },
1570 extension: (ctx) => ({
1571 seed: () => ctx.core.integrations.register({ slug: INTEG, description: "Acme", config: {} }),
1572 }),
1573 }))();
1574
1575/** Mint a connection against `server` and return the harness + call log. */
1576const 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