Skip to content

Commit 3a9c97d

Browse files
committed
feat(server): restore dependencies parameter on MCPServer
Restores the `dependencies` parameter that was removed in #1877. The parameter is read by the `mcp dev` and `mcp install` CLI commands to auto-populate `uv run --with <pkg>` flags. Removal without a working replacement breaks high-profile consumers (awslabs/mcp uses it in 47 servers, mindsdb, redis/mcp-redis). While PEP 723 inline script metadata is the intended replacement, the CLI doesn't currently parse it — `uv` only reads PEP 723 when the script is the direct target, not when wrapped in `mcp run <file>`. Long-term design (deprecate vs. keep vs. config file) is tracked in the linked issue. Github-Issue:#2354
1 parent 7ba4fb8 commit 3a9c97d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/mcp/server/mcpserver/server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import inspect
77
import json
88
import re
9-
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence
9+
from collections.abc import AsyncIterator, Awaitable, Callable, Collection, Iterable, Sequence
1010
from contextlib import AbstractAsyncContextManager, asynccontextmanager
1111
from typing import Any, Generic, Literal, TypeVar, overload
1212

@@ -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: Collection[str] = (),
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=list(dependencies),
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)