Skip to content

Commit 57240a2

Browse files
authored
Merge pull request #306 from CasperGN/chore/stronger-tool-return-types
fix: improve type checking for the mcp and toolbox functions
2 parents 027dfde + 2505989 commit 57240a2

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

dapr_agents/tool/base.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import inspect
24
import logging
35
from typing import TYPE_CHECKING, Callable, Type, Optional, Any, Dict
@@ -80,10 +82,10 @@ def from_func(cls, func: Callable) -> "AgentTool":
8082
@classmethod
8183
def from_mcp(
8284
cls,
83-
mcp_tool: "MCPTool",
84-
session: "Optional[ClientSession]" = None,
85+
mcp_tool: MCPTool,
86+
session: Optional[ClientSession] = None,
8587
connection: Any = None,
86-
) -> "AgentTool":
88+
) -> AgentTool:
8789
"""
8890
Create an AgentTool from an MCPTool and a session or connection.
8991
@@ -157,10 +159,10 @@ async def executor(**kwargs: Any) -> Any:
157159
@classmethod
158160
def from_mcp_many(
159161
cls,
160-
mcp_tools: list,
161-
session: "ClientSession" = None,
162+
mcp_tools: list[MCPTool],
163+
session: Optional[ClientSession] = None,
162164
connection: Any = None,
163-
) -> list:
165+
) -> list[AgentTool]:
164166
"""
165167
Batch-create AgentTool objects from a list of MCPTool objects.
166168
@@ -182,7 +184,7 @@ def from_mcp_many(
182184
]
183185

184186
@classmethod
185-
async def from_mcp_session(cls, session: "ClientSession") -> list:
187+
async def from_mcp_session(cls, session: ClientSession) -> list[AgentTool]:
186188
"""
187189
Fetch all tools and wrap them as AgentTool objects.
188190
@@ -201,8 +203,8 @@ async def from_mcp_session(cls, session: "ClientSession") -> list:
201203
@classmethod
202204
def from_toolbox(
203205
cls,
204-
toolbox_tool: "ToolboxSyncTool",
205-
) -> "AgentTool":
206+
toolbox_tool: ToolboxSyncTool,
207+
) -> AgentTool:
206208
"""
207209
Create an AgentTool from a ToolboxSyncTool.
208210
@@ -275,8 +277,8 @@ def executor(**kwargs: Any) -> Any:
275277
@classmethod
276278
def from_toolbox_many(
277279
cls,
278-
toolbox_tools: list,
279-
) -> list:
280+
toolbox_tools: list[ToolboxSyncTool],
281+
) -> list[AgentTool]:
280282
"""
281283
Batch-create AgentTool objects from a list of ToolboxSyncTool objects.
282284

0 commit comments

Comments
 (0)