@@ -9,7 +9,12 @@ import { Telemetry } from "./telemetry/telemetry.js";
99import { UserConfig } from "./common/config.js" ;
1010import { type ServerEvent } from "./telemetry/types.js" ;
1111import { type ServerCommand } from "./telemetry/types.js" ;
12- import { CallToolRequestSchema , CallToolResult } from "@modelcontextprotocol/sdk/types.js" ;
12+ import {
13+ CallToolRequestSchema ,
14+ CallToolResult ,
15+ SubscribeRequestSchema ,
16+ UnsubscribeRequestSchema ,
17+ } from "@modelcontextprotocol/sdk/types.js" ;
1318import assert from "assert" ;
1419import { ToolBase } from "./tools/tool.js" ;
1520
@@ -27,6 +32,7 @@ export class Server {
2732 public readonly userConfig : UserConfig ;
2833 public readonly tools : ToolBase [ ] = [ ] ;
2934 private readonly startTime : number ;
35+ private readonly subscriptions = new Set < string > ( ) ;
3036
3137 constructor ( { session, mcpServer, userConfig, telemetry } : ServerOptions ) {
3238 this . startTime = Date . now ( ) ;
@@ -42,7 +48,7 @@ export class Server {
4248 this . registerResources ( ) ;
4349 await this . validateConfig ( ) ;
4450
45- this . mcpServer . server . registerCapabilities ( { logging : { } , resources : { listChanged : true } } ) ;
51+ this . mcpServer . server . registerCapabilities ( { logging : { } , resources : { listChanged : true , subscribe : true } } ) ;
4652
4753 // TODO: Eventually we might want to make tools reactive too instead of relying on custom logic.
4854 this . registerTools ( ) ;
@@ -70,6 +76,26 @@ export class Server {
7076 return existingHandler ( request , extra ) ;
7177 } ) ;
7278
79+ this . mcpServer . server . setRequestHandler ( SubscribeRequestSchema , ( { params } ) => {
80+ this . subscriptions . add ( params . uri ) ;
81+ this . session . logger . debug ( {
82+ id : LogId . serverInitialized ,
83+ context : "resources" ,
84+ message : `Client subscribed to resource: ${ params . uri } ` ,
85+ } ) ;
86+ return { } ;
87+ } ) ;
88+
89+ this . mcpServer . server . setRequestHandler ( UnsubscribeRequestSchema , ( { params } ) => {
90+ this . subscriptions . delete ( params . uri ) ;
91+ this . session . logger . debug ( {
92+ id : LogId . serverInitialized ,
93+ context : "resources" ,
94+ message : `Client unsubscribed from resource: ${ params . uri } ` ,
95+ } ) ;
96+ return { } ;
97+ } ) ;
98+
7399 this . mcpServer . server . oninitialized = ( ) : void => {
74100 this . session . setAgentRunner ( this . mcpServer . server . getClientVersion ( ) ) ;
75101
@@ -101,6 +127,16 @@ export class Server {
101127 await this . mcpServer . close ( ) ;
102128 }
103129
130+ public sendResourceListChanged ( ) : void {
131+ this . mcpServer . sendResourceListChanged ( ) ;
132+ }
133+
134+ public sendResourceUpdated ( uri : string ) : void {
135+ if ( this . subscriptions . has ( uri ) ) {
136+ void this . mcpServer . server . sendResourceUpdated ( { uri } ) ;
137+ }
138+ }
139+
104140 /**
105141 * Emits a server event
106142 * @param command - The server command (e.g., "start", "stop", "register", "deregister")
0 commit comments