Drop dependencies parameter from FastMCP (#1877)
This commit is contained in:
parent
cfb2909631
commit
2ce41a8347
4 changed files with 8 additions and 53 deletions
|
|
@ -37,15 +37,7 @@ DEFAULT_EMBEDDING_MODEL = "text-embedding-3-small"
|
||||||
|
|
||||||
T = TypeVar("T")
|
T = TypeVar("T")
|
||||||
|
|
||||||
mcp = FastMCP(
|
mcp = FastMCP("memory")
|
||||||
"memory",
|
|
||||||
dependencies=[
|
|
||||||
"pydantic-ai-slim[openai]",
|
|
||||||
"asyncpg",
|
|
||||||
"numpy",
|
|
||||||
"pgvector",
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
DB_DSN = "postgresql://postgres:postgres@localhost:54320/memory_db"
|
DB_DSN = "postgresql://postgres:postgres@localhost:54320/memory_db"
|
||||||
# reset memory with rm ~/.fastmcp/{USER}/memory/*
|
# reset memory with rm ~/.fastmcp/{USER}/memory/*
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ from mcp.server.fastmcp import FastMCP
|
||||||
from mcp.server.fastmcp.utilities.types import Image
|
from mcp.server.fastmcp.utilities.types import Image
|
||||||
|
|
||||||
# Create server
|
# Create server
|
||||||
mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])
|
mcp = FastMCP("Screenshot Demo")
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,8 @@
|
||||||
"""FastMCP - A more ergonomic interface for MCP servers."""
|
"""FastMCP - A more ergonomic interface for MCP servers."""
|
||||||
|
|
||||||
from importlib.metadata import version
|
|
||||||
|
|
||||||
from mcp.types import Icon
|
from mcp.types import Icon
|
||||||
|
|
||||||
from .server import Context, FastMCP
|
from .server import Context, FastMCP
|
||||||
from .utilities.types import Audio, Image
|
from .utilities.types import Audio, Image
|
||||||
|
|
||||||
__version__ = version("mcp")
|
|
||||||
__all__ = ["FastMCP", "Context", "Image", "Audio", "Icon"]
|
__all__ = ["FastMCP", "Context", "Image", "Audio", "Icon"]
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
import inspect
|
import inspect
|
||||||
import re
|
import re
|
||||||
from collections.abc import (
|
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence
|
||||||
AsyncIterator,
|
|
||||||
Awaitable,
|
|
||||||
Callable,
|
|
||||||
Collection,
|
|
||||||
Iterable,
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
from contextlib import AbstractAsyncContextManager, asynccontextmanager
|
from contextlib import AbstractAsyncContextManager, asynccontextmanager
|
||||||
from typing import Any, Generic, Literal
|
from typing import Any, Generic, Literal
|
||||||
|
|
||||||
|
|
@ -29,25 +22,11 @@ from starlette.routing import Mount, Route
|
||||||
from starlette.types import Receive, Scope, Send
|
from starlette.types import Receive, Scope, Send
|
||||||
|
|
||||||
from mcp.server.auth.middleware.auth_context import AuthContextMiddleware
|
from mcp.server.auth.middleware.auth_context import AuthContextMiddleware
|
||||||
from mcp.server.auth.middleware.bearer_auth import (
|
from mcp.server.auth.middleware.bearer_auth import BearerAuthBackend, RequireAuthMiddleware
|
||||||
BearerAuthBackend,
|
from mcp.server.auth.provider import OAuthAuthorizationServerProvider, ProviderTokenVerifier, TokenVerifier
|
||||||
RequireAuthMiddleware,
|
|
||||||
)
|
|
||||||
from mcp.server.auth.provider import (
|
|
||||||
OAuthAuthorizationServerProvider,
|
|
||||||
ProviderTokenVerifier,
|
|
||||||
TokenVerifier,
|
|
||||||
)
|
|
||||||
from mcp.server.auth.settings import AuthSettings
|
from mcp.server.auth.settings import AuthSettings
|
||||||
from mcp.server.elicitation import (
|
from mcp.server.elicitation import ElicitationResult, ElicitSchemaModelT, UrlElicitationResult, elicit_with_validation
|
||||||
ElicitationResult,
|
from mcp.server.elicitation import elicit_url as _elicit_url
|
||||||
ElicitSchemaModelT,
|
|
||||||
UrlElicitationResult,
|
|
||||||
elicit_with_validation,
|
|
||||||
)
|
|
||||||
from mcp.server.elicitation import (
|
|
||||||
elicit_url as _elicit_url,
|
|
||||||
)
|
|
||||||
from mcp.server.fastmcp.exceptions import ResourceError
|
from mcp.server.fastmcp.exceptions import ResourceError
|
||||||
from mcp.server.fastmcp.prompts import Prompt, PromptManager
|
from mcp.server.fastmcp.prompts import Prompt, PromptManager
|
||||||
from mcp.server.fastmcp.resources import FunctionResource, Resource, ResourceManager
|
from mcp.server.fastmcp.resources import FunctionResource, Resource, ResourceManager
|
||||||
|
|
@ -116,10 +95,6 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
|
||||||
# prompt settings
|
# prompt settings
|
||||||
warn_on_duplicate_prompts: bool
|
warn_on_duplicate_prompts: bool
|
||||||
|
|
||||||
# TODO(Marcelo): Investigate if this is used. If it is, it's probably a good idea to remove it.
|
|
||||||
dependencies: list[str]
|
|
||||||
"""A list of dependencies to install in the server environment."""
|
|
||||||
|
|
||||||
lifespan: Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None
|
lifespan: Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None
|
||||||
"""A async context manager that will be called when the server is started."""
|
"""A async context manager that will be called when the server is started."""
|
||||||
|
|
||||||
|
|
@ -172,7 +147,6 @@ class FastMCP(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: Collection[str] = (),
|
|
||||||
lifespan: (Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None) = None,
|
lifespan: (Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None) = None,
|
||||||
auth: AuthSettings | None = None,
|
auth: AuthSettings | None = None,
|
||||||
transport_security: TransportSecuritySettings | None = None,
|
transport_security: TransportSecuritySettings | None = None,
|
||||||
|
|
@ -199,7 +173,6 @@ class FastMCP(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=list(dependencies),
|
|
||||||
lifespan=lifespan,
|
lifespan=lifespan,
|
||||||
auth=auth,
|
auth=auth,
|
||||||
transport_security=transport_security,
|
transport_security=transport_security,
|
||||||
|
|
@ -238,7 +211,6 @@ class FastMCP(Generic[LifespanResultT]):
|
||||||
self._event_store = event_store
|
self._event_store = event_store
|
||||||
self._retry_interval = retry_interval
|
self._retry_interval = retry_interval
|
||||||
self._custom_starlette_routes: list[Route] = []
|
self._custom_starlette_routes: list[Route] = []
|
||||||
self.dependencies = self.settings.dependencies
|
|
||||||
self._session_manager: StreamableHTTPSessionManager | None = None
|
self._session_manager: StreamableHTTPSessionManager | None = None
|
||||||
|
|
||||||
# Set up MCP protocol handlers
|
# Set up MCP protocol handlers
|
||||||
|
|
@ -835,8 +807,6 @@ class FastMCP(Generic[LifespanResultT]):
|
||||||
|
|
||||||
def sse_app(self, mount_path: str | None = None) -> Starlette:
|
def sse_app(self, mount_path: str | None = None) -> Starlette:
|
||||||
"""Return an instance of the SSE server app."""
|
"""Return an instance of the SSE server app."""
|
||||||
from starlette.middleware import Middleware
|
|
||||||
from starlette.routing import Mount, Route
|
|
||||||
|
|
||||||
# Update mount_path in settings if provided
|
# Update mount_path in settings if provided
|
||||||
if mount_path is not None:
|
if mount_path is not None:
|
||||||
|
|
@ -855,11 +825,7 @@ class FastMCP(Generic[LifespanResultT]):
|
||||||
async def handle_sse(scope: Scope, receive: Receive, send: Send): # pragma: no cover
|
async def handle_sse(scope: Scope, receive: Receive, send: Send): # pragma: no cover
|
||||||
# Add client ID from auth context into request context if available
|
# Add client ID from auth context into request context if available
|
||||||
|
|
||||||
async with sse.connect_sse(
|
async with sse.connect_sse(scope, receive, send) as streams:
|
||||||
scope,
|
|
||||||
receive,
|
|
||||||
send,
|
|
||||||
) as streams:
|
|
||||||
await self._mcp_server.run(
|
await self._mcp_server.run(
|
||||||
streams[0],
|
streams[0],
|
||||||
streams[1],
|
streams[1],
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue