Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/mcp/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,12 @@ class ToolAnnotations(BaseModel):
Default: true
"""

agencyHint: bool | None = None
"""
If true, this tool encapsulates an internal "agent loop" (e.g., plan–act–observe cycles, tool-chaining, or autonomous retries).
Default: false
"""

model_config = ConfigDict(extra="allow")


Expand Down
5 changes: 4 additions & 1 deletion tests/server/fastmcp/test_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ def read_data(path: str) -> str: # pragma: no cover
title="File Reader",
readOnlyHint=True,
openWorldHint=False,
agencyHint=True,
)

manager = ToolManager()
Expand All @@ -437,14 +438,15 @@ def read_data(path: str) -> str: # pragma: no cover
assert tool.annotations.title == "File Reader"
assert tool.annotations.readOnlyHint is True
assert tool.annotations.openWorldHint is False
assert tool.annotations.agencyHint is True

@pytest.mark.anyio
async def test_tool_annotations_in_fastmcp(self):
"""Test that tool annotations are included in MCPTool conversion."""

app = FastMCP()

@app.tool(annotations=ToolAnnotations(title="Echo Tool", readOnlyHint=True))
@app.tool(annotations=ToolAnnotations(title="Echo Tool", readOnlyHint=True, agencyHint=False))
def echo(message: str) -> str: # pragma: no cover
"""Echo a message back."""
return message
Expand All @@ -454,6 +456,7 @@ def echo(message: str) -> str: # pragma: no cover
assert tools[0].annotations is not None
assert tools[0].annotations.title == "Echo Tool"
assert tools[0].annotations.readOnlyHint is True
assert tools[0].annotations.agencyHint is False


class TestStructuredOutput:
Expand Down
2 changes: 2 additions & 0 deletions tests/server/test_lowlevel_tool_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async def list_tools(): # pragma: no cover
annotations=ToolAnnotations(
title="Echo Tool",
readOnlyHint=True,
agencyHint=True,
),
)
]
Expand Down Expand Up @@ -98,3 +99,4 @@ async def handle_messages():
assert tools_result.tools[0].annotations is not None
assert tools_result.tools[0].annotations.title == "Echo Tool"
assert tools_result.tools[0].annotations.readOnlyHint is True
assert tools_result.tools[0].annotations.agencyHint is True
Loading