feat(server): restore dependencies parameter on MCPServer (#2358)
This commit is contained in:
parent
98f8ef295a
commit
3517a29c82
2 changed files with 15 additions and 0 deletions
|
|
@ -105,6 +105,9 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
|
||||||
# prompt settings
|
# prompt settings
|
||||||
warn_on_duplicate_prompts: bool
|
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
|
lifespan: Callable[[MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None
|
||||||
"""An async context manager that will be called when the server is started."""
|
"""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_resources: bool = True,
|
||||||
warn_on_duplicate_tools: bool = True,
|
warn_on_duplicate_tools: bool = True,
|
||||||
warn_on_duplicate_prompts: bool = True,
|
warn_on_duplicate_prompts: bool = True,
|
||||||
|
dependencies: list[str] | None = None,
|
||||||
lifespan: Callable[[MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None = None,
|
lifespan: Callable[[MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None = None,
|
||||||
auth: AuthSettings | 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_resources=warn_on_duplicate_resources,
|
||||||
warn_on_duplicate_tools=warn_on_duplicate_tools,
|
warn_on_duplicate_tools=warn_on_duplicate_tools,
|
||||||
warn_on_duplicate_prompts=warn_on_duplicate_prompts,
|
warn_on_duplicate_prompts=warn_on_duplicate_prompts,
|
||||||
|
dependencies=dependencies or [],
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
auth=auth,
|
auth=auth,
|
||||||
)
|
)
|
||||||
|
self.dependencies = self.settings.dependencies
|
||||||
|
|
||||||
self._tool_manager = ToolManager(tools=tools, warn_on_duplicate_tools=self.settings.warn_on_duplicate_tools)
|
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)
|
self._resource_manager = ResourceManager(warn_on_duplicate_resources=self.settings.warn_on_duplicate_resources)
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,15 @@ class TestServer:
|
||||||
assert len(mcp.icons) == 1
|
assert len(mcp.icons) == 1
|
||||||
assert mcp.icons[0].src == "https://example.com/icon.png"
|
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):
|
async def test_sse_app_returns_starlette_app(self):
|
||||||
"""Test that sse_app returns a Starlette application with correct routes."""
|
"""Test that sse_app returns a Starlette application with correct routes."""
|
||||||
mcp = MCPServer("test")
|
mcp = MCPServer("test")
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue