File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed
src/mcp/server/fastmcp/resources Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,14 @@ async def read(self, context: Any | None = None) -> str | bytes:
6666 else :
6767 result = self .fn (** args )
6868
69+ # Support cases where a sync function returns a coroutine
70+ if inspect .iscoroutine (result ):
71+ result = await result
72+
73+ # Support returning a Resource instance (recursive read)
74+ if isinstance (result , Resource ):
75+ return await result .read (context )
76+
6977 if isinstance (result , str | bytes ):
7078 return result
7179 if isinstance (result , pydantic .BaseModel ):
@@ -208,4 +216,4 @@ async def read(self, context: Any | None = None) -> str: # Always returns JSON
208216 file_list = [str (f .relative_to (self .path )) for f in files if f .is_file ()]
209217 return json .dumps ({"files" : file_list }, indent = 2 )
210218 except Exception as e :
211- raise ValueError (f"Error reading directory { self .path } : { e } " )
219+ raise ValueError (f"Error reading directory { self .path } : { e } " )
You can’t perform that action at this time.
0 commit comments