Skip to content

Commit 3ef9023

Browse files
authored
Merge pull request #334 from m-paternostro/mp/notifier
Capability notification for the MCP Server
2 parents 5b6d35e + 94759c3 commit 3ef9023

File tree

6 files changed

+1701
-61
lines changed

6 files changed

+1701
-61
lines changed

src/examples/server/simpleStreamableHttp.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ const server = new McpServer({
1212
version: '1.0.0',
1313
}, { capabilities: { logging: {} } });
1414

15+
// Log the capability invocation details
16+
server.onCapabilityChange((event) => {
17+
switch (event.action) {
18+
case 'invoked':
19+
console.log(`${event.capabilityType} invocation ${event.invocationIndex}: '${event.capabilityName}' started`);
20+
break;
21+
case 'completed':
22+
console.log(`${event.capabilityType} invocation ${event.invocationIndex}: '${event.capabilityName}' completed in ${event.durationMs}ms`);
23+
break;
24+
case 'error':
25+
console.log(`${event.capabilityType} invocation ${event.invocationIndex}: '${event.capabilityName}' failed in ${event.durationMs}ms: ${event.error}`);
26+
break;
27+
}
28+
});
29+
1530
// Register a simple tool that returns a greeting
1631
server.tool(
1732
'greet',
@@ -291,4 +306,4 @@ process.on('SIGINT', async () => {
291306
await server.close();
292307
console.log('Server shutdown complete');
293308
process.exit(0);
294-
});
309+
});

src/server/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ export class Server<
104104
);
105105
}
106106

107+
/**
108+
* The server's name and version.
109+
*/
110+
getVersion(): { readonly name: string; readonly version: string } {
111+
return this._serverInfo;
112+
}
113+
107114
/**
108115
* Registers new capabilities. This can only be called before connecting to a transport.
109116
*

0 commit comments

Comments
 (0)