-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add Support for SEP-2084: Primitive Grouping #1399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Support for SEP-2084: Primitive Grouping #1399
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: |
* 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
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