11"""FastMCP - A more ergonomic interface for MCP servers."""
22
3- import functools
43import inspect
54import json
65import re
@@ -305,9 +304,19 @@ def resource(
305304 def get_data() -> str:
306305 return "Hello, world!"
307306
307+ @server.resource("resource://my-resource")
308+ async get_data() -> str:
309+ data = await fetch_data()
310+ return f"Hello, world! {data}"
311+
308312 @server.resource("resource://{city}/weather")
309313 def get_weather(city: str) -> str:
310314 return f"Weather for {city}"
315+
316+ @server.resource("resource://{city}/weather")
317+ async def get_weather(city: str) -> str:
318+ data = await fetch_weather(city)
319+ return f"Weather for {city}: {data}"
311320 """
312321 # Check if user passed function directly instead of calling decorator
313322 if callable (uri ):
@@ -317,10 +326,6 @@ def get_weather(city: str) -> str:
317326 )
318327
319328 def decorator (fn : Callable ) -> Callable :
320- @functools .wraps (fn )
321- def wrapper (* args : Any , ** kwargs : Any ) -> Any :
322- return fn (* args , ** kwargs )
323-
324329 # Check if this should be a template
325330 has_uri_params = "{" in uri and "}" in uri
326331 has_func_params = bool (inspect .signature (fn ).parameters )
@@ -338,7 +343,7 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
338343
339344 # Register as template
340345 self ._resource_manager .add_template (
341- wrapper ,
346+ fn = fn ,
342347 uri_template = uri ,
343348 name = name ,
344349 description = description ,
@@ -351,10 +356,10 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
351356 name = name ,
352357 description = description ,
353358 mime_type = mime_type or "text/plain" ,
354- fn = wrapper ,
359+ fn = fn ,
355360 )
356361 self .add_resource (resource )
357- return wrapper
362+ return fn
358363
359364 return decorator
360365
0 commit comments