modelcontextprotocol / modelcontextprotocol/typescript-sdk

TaskStore interface should pass through authInfo and signal

Open
#2,020 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auth enhancement needs decision P3
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

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`

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing RequestTaskStore and RequestHandlerExtra through server.executeToolHandler and validateToolInput, focusing on how taskStore reaches methods beyond task creation. Done means the chosen interface consistently exposes the request authInfo and signal, or the full RequestHandlerExtra, to every relevant TaskStore method without monkeypatching.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.