In roots.ts, clientCapabilites.roots and response.roots are optional.
Fixes #2818
This commit is contained in:
parent
9691b958ec
commit
7300631a5c
1 changed files with 3 additions and 3 deletions
|
|
@ -30,7 +30,7 @@ export const roots: Map<string | undefined, Root[]> = new Map<
|
||||||
*/
|
*/
|
||||||
export const syncRoots = async (server: McpServer, sessionId?: string) => {
|
export const syncRoots = async (server: McpServer, sessionId?: string) => {
|
||||||
const clientCapabilities = server.server.getClientCapabilities() || {};
|
const clientCapabilities = server.server.getClientCapabilities() || {};
|
||||||
const clientSupportsRoots: boolean = clientCapabilities.roots !== undefined;
|
const clientSupportsRoots: boolean = clientCapabilities?.roots !== undefined;
|
||||||
|
|
||||||
// Fetch the roots list for this client
|
// Fetch the roots list for this client
|
||||||
if (clientSupportsRoots) {
|
if (clientSupportsRoots) {
|
||||||
|
|
@ -41,14 +41,14 @@ export const syncRoots = async (server: McpServer, sessionId?: string) => {
|
||||||
const response = await server.server.listRoots();
|
const response = await server.server.listRoots();
|
||||||
if (response && "roots" in response) {
|
if (response && "roots" in response) {
|
||||||
// Store the roots list for this client
|
// Store the roots list for this client
|
||||||
roots.set(sessionId, response.roots);
|
roots.set(sessionId, response?.roots);
|
||||||
|
|
||||||
// Notify the client of roots received
|
// Notify the client of roots received
|
||||||
await server.sendLoggingMessage(
|
await server.sendLoggingMessage(
|
||||||
{
|
{
|
||||||
level: "info",
|
level: "info",
|
||||||
logger: "everything-server",
|
logger: "everything-server",
|
||||||
data: `Roots updated: ${response.roots.length} root(s) received from client`,
|
data: `Roots updated: ${response?.roots?.length} root(s) received from client`,
|
||||||
},
|
},
|
||||||
sessionId
|
sessionId
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue