Skip to content

Commit 28303ef

Browse files
committed
Clean up
1 parent b121760 commit 28303ef

File tree

5 files changed

+142
-226
lines changed

5 files changed

+142
-226
lines changed

src/mcp/server/mcpserver/resources/resource_manager.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,36 +22,26 @@
2222
class ResourceManager:
2323
"""Manages MCPServer resources."""
2424

25-
def __init__(
26-
self,
27-
warn_on_duplicate_resources: bool = True,
28-
*,
29-
resources: list[Resource] | None = None,
30-
):
25+
def __init__(self, warn_on_duplicate_resources: bool = True, *, resources: list[Resource] | None = None):
3126
self._resources: dict[str, Resource] = {}
3227
self._templates: dict[str, ResourceTemplate] = {}
3328
self.warn_on_duplicate_resources = warn_on_duplicate_resources
34-
if resources is not None:
35-
for resource in resources:
36-
self.add_resource(resource)
29+
30+
for resource in resources or ():
31+
self.add_resource(resource)
3732

3833
def add_resource(self, resource: Resource) -> Resource:
3934
"""Add a resource to the manager.
4035
4136
Args:
42-
resource: A Resource instance to add
37+
resource: A Resource instance to add.
4338
4439
Returns:
45-
The added resource. If a resource with the same URI already exists,
46-
returns the existing resource.
40+
The added resource. If a resource with the same URI already exists, returns the existing resource.
4741
"""
4842
logger.debug(
4943
"Adding resource",
50-
extra={
51-
"uri": resource.uri,
52-
"type": type(resource).__name__,
53-
"resource_name": resource.name,
54-
},
44+
extra={"uri": resource.uri, "type": type(resource).__name__, "resource_name": resource.name},
5545
)
5646
existing = self._resources.get(str(resource.uri))
5747
if existing:

src/mcp/server/mcpserver/server.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ def __init__(
164164

165165
self._tool_manager = ToolManager(tools=tools, warn_on_duplicate_tools=self.settings.warn_on_duplicate_tools)
166166
self._resource_manager = ResourceManager(
167-
resources=resources,
168-
warn_on_duplicate_resources=self.settings.warn_on_duplicate_resources,
167+
resources=resources, warn_on_duplicate_resources=self.settings.warn_on_duplicate_resources
169168
)
170169
self._prompt_manager = PromptManager(warn_on_duplicate_prompts=self.settings.warn_on_duplicate_prompts)
171170
self._lowlevel_server = Server(

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818
class ToolManager:
1919
"""Manages MCPServer tools."""
2020

21-
def __init__(
22-
self,
23-
warn_on_duplicate_tools: bool = True,
24-
*,
25-
tools: list[Tool] | None = None,
26-
):
21+
def __init__(self, warn_on_duplicate_tools: bool = True, *, tools: list[Tool] | None = None):
2722
self._tools: dict[str, Tool] = {}
28-
if tools is not None:
29-
for tool in tools:
30-
if warn_on_duplicate_tools and tool.name in self._tools:
31-
logger.warning(f"Tool already exists: {tool.name}")
32-
self._tools[tool.name] = tool
23+
for tool in tools or ():
24+
if warn_on_duplicate_tools and tool.name in self._tools:
25+
logger.warning(f"Tool already exists: {tool.name}")
26+
self._tools[tool.name] = tool
3327

3428
self.warn_on_duplicate_tools = warn_on_duplicate_tools
3529

0 commit comments

Comments
 (0)