Skip to content

Commit 3517a29

Browse files
authored
feat(server): restore dependencies parameter on MCPServer (#2358)
1 parent 98f8ef2 commit 3517a29

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/mcp/server/mcpserver/server.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
105105
# prompt settings
106106
warn_on_duplicate_prompts: bool
107107

108+
dependencies: list[str]
109+
"""List of dependencies to install in the server environment. Used by the `mcp install` and `mcp dev` CLI."""
110+
108111
lifespan: Callable[[MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None
109112
"""An async context manager that will be called when the server is started."""
110113

@@ -142,6 +145,7 @@ def __init__(
142145
warn_on_duplicate_resources: bool = True,
143146
warn_on_duplicate_tools: bool = True,
144147
warn_on_duplicate_prompts: bool = True,
148+
dependencies: list[str] | None = None,
145149
lifespan: Callable[[MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None = None,
146150
auth: AuthSettings | None = None,
147151
):
@@ -151,9 +155,11 @@ def __init__(
151155
warn_on_duplicate_resources=warn_on_duplicate_resources,
152156
warn_on_duplicate_tools=warn_on_duplicate_tools,
153157
warn_on_duplicate_prompts=warn_on_duplicate_prompts,
158+
dependencies=dependencies or [],
154159
lifespan=lifespan,
155160
auth=auth,
156161
)
162+
self.dependencies = self.settings.dependencies
157163

158164
self._tool_manager = ToolManager(tools=tools, warn_on_duplicate_tools=self.settings.warn_on_duplicate_tools)
159165
self._resource_manager = ResourceManager(warn_on_duplicate_resources=self.settings.warn_on_duplicate_resources)

tests/server/mcpserver/test_server.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ async def test_create_server(self):
6565
assert len(mcp.icons) == 1
6666
assert mcp.icons[0].src == "https://example.com/icon.png"
6767

68+
def test_dependencies(self):
69+
"""Dependencies list is read by `mcp install` / `mcp dev` CLI commands."""
70+
mcp = MCPServer("test", dependencies=["pandas", "numpy"])
71+
assert mcp.dependencies == ["pandas", "numpy"]
72+
assert mcp.settings.dependencies == ["pandas", "numpy"]
73+
74+
mcp_no_deps = MCPServer("test")
75+
assert mcp_no_deps.dependencies == []
76+
6877
async def test_sse_app_returns_starlette_app(self):
6978
"""Test that sse_app returns a Starlette application with correct routes."""
7079
mcp = MCPServer("test")

0 commit comments

Comments
 (0)