Skip to content

Parameterless tools expose Returns: as part of their description #4952

Closed

Description

@pvliesdonk

What happened?

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

import asyncio

from fastmcp import Client, FastMCP

mcp = FastMCP("repro")


@mcp.tool
async def status() -> dict[str, bool]:
    """Return current status.

    Returns:
        A dict containing the current status.
    """
    return {"ok": True}


async def main() -> None:
    async with Client(mcp) as client:
        [tool] = await client.list_tools()
        print(repr(tool.description))
        assert tool.description == "Return current status."


asyncio.run(main())

Actual description:

Return current status.\n\nReturns:\n    A dict containing the current status.

Version Information

FastMCP version: 3.4.7
MCP version: 1.29.0
Python version: 3.12.11
Platform: Linux-7.1.8-arch1-3-x86_64-with-glibc2.44

Generated by Claude Code

Activity

  1. added
    bug
    on Aug 31, 2026
  2. Ewertonslv commented on Aug 31, 2026

    @Ewertonslv

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions