feat(server): restore dependencies parameter on MCPServer (#2358)

This commit is contained in:
Max Isbey 2026-03-27 13:42:15 +00:00 • committed by GitHub
commit 3517a29c82
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 0 deletions

View file

@ -105,6 +105,9 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
# prompt settings
warn_on_duplicate_prompts: bool
dependencies: list[str]
"""List of dependencies to install in the server environment. Used by the `mcp install` and `mcp dev` CLI."""
lifespan: Callable[[MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None
"""An async context manager that will be called when the server is started."""
@ -142,6 +145,7 @@ class MCPServer(Generic[LifespanResultT]):
warn_on_duplicate_resources: bool = True,
warn_on_duplicate_tools: bool = True,
warn_on_duplicate_prompts: bool = True,
dependencies: list[str] | None = None,
lifespan: Callable[[MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None = None,
auth: AuthSettings | None = None,
):
@ -151,9 +155,11 @@ class MCPServer(Generic[LifespanResultT]):
warn_on_duplicate_resources=warn_on_duplicate_resources,
warn_on_duplicate_tools=warn_on_duplicate_tools,
warn_on_duplicate_prompts=warn_on_duplicate_prompts,
dependencies=dependencies or [],
lifespan=lifespan,
auth=auth,
)
self.dependencies = self.settings.dependencies
self._tool_manager = ToolManager(tools=tools, warn_on_duplicate_tools=self.settings.warn_on_duplicate_tools)
self._resource_manager = ResourceManager(warn_on_duplicate_resources=self.settings.warn_on_duplicate_resources)

View file

@ -65,6 +65,15 @@ class TestServer:
assert len(mcp.icons) == 1
assert mcp.icons[0].src == "https://example.com/icon.png"
def test_dependencies(self):
"""Dependencies list is read by `mcp install` / `mcp dev` CLI commands."""
mcp = MCPServer("test", dependencies=["pandas", "numpy"])
assert mcp.dependencies == ["pandas", "numpy"]
assert mcp.settings.dependencies == ["pandas", "numpy"]
mcp_no_deps = MCPServer("test")
assert mcp_no_deps.dependencies == []
async def test_sse_app_returns_starlette_app(self):
"""Test that sse_app returns a Starlette application with correct routes."""
mcp = MCPServer("test")