From e485eb298f5289394f45f472d8071de13bab6b90 Mon Sep 17 00:00:00 2001 From: Ryan Fang Date: Mon, 16 Jun 2025 14:44:45 +0800 Subject: [PATCH] fix tool description indentation issue #844 https://github.com/jlowin/fastmcp/issues/844 --- src/fastmcp/prompts/prompt.py | 2 +- src/fastmcp/resources/resource.py | 2 +- src/fastmcp/resources/template.py | 2 +- src/fastmcp/tools/tool.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/fastmcp/prompts/prompt.py b/src/fastmcp/prompts/prompt.py index c8193a078..48343e2bb 100644 --- a/src/fastmcp/prompts/prompt.py +++ b/src/fastmcp/prompts/prompt.py @@ -155,7 +155,7 @@ class FunctionPrompt(Prompt): if param.kind == inspect.Parameter.VAR_KEYWORD: raise ValueError("Functions with **kwargs are not supported as prompts") - description = description or fn.__doc__ + description = description or inspect.getdoc(fn) # if the fn is a callable class, we need to get the __call__ method from here out if not inspect.isroutine(fn): diff --git a/src/fastmcp/resources/resource.py b/src/fastmcp/resources/resource.py index fc4ece58f..8e7ce307f 100644 --- a/src/fastmcp/resources/resource.py +++ b/src/fastmcp/resources/resource.py @@ -135,7 +135,7 @@ class FunctionResource(Resource): fn=fn, uri=uri, name=name or fn.__name__, - description=description or fn.__doc__, + description=description or inspect.getdoc(fn), mime_type=mime_type or "text/plain", tags=tags or set(), enabled=enabled if enabled is not None else True, diff --git a/src/fastmcp/resources/template.py b/src/fastmcp/resources/template.py index 36e05be11..acbb98eeb 100644 --- a/src/fastmcp/resources/template.py +++ b/src/fastmcp/resources/template.py @@ -214,7 +214,7 @@ class FunctionResourceTemplate(ResourceTemplate): f"URI parameters {uri_params} must be a subset of the function arguments: {func_params}" ) - description = description or fn.__doc__ + description = description or inspect.getdoc(fn) # if the fn is a callable class, we need to get the __call__ method from here out if not inspect.isroutine(fn): diff --git a/src/fastmcp/tools/tool.py b/src/fastmcp/tools/tool.py index 9b94bb00e..14fe7f8b6 100644 --- a/src/fastmcp/tools/tool.py +++ b/src/fastmcp/tools/tool.py @@ -231,7 +231,7 @@ class ParsedFunction: # collect name and doc before we potentially modify the function fn_name = getattr(fn, "__name__", None) or fn.__class__.__name__ - fn_doc = fn.__doc__ + fn_doc = inspect.getdoc(fn) # if the fn is a callable class, we need to get the __call__ method from here out if not inspect.isroutine(fn):