You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Parameterless tools expose Returns: as part of their description #4952
A parameterless tool with a Google-style docstring exposes the entire raw docstring, including its Returns: section, as the client-visible tool description. I expected only the leading description text, matching FastMCP's docstring documentation and the behavior of tools whose parameter descriptions are parsed.
Example Code
importasynciofromfastmcpimportClient, FastMCPmcp=FastMCP("repro")
@mcp.toolasyncdefstatus() ->dict[str, bool]:
"""Return current status. Returns: A dict containing the current status. """return {"ok": True}
asyncdefmain() ->None:
asyncwithClient(mcp) asclient:
[tool] =awaitclient.list_tools()
print(repr(tool.description))
asserttool.description=="Return current status."asyncio.run(main())
Actual description:
Return current status.\n\nReturns:\n A dict containing the current status.
I'd like to take this one — root cause looks clear: parse_docstring() in src/fastmcp/utilities/docstring_parsing.py (or the fastmcp_slim mirror) tries each of the google/numpy/sphinx parsers in turn and only accepts a parser's result when it finds a parameters section (line ~61: if parameters: return ParsedDocstring(...)). For a parameterless tool none of the three ever populate parameters, so the loop falls through to the final fallback, which returns the raw, unparsed docstring as the description — Returns: section included — instead of using the description that Google's own parser already extracted correctly.
Planned fix: track the best description found across the parser attempts (even when that attempt found no parameters) and return it instead of the raw docstring, only falling back to the truly-raw doc when no parser produced any structured section at all. Will add a regression test mirroring the repro in the issue plus a couple of adjacent cases (parameterless tool with only Args: no Returns:, and one with both) in tests/utilities/test_docstring_parsing.py.
Could you assign this to me? Happy to open the PR right after.
Activity
Ewertonslv commentedon Aug 31, 2026
I'd like to take this one — root cause looks clear:
parse_docstring()insrc/fastmcp/utilities/docstring_parsing.py(or thefastmcp_slimmirror) tries each of the google/numpy/sphinx parsers in turn and only accepts a parser's result when it finds aparameterssection (line ~61:if parameters: return ParsedDocstring(...)). For a parameterless tool none of the three ever populateparameters, so the loop falls through to the final fallback, which returns the raw, unparsed docstring as the description —Returns:section included — instead of using thedescriptionthat Google's own parser already extracted correctly.Planned fix: track the best
descriptionfound across the parser attempts (even when that attempt found no parameters) and return it instead of the raw docstring, only falling back to the truly-raw doc when no parser produced any structured section at all. Will add a regression test mirroring the repro in the issue plus a couple of adjacent cases (parameterless tool with onlyArgs:noReturns:, and one with both) intests/utilities/test_docstring_parsing.py.Could you assign this to me? Happy to open the PR right after.