Skip to content

Commit 1e88579

Browse files
committed
Implementation Details
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
1 parent f657ead commit 1e88579

File tree

3 files changed

+465
-51
lines changed

3 files changed

+465
-51
lines changed

src/client/index.ts

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,16 @@ import {
2121
Implementation,
2222
InitializeResultSchema,
2323
LATEST_PROTOCOL_VERSION,
24+
ListGroupsRequest,
25+
ListGroupsResultSchema,
2426
ListPromptsRequest,
2527
ListPromptsResultSchema,
2628
ListResourcesRequest,
2729
ListResourcesResultSchema,
2830
ListResourceTemplatesRequest,
2931
ListResourceTemplatesResultSchema,
32+
ListTagsRequest,
33+
ListTagsResultSchema,
3034
ListToolsRequest,
3135
ListToolsResultSchema,
3236
LoggingLevel,
@@ -501,8 +505,13 @@ export class Client<
501505
params?: ListToolsRequest["params"],
502506
options?: RequestOptions,
503507
) {
508+
const request: ListToolsRequest = {
509+
method: "tools/list",
510+
params: params || {},
511+
};
512+
504513
const result = await this.request(
505-
{ method: "tools/list", params },
514+
request,
506515
ListToolsResultSchema,
507516
options,
508517
);
@@ -513,6 +522,32 @@ export class Client<
513522
return result;
514523
}
515524

525+
async listGroups(
526+
params?: ListGroupsRequest["params"],
527+
options?: RequestOptions,
528+
) {
529+
this.assertCapabilityForMethod("groups/list");
530+
// Use type assertion with unknown as intermediate step
531+
return this.request(
532+
{ method: "groups/list", params: params || {} } as unknown as ClientRequest,
533+
ListGroupsResultSchema,
534+
options,
535+
);
536+
}
537+
538+
async listTags(
539+
params?: ListTagsRequest["params"],
540+
options?: RequestOptions,
541+
) {
542+
this.assertCapabilityForMethod("tags/list");
543+
// Use type assertion with unknown as intermediate step
544+
return this.request(
545+
{ method: "tags/list", params: params || {} } as unknown as ClientRequest,
546+
ListTagsResultSchema,
547+
options,
548+
);
549+
}
550+
516551
async sendRootsListChanged() {
517552
return this.notification({ method: "notifications/roots/list_changed" });
518553
}

0 commit comments

Comments
 (0)