Skip to content

Commit 877db76

Browse files
fix: add type annotations to fix Pyright errors
ROOT CAUSE: Pyright reported 8 type errors about partially unknown types in list operations and dictionary assignments. The issues were: - skip_names list type inference - direct_args dict type inference - param.default type casting CHANGES: - Added explicit type annotation `skip_names: list[str]` in tools/base.py - Added explicit type annotation `skip_names: list[str]` in prompts/base.py - Added explicit type annotation `direct_args: dict[str, Any]` in tools/base.py - Added type ignore comment for param.default assignment in dependencies.py IMPACT: - Fixes all 8 Pyright type errors - CI pre-commit hook will now pass - Type safety improved with explicit annotations Refs: #2081
1 parent 4ca7742 commit 877db76

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/mcp/server/mcpserver/prompts/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def from_function(
111111
dependency_kwarg_names = list(dependency_params.keys())
112112

113113
# Get schema from func_metadata, excluding context and dependency parameters
114-
skip_names = []
114+
skip_names: list[str] = []
115115
if context_kwarg:
116116
skip_names.append(context_kwarg)
117117
skip_names.extend(dependency_kwarg_names)

src/mcp/server/mcpserver/tools/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def from_function(
7878
dependency_kwarg_names = list(dependency_params.keys())
7979

8080
# Skip both context and dependency params from arg_model
81-
skip_names = []
81+
skip_names: list[str] = []
8282
if context_kwarg:
8383
skip_names.append(context_kwarg)
8484
skip_names.extend(dependency_kwarg_names)
@@ -115,7 +115,7 @@ async def run(
115115
"""Run the tool with arguments."""
116116
try:
117117
# Build direct args (context and dependencies)
118-
direct_args = {}
118+
direct_args: dict[str, Any] = {}
119119
if self.context_kwarg is not None:
120120
direct_args[self.context_kwarg] = context
121121

src/mcp/server/mcpserver/utilities/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ def find_dependency_parameters(
6363

6464
# Check if default is Depends instance
6565
if isinstance(param.default, Depends):
66-
deps[param_name] = param.default
66+
deps[param_name] = param.default # type: ignore[assignment]
6767

6868
return deps

0 commit comments

Comments
 (0)