Get roots unconditionally when syncRoots is called
* In server/roots.ts - in syncRoots, if roots are supported fetch them * In get-roots-list.ts, - Don't import and inspect current roots map, just call syncRoots to get the list.
This commit is contained in:
parent
1b8f376b90
commit
c6daef707a
2 changed files with 5 additions and 14 deletions
|
|
@ -27,8 +27,8 @@ 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;
|
||||||
|
|
||||||
// If roots have not been fetched for this client, fetch them
|
// Fetch the roots list for this client
|
||||||
if (clientSupportsRoots && !roots.has(sessionId)) {
|
if (clientSupportsRoots) {
|
||||||
// Function to request the updated roots list from the client
|
// Function to request the updated roots list from the client
|
||||||
const requestRoots = async () => {
|
const requestRoots = async () => {
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
||||||
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
||||||
import { roots, syncRoots } from "../server/roots.js";
|
import { syncRoots } from "../server/roots.js";
|
||||||
|
|
||||||
// Tool configuration
|
// Tool configuration
|
||||||
const name = "get-roots-list";
|
const name = "get-roots-list";
|
||||||
|
|
@ -39,17 +39,8 @@ export const registerGetRootsListTool = (server: McpServer) => {
|
||||||
name,
|
name,
|
||||||
config,
|
config,
|
||||||
async (args, extra): Promise<CallToolResult> => {
|
async (args, extra): Promise<CallToolResult> => {
|
||||||
// Check if the roots list is already cached for this client
|
// Get the current rootsFetch the current roots list from the client if need be
|
||||||
const rootsCached = roots?.has(extra.sessionId);
|
const currentRoots = await syncRoots(server, extra.sessionId);
|
||||||
|
|
||||||
// Fetch the current roots list from the client if need be
|
|
||||||
const currentRoots = rootsCached
|
|
||||||
? roots.get(extra.sessionId)
|
|
||||||
: await syncRoots(server, extra.sessionId);
|
|
||||||
|
|
||||||
// If roots had to be fetched, store them in the cache
|
|
||||||
if (currentRoots && !rootsCached)
|
|
||||||
roots.set(extra.sessionId, currentRoots);
|
|
||||||
|
|
||||||
// Respond if client supports roots but doesn't have any configured
|
// Respond if client supports roots but doesn't have any configured
|
||||||
if (
|
if (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue