v2 - RFC Extract Tasks out of protocol.ts into TaskManager#1673
Draft
KKonstantinov wants to merge 8 commits intomodelcontextprotocol:mainfrom
Draft
Conversation
…re and task MQ on constructor
🦋 Changeset detectedLatest commit: 3b7c0fd The changes in this PR will be included in the next version bump. This PR includes changesets to release 6 packages
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 |
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
…lity' of github.com:KKonstantinov/typescript-sdk into feature/extract-tasks-in-task-manager-trigger-on-capability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #1449
Extract all task orchestration logic (creation, polling, queuing, routing) from the monolithic
Protocolclass into a dedicatedTaskManagerclass that implements a newProtocolModuleinterface.TaskManageris only instantiated whencapabilities.tasksis declared, keeping Protocol lean for non-task use cases.Motivation and Context
The
Protocolclass had grown to ~1800 lines, with roughly half dedicated to task management. This made it difficult to reason about, test, and extend independently. Extracting tasks intoTaskManagerachieves:ProtocolModuleinterface allows future modules to hook into request/response/notification lifecycle without modifying Protocolextra/ctxtask fields are grouped under a singletaskobject instead of scattered top-level propertiesHow Has This Been Tested?
pnpm test:all)pnpm typecheck:allpasses (except a pre-existing unrelated type error inexamples/client)experimental.tasks.*APIsInMemoryTaskStoreon both client and serverBreaking Changes
ProtocolOptions.taskStorecapabilities.tasks.taskStore(onClientOptions/ServerOptions)ProtocolOptions.taskMessageQueuecapabilities.tasks.taskMessageQueue(onClientOptions/ServerOptions)Protocol.assertTaskCapability()(abstract)TaskManagerOptionsProtocol.assertTaskHandlerCapability()(abstract)TaskManagerOptionsTypes of changes
Checklist
Additional context
New files:
packages/core/src/shared/taskManager.ts—TaskManagerclass implementingProtocolModulepackages/core/src/shared/protocolModule.ts—ProtocolModuleinterface and lifecycle typesArchitecture: Protocol now maintains a
_modulesarray. During request/response/notification processing, it delegates to each registered module in order. TaskManager is the first (and currently only) module. The interface is designed so additional modules can be added without further changes to Protocol.Test fixes: Integration tests for
createMessageStreamandelicitInputStreamwere updated to declaretaskscapability on the server, sinceexperimental.tasks.*methods correctly require it. ThecreateMessageStreamtask-related tests were also restructured with sharedbeforeEach/afterEachto eliminate repeated inline server creation.