Add Support for SEP-2084: Primitive Grouping#1399
Draft
cliffhall wants to merge 13 commits intomodelcontextprotocol:mainfrom
Draft
Add Support for SEP-2084: Primitive Grouping#1399cliffhall wants to merge 13 commits intomodelcontextprotocol:mainfrom
cliffhall wants to merge 13 commits intomodelcontextprotocol:mainfrom
Conversation
… allowing servers to organize primitives (tools, prompts, tasks, resources, and groups themselves) into logical groups. This change includes updates to the core protocol schemas, high-level server and client APIs, and comprehensive testing. ### PR Description: Implementation of Groups Primitive This PR introduces the `groups` primitive to the Model Context Protocol TypeScript SDK, enabling servers to categorize and organize their offerings. #### Core Changes (`@modelcontextprotocol/core`) **`src/types/types.ts`** - Added `GROUPS_META_KEY` constant (`io.modelcontextprotocol/groups`). - Updated `BaseMetadataSchema` to include `name` and optional `title`. - Introduced `GroupSchema` and `Group` type for defining group objects. - Added `ServerCapabilitiesSchema.groups` to allow servers to advertise group support and `listChanged` notifications. - Added `ListGroupsRequestSchema`, `ListGroupsResultSchema`, and `GroupListChangedNotificationSchema` for protocol-level group management. - Updated `ToolSchema`, `PromptSchema`, `ResourceSchema`, and `TaskSchema` to support the `groups` key in their `_meta` objects. - Added `ListChangedHandlers` support for groups in client-side configuration. **`src/shared/protocol.ts`** - Added `listGroups` method to the base `Protocol` class to handle `groups/list` requests. #### Server Changes (`@modelcontextprotocol/server`) **`src/server/server.ts`** - Added `sendGroupListChanged()` method to the `Server` class to emit `notifications/groups/list_changed` to connected clients. **`src/server/mcp.ts`** - Added `registerGroup()` to the high-level `McpServer` API. - Implemented automatic handling of `groups/list` requests. - Updated `registerTool`, `registerPrompt`, and `registerResource` to correctly propagate `_meta` information (including group memberships) to the client. - Modified registration logic to be "connection-aware": capabilities and request handlers are registered before connection, while `list_changed` notifications are sent if changes occur post-connection. - Improved `update()` methods for registered primitives to handle dynamic name changes and metadata updates. #### Client Changes (`@modelcontextprotocol/client`) **`src/client/client.ts`** - Added `listGroups()` method to fetch the list of groups from a server. - Integrated `groups` into the `listChanged` notification handling system, allowing clients to automatically refresh group lists when the server notifies of changes. #### Testing **`packages/server/test/server/groups.test.ts` (New)** - Verified group registration and listing. - Verified mixed membership: tools, prompts, resources, and task-tools assigned to the same group. - Verified nested groups (groups within groups). - Verified that `_meta.groups` is only present in listed primitives when they are actually assigned to a group. **`test/integration/test/client/client.test.ts`** - Added integration tests for `groups/list` and `notifications/groups/list_changed`. - Ensured proper synchronization between server registration and client-side auto-refresh logic.
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
9 tasks
* In groupsExample.ts
- implement a server with
- two parent groups (communications and work)
- several child groups (email, calendar, spreadsheets, documents, todos).
- prompts, resources, and tools organized into groups
* In groupsExampleClient.ts
- implement a command line REPL with commands
- all/a - list all groups, tools, resources, and prompts
- groups/g/enter - list available groups
- help/h - for a list of commands
- quit/q - to exit the program
- enter a command name or a list of groups to filter by
* In examples/client/README.md
- document the example client groupsExampleClient.ts
* In examples/server/README.md
- document the example server groupsExample.ts
- simplify command prompt
- replace GroupSchema._meta definition with the simplified one used in the other primitives
- define GroupsWithMetaSchema - In all primitives, replace _meta defintion with reference to GroupsWithMetaSchema
- Export GroupMeta
In mcp.ts
- Import GroupMeta
- use as type of _meta argument in
- _createRegisteredResource
- automatically via ResourceMetadata which uses it
- _createRegisteredResourceTemplate
- automatically via ResourceMetadata which uses it
- _createRegisteredPrompt
- _createRegisteredGroup
- _createRegisteredTool
- fix linting complaints
- Add documentation to examples - Add support for setting display depth
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.
Implemented the new
groupsprimitive across the MCP TypeScript SDK, allowing servers to organize primitives (tools, prompts, tasks, resources, and groups themselves) into logical groups. This change includes updates to the core protocol schemas, high-level server and client APIs, and comprehensive testing.PR Description: Implementation of Groups Primitive
This PR introduces the
groupsprimitive to the Model Context Protocol TypeScript SDK, enabling servers to categorize and organize their offerings.Core Changes (
@modelcontextprotocol/core)src/types/types.tsGROUPS_META_KEYconstant (io.modelcontextprotocol/groups).BaseMetadataSchemato includenameand optionaltitle.GroupSchemaandGrouptype for defining group objects.ServerCapabilitiesSchema.groupsto allow servers to advertise group support andlistChangednotifications.ListGroupsRequestSchema,ListGroupsResultSchema, andGroupListChangedNotificationSchemafor protocol-level group management.ToolSchema,PromptSchema,ResourceSchema, andTaskSchemato support thegroupskey in their_metaobjects.ListChangedHandlerssupport for groups in client-side configuration.src/shared/protocol.tslistGroupsmethod to the baseProtocolclass to handlegroups/listrequests.Server Changes (
@modelcontextprotocol/server)src/server/server.tssendGroupListChanged()method to theServerclass to emitnotifications/groups/list_changedto connected clients.src/server/mcp.tsregisterGroup()to the high-levelMcpServerAPI.groups/listrequests.registerTool,registerPrompt, andregisterResourceto correctly propagate_metainformation (including group memberships) to the client.list_changednotifications are sent if changes occur post-connection.update()methods for registered primitives to handle dynamic name changes and metadata updates.Client Changes (
@modelcontextprotocol/client)src/client/client.tslistGroups()method to fetch the list of groups from a server.groupsinto thelistChangednotification handling system, allowing clients to automatically refresh group lists when the server notifies of changes.Examples (
@modelcontextprotocol/examples)src/examples/server/src/groupsExample.ts(New)src/examples/server/README.mdgroupsExample.tssrc/examples/client/src/groupsExampleClient.ts(New)src/examples/client/README.mdgroupsExampleClient.tsTesting
packages/server/test/server/groups.test.ts(New)_meta.groupsis only present in listed primitives when they are actually assigned to a group.test/integration/test/client/client.test.tsgroups/listandnotifications/groups/list_changed.Motivation and Context
Reference implementation for SEP-2084: Primitive Grouping.
How Has This Been Tested?
Run the example client
pnpm --filter @modelcontextprotocol/examples-client exec tsx src/groupsExampleClient.tsThe Menu
List All Primitives
Filter all by a parent group
Filter all by a leaf group
Enter a command or a list of groups to filter by: todos Groups: (none) Tools: - todos_add — Add a todo item. - todos_complete — Mark a todo item complete. Resources: - todos_overview — A short overview of task management basics. Prompts: - todos_plan_day — Turn a list of tasks into a simple day plan.Breaking Changes
None.
Types of changes
Checklist
Additional context