Add strict mode to pyright (#315)

* Add strict mode to pyright

* Apply UP rule

* fix readme

* More correct

* Leave wrong Context for now

* Add strict mode to pyright

* Apply UP rule

* fix readme

* fix

* ignore
This commit is contained in:
Marcelo Trylesinski 2025-03-20 09:13:08 +00:00 • committed by GitHub
commit ae77772ea8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 194 additions and 133 deletions

View file

@ -1,11 +1,11 @@
from __future__ import annotations as _annotations
import inspect
from typing import TYPE_CHECKING, Any, Callable
from collections.abc import Callable
from typing import TYPE_CHECKING, Any
from pydantic import BaseModel, Field
import mcp.server.fastmcp
from mcp.server.fastmcp.exceptions import ToolError
from mcp.server.fastmcp.utilities.func_metadata import FuncMetadata, func_metadata
@ -38,8 +38,10 @@ class Tool(BaseModel):
name: str | None = None,
description: str | None = None,
context_kwarg: str | None = None,
) -> "Tool":
) -> Tool:
"""Create a Tool from a function."""
from mcp.server.fastmcp import Context
func_name = name or fn.__name__
if func_name == "<lambda>":
@ -48,11 +50,10 @@ class Tool(BaseModel):
func_doc = description or fn.__doc__ or ""
is_async = inspect.iscoroutinefunction(fn)
# Find context parameter if it exists
if context_kwarg is None:
sig = inspect.signature(fn)
for param_name, param in sig.parameters.items():
if param.annotation is mcp.server.fastmcp.Context:
if param.annotation is Context:
context_kwarg = param_name
break

View file

@ -32,7 +32,7 @@ class ToolManager:
def add_tool(
self,
fn: Callable,
fn: Callable[..., Any],
name: str | None = None,
description: str | None = None,
) -> Tool: