Skip to content

[RFC] refactor: extract task orchestration from Protocol into TaskManager - #1449

Closed
felixweinberger wants to merge 1 commit into
mainfrom
fweinberger/extract-tasks-from-protocol
Closed

[RFC] refactor: extract task orchestration from Protocol into TaskManager#1449
felixweinberger wants to merge 1 commit into
mainfrom
fweinberger/extract-tasks-from-protocol

Conversation

@felixweinberger

@felixweinbergerfelixweinberger commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Extracts experimental task orchestration logic from Protocol into a dedicated TaskManager class.

Protocol.ts drops from 1,736 to 992 lines. Task handler registration, message queuing, polling, and state management now live in TaskManager.

Protocol delegates through 5 lifecycle methods (processInboundRequest, processOutboundRequest, processInboundResponse, processOutboundNotification, onClose) and a NullTaskManager provides no-op defaults when tasks are not configured.

Motivation and Context

Task logic was spread across every major Protocol method, making it hard to reason about either concern independently. Since tasks are experimental, this isolation makes Protocol easier to maintain.

Breaking Changes

  • ProtocolOptions.taskStore / taskMessageQueue / etc. moved under ProtocolOptions.tasks?: TaskManagerOptions

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@changeset-bot

changeset-botBot commented Feb 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c76a53b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
NameType
@modelcontextprotocol/coreMinor
@modelcontextprotocol/clientMinor
@modelcontextprotocol/serverMinor
@modelcontextprotocol/nodeMajor
@modelcontextprotocol/expressMajor
@modelcontextprotocol/honoMajor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-newBot commented Feb 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1449

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1449

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1449

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1449

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1449

commit: c76a53b

@felixweinbergerfelixweinberger changed the title refactor: extract task orchestration from Protocol into TaskManager[RFC] refactor: extract task orchestration from Protocol into TaskManagerFeb 3, 2026
@felixweinberger
felixweinbergerforce-pushed the fweinberger/extract-tasks-from-protocol branch from c3104d6 to b783fcdCompareFebruary 3, 2026 10:06
@felixweinberger
felixweinbergerforce-pushed the fweinberger/extract-tasks-from-protocol branch 5 times, most recently from 1cf942d to adf1507CompareFebruary 3, 2026 21:47
Extract all task-related logic from Protocol into a dedicated TaskManager
class with consolidated lifecycle API and NullTaskManager (Null Object pattern).
Protocol delegates to TaskManager via 4 lifecycle methods:
- processInboundRequest: context extraction + function wrapping
- processOutboundRequest: metadata augmentation + queue routing
- processInboundResponse: side-channel handling + progress preservation
- processOutboundNotification: task-related notification routing
NullTaskManager provides no-op defaults, eliminating all conditional
checks in Protocol.
@felixweinberger
felixweinbergerforce-pushed the fweinberger/extract-tasks-from-protocol branch from adf1507 to c76a53bCompareFebruary 3, 2026 21:51
Comment on lines +183 to +185
return {
...task
} as Result;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Task not satisfy GetTaskResult already?

Comment on lines +181 to +182
// Per spec: tasks/get responses SHALL NOT include related-task metadata
// as the taskId parameter is the source of truth

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think this comment is relevant here?

@LucaButBoring

Copy link
Copy Markdown
Contributor

Does this affect how task tools are registered and executed as well? It doesn't look like it does, but I just wanted to verify that first - I believe this supersedes #1315, but I'm unsure if it supersedes #1332 as well or not.

Looks good overall though, I have similar problems in the Java SDK (modelcontextprotocol/java-sdk#755) and will probably copy part of this approach over there.

@felixweinberger

Copy link
Copy Markdown
ContributorAuthor

Superseded by #1673

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@felixweinberger@LucaButBoring