Group/Tag Filtering Implementation for SEP-1300#840
Closed
cliffhall wants to merge 3 commits intomodelcontextprotocol:mainfrom
Closed
Group/Tag Filtering Implementation for SEP-1300#840cliffhall wants to merge 3 commits intomodelcontextprotocol:mainfrom
cliffhall wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
The implementation follows the MCP specification for filtering capabilities: Server Capabilities: Servers can now declare support for filtering with the filtering capability, including whether list change notifications are supported. Group Primitive: Groups are collections of tools that separate the server's toolspace by functionality or use case. Tag Primitive: Tags are labels that can be attached to tools to denote cross-cutting concerns like status or operational safety. Filter Parameter: The tools/list method now accepts a filter parameter that allows filtering tools by groups and tags. Tool Definition: Tools can now be associated with groups and tags, which are included in the tool definition. The implementation is fully backward compatible - if the filter parameter is omitted, all tools are returned as before. In src/types.ts * Added a new filtering capability to the ServerCapabilitiesSchema to allow servers to declare support for filtering groups and tags * Created new schemas for groups and tags: GroupSchema: Defines a group that contains tools, with name, title, and description TagSchema: Defines a tag that can be attached to tools, with name and description * Extended the ToolSchema to include optional groups and tags properties * Added a ToolsFilterSchema to define filter parameters for the tools/list request * Extended the ListToolsRequestSchema to include the filter parameter * Added new request/response schemas for group and tag operations: ListGroupsRequestSchema and ListGroupsResultSchema ListTagsRequestSchema and ListTagsResultSchema * Added notification schemas for group and tag list changes: GroupListChangedNotificationSchema TagListChangedNotificationSchema Added type exports for all the new schemas In src/client/index.ts Added client-side methods to support the new filtering capabilities: * Added imports for the new types and schemas * Implemented listGroups() method to request a list of groups from the server * Implemented listTags() method to request a list of tags from the server * Updated the listTools() method to properly handle the filter parameter In src/server/mcp.ts Added server-side implementation for filtering capabilities: * Added imports for the new types * Added registration of the filtering capability in the McpServer constructor * Added storage for registered groups and tags with _registeredGroups and _registeredTags properties * Implemented request handlers for groups and tags: - setGroupRequestHandlers() for handling group-related requests - setTagRequestHandlers() for handling tag-related requests * Updated the ListToolsRequestSchema handler to support filtering by groups and tags * Extended the RegisteredTool type to include groups and tags * Added methods to send group and tag list changed notifications: - sendGroupListChanged() - sendTagListChanged() * Added methods to register groups and tags: - registerGroup(): Registers a group with name, title, and description - registerTag(): Registers a tag with name and description
In src/client/filtering.test.ts * Tests client-side filtering capabilities * Verifies listGroups and listTags methods work correctly * Tests filtering tools by groups, tags, and combinations * Verifies error handling when filtering capability is not available In src/server/filtering.test.ts * Tests server-side filtering capabilities * Verifies group and tag registration, updating, and removal * Tests filtering tools by groups, tags, and combinations * Verifies that tools match ANY of the specified groups * Verifies that tools match ALL of the specified tags In src/integration-tests/filtering.test.ts * End-to-end tests for filtering capabilities * Tests listing groups and tags * Tests filtering tools by groups, tags, and combinations * Verifies correct behavior with real HTTP server and transports
The filtering examples demonstrate the implementation of the MCP filtering capabilities through a client-server application. These examples showcase how to organize tools into logical groups and tag them with cross-cutting concerns, allowing clients to filter tools to avoid LLM context overload.
0845a57 to
c94ba4b
Compare
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.
Groups and tags implementation. See SEP-1300 - Tool Filtering with Groups and Tags
Motivation and Context
It is an implementation for an SEP and not expected to be merged. It contains updates to the SDK, unit tests, integration tests, and examples
How Has This Been Tested?
In addition to unit tests and integration tests, there are client and server examples that work together:
Breaking Changes
Nope.
Types of changes
Checklist
Additional context