Skip to content

Commit 8fb7988

Browse files
committed
linting and formatting
1 parent 5d43128 commit 8fb7988

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

src/mcp/server/fastmcp/resources/templates.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
import inspect
66
import re
77
from collections.abc import Callable
8-
from typing import TYPE_CHECKING, Any, Dict, List
8+
from typing import TYPE_CHECKING, Any
99

1010
from pydantic import BaseModel, Field, validate_call
1111

1212
from mcp.server.fastmcp.resources.types import FunctionResource, Resource
1313
from mcp.server.fastmcp.utilities.context_injection import find_context_parameter, inject_context
14-
from mcp.server.fastmcp.utilities.convertors import Convertor,CONVERTOR_TYPES
14+
from mcp.server.fastmcp.utilities.convertors import CONVERTOR_TYPES, Convertor
1515
from mcp.server.fastmcp.utilities.func_metadata import func_metadata
1616
from mcp.types import Icon
1717

@@ -83,8 +83,8 @@ def matches(self, uri: str) -> dict[str, Any] | None:
8383
uri = str(uri)
8484

8585
parts = uriTemplate.strip("/").split("/")
86-
pattern_parts: List[str] = []
87-
converters: Dict[str, Convertor[Any]] = {}
86+
pattern_parts: list[str] = []
87+
converters: dict[str, Convertor[Any]] = {}
8888
# generate the regex pattern
8989
for i, part in enumerate(parts):
9090
match = re.fullmatch(r"\{(\w+)(?::(\w+))?\}", part)
@@ -112,18 +112,17 @@ def matches(self, uri: str) -> dict[str, Any] | None:
112112
match = regex.match(uri.strip("/"))
113113
if not match:
114114
return None
115-
115+
116116
# try to convert them into respective types
117-
result: Dict[str, Any] = {}
117+
result: dict[str, Any] = {}
118118
for name, conv in converters.items():
119119
raw_value = match.group(name)
120120
try:
121121
result[name] = conv.convert(raw_value)
122122
except Exception:
123123
return None
124124

125-
return result
126-
125+
return result
127126

128127
async def create_resource(
129128
self,

src/mcp/server/fastmcp/utilities/convertors.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
import math
44
import uuid
55
from typing import (
6-
Any,
7-
ClassVar,
8-
Dict,
9-
Generic,
10-
TypeVar,
6+
Any,
7+
ClassVar,
8+
Generic,
9+
TypeVar,
1110
)
1211

1312
T = TypeVar("T")
1413

14+
1515
class Convertor(Generic[T]):
1616
regex: ClassVar[str] = ""
1717

@@ -74,7 +74,7 @@ def to_string(self, value: float) -> str:
7474
assert value >= 0.0, "Negative floats are not supported"
7575
assert not math.isnan(value), "NaN values are not supported"
7676
assert not math.isinf(value), "Infinite values are not supported"
77-
return ("%0.20f" % value).rstrip("0").rstrip(".")
77+
return f"{value:.20f}".rstrip("0").rstrip(".")
7878

7979

8080
class UUIDConvertor(Convertor[uuid.UUID]):
@@ -89,10 +89,11 @@ def convert(self, value: str) -> uuid.UUID:
8989
def to_string(self, value: uuid.UUID) -> str:
9090
return str(value)
9191

92-
CONVERTOR_TYPES: Dict[str, Convertor[Any]] = {
92+
93+
CONVERTOR_TYPES: dict[str, Convertor[Any]] = {
9394
"str": StringConvertor(),
9495
"path": PathConvertor(),
9596
"int": IntegerConvertor(),
9697
"float": FloatConvertor(),
9798
"uuid": UUIDConvertor(),
98-
}
99+
}

tests/server/fastmcp/resources/test_resource_template.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ def my_func(a: int, b: float, name: str) -> dict[str, Any]:
5959
)
6060

6161
params = template.matches("calc://10/3.14/foo")
62-
62+
6363
assert params == {"a": 10, "b": 3.14, "name": "foo"}
6464
assert template.matches("calc://x/3.14/foo") is None
6565
assert template.matches("calc://10/bar/foo") is None
6666

67-
6867
def test_template_matches_with_path(self):
6968
"""Test matching URIs with {path:path} placeholder."""
7069

0 commit comments

Comments
 (0)