Skip to content

TaskStore interface should pass through authInfo and signal #2020

@icopp

Description

@icopp

Is your feature request related to a problem? Please describe.
Using the server-level TaskStore to interface with external systems doesn't work if that interfacing depends on using user-level auth, such as RLS-based database systems.

Describe the solution you'd like
The taskStore instance should get passed at a minimum authInfo and signal from the request, but ideally just the whole RequestHandlerExtra object, either in the constructor or as an additional parameter for all methods (not just creating tasks).

Describe alternatives you've considered
The workaround I'm using for the moment is to use monkeypatching along these lines for each server method that passes through taskStore to the actual tool calls:

class InternalTaskStore implements RequestTaskStore {
  readonly #authInfo: AuthInfo;
  readonly #signal: AbortSignal;

  constructor({
    authInfo,
    signal,
  }: {
    authInfo: AuthInfo;
    signal: AbortSignal;
  }) {
    this.#authInfo = authInfo;
    this.#signal = signal;
  }

  // ... with overrides of each method that have auth-based DB usage
}

const originalExecuteToolHandler: (
  tool: RegisteredTool,
  args: unknown,
  extra: RequestHandlerExtra<ServerRequest, ServerNotification>,
) => Promise<CallToolResult | CreateTaskResult> =
  // @ts-expect-error Using private property
  server.executeToolHandler.bind(server);
const executeToolHandler: typeof originalExecuteToolHandler =
  function executeToolHandler(tool, args, extra) {
    return originalExecuteToolHandler(tool, args, {
      ...extra,
      taskStore: new InternalTaskStore({
        authInfo: extra.authInfo!,
        signal: extra.signal,
      }),
    });
  };
// @ts-expect-error Using private property
server.executeToolHandler = executeToolHandler.bind(server);

// same kind of thing for `validateToolInput`

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementRequest for a new feature that's not currently supported

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions