Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Match functions and methods

Jeremiah Lowin794ef3f11403
diff --git a/src/fastmcp/prompts/prompt.py b/src/fastmcp/prompts/prompt.py
index 0b870438e..d9bae2b9a 100644
--- a/src/fastmcp/prompts/prompt.py
+++ b/src/fastmcp/prompts/prompt.py
@@ -112,7 +112,7 @@ class Prompt(BaseModel):
description = description or fn.__doc__
# if the fn is a callable class, we need to get the __call__ method from here out
- if not inspect.isfunction(fn):
+ if not inspect.isroutine(fn):
fn = fn.__call__
type_adapter = get_cached_typeadapter(fn)
diff --git a/src/fastmcp/resources/template.py b/src/fastmcp/resources/template.py
index 9e7984a67..b7adb9481 100644
--- a/src/fastmcp/resources/template.py
+++ b/src/fastmcp/resources/template.py
@@ -150,7 +150,7 @@ class ResourceTemplate(BaseModel):
description = description or fn.__doc__ or ""
- if not inspect.isfunction(fn):
+ if not inspect.isroutine(fn):
fn = fn.__call__
type_adapter = get_cached_typeadapter(fn)
diff --git a/src/fastmcp/tools/tool.py b/src/fastmcp/tools/tool.py
index 4f22ca4f6..e92eda26b 100644
--- a/src/fastmcp/tools/tool.py
+++ b/src/fastmcp/tools/tool.py
@@ -77,7 +77,7 @@ class Tool(BaseModel):
func_doc = description or fn.__doc__ or ""
# if the fn is a callable class, we need to get the __call__ method from here out
- if not inspect.isfunction(fn):
+ if not inspect.isroutine(fn):
fn = fn.__call__
type_adapter = get_cached_typeadapter(fn)
diff --git a/tests/utilities/test_tests.py b/tests/utilities/test_tests.py
index 9d4ea8822..104aaf9e6 100644
--- a/tests/utilities/test_tests.py
+++ b/tests/utilities/test_tests.py
@@ -4,6 +4,7 @@ from fastmcp.utilities.tests import temporary_settings
class TestTemporarySettings:
def test_temporary_settings(self):
- with temporary_settings(log_level="DEBUG"):
- assert fastmcp.settings.settings.log_level == "DEBUG"
- assert fastmcp.settings.settings.log_level == "INFO"
+ assert fastmcp.settings.settings.log_level == "DEBUG"
+ with temporary_settings(log_level="ERROR"):
+ assert fastmcp.settings.settings.log_level == "ERROR"
+ assert fastmcp.settings.settings.log_level == "DEBUG"