Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions examples/fastmcp/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,7 @@

T = TypeVar("T")

mcp = FastMCP(
"memory",
dependencies=[
"pydantic-ai-slim[openai]",
"asyncpg",
"numpy",
"pgvector",
],
)
mcp = FastMCP("memory")

DB_DSN = "postgresql://postgres:postgres@localhost:54320/memory_db"
# reset memory with rm ~/.fastmcp/{USER}/memory/*
Expand Down
2 changes: 1 addition & 1 deletion examples/fastmcp/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from mcp.server.fastmcp.utilities.types import Image

# Create server
mcp = FastMCP("Screenshot Demo", dependencies=["pyautogui", "Pillow"])
mcp = FastMCP("Screenshot Demo")


@mcp.tool()
Expand Down
3 changes: 0 additions & 3 deletions src/mcp/server/fastmcp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
"""FastMCP - A more ergonomic interface for MCP servers."""

from importlib.metadata import version

from mcp.types import Icon

from .server import Context, FastMCP
from .utilities.types import Audio, Image

__version__ = version("mcp")
__all__ = ["FastMCP", "Context", "Image", "Audio", "Icon"]
46 changes: 6 additions & 40 deletions src/mcp/server/fastmcp/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@

import inspect
import re
from collections.abc import (
AsyncIterator,
Awaitable,
Callable,
Collection,
Iterable,
Sequence,
)
from collections.abc import AsyncIterator, Awaitable, Callable, Iterable, Sequence
from contextlib import AbstractAsyncContextManager, asynccontextmanager
from typing import Any, Generic, Literal

Expand All @@ -29,25 +22,11 @@
from starlette.types import Receive, Scope, Send

from mcp.server.auth.middleware.auth_context import AuthContextMiddleware
from mcp.server.auth.middleware.bearer_auth import (
BearerAuthBackend,
RequireAuthMiddleware,
)
from mcp.server.auth.provider import (
OAuthAuthorizationServerProvider,
ProviderTokenVerifier,
TokenVerifier,
)
from mcp.server.auth.middleware.bearer_auth import BearerAuthBackend, RequireAuthMiddleware
from mcp.server.auth.provider import OAuthAuthorizationServerProvider, ProviderTokenVerifier, TokenVerifier
from mcp.server.auth.settings import AuthSettings
from mcp.server.elicitation import (
ElicitationResult,
ElicitSchemaModelT,
UrlElicitationResult,
elicit_with_validation,
)
from mcp.server.elicitation import (
elicit_url as _elicit_url,
)
from mcp.server.elicitation import ElicitationResult, 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.prompts import Prompt, PromptManager
from mcp.server.fastmcp.resources import FunctionResource, Resource, ResourceManager
Expand Down Expand Up @@ -116,10 +95,6 @@ class Settings(BaseSettings, Generic[LifespanResultT]):
# prompt settings
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
"""A async context manager that will be called when the server is started."""

Expand Down Expand Up @@ -172,7 +147,6 @@ def __init__( # noqa: PLR0913
warn_on_duplicate_resources: bool = True,
warn_on_duplicate_tools: bool = True,
warn_on_duplicate_prompts: bool = True,
dependencies: Collection[str] = (),
lifespan: (Callable[[FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]] | None) = None,
auth: AuthSettings | None = None,
transport_security: TransportSecuritySettings | None = None,
Expand All @@ -199,7 +173,6 @@ def __init__( # noqa: PLR0913
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=list(dependencies),
lifespan=lifespan,
auth=auth,
transport_security=transport_security,
Expand Down Expand Up @@ -238,7 +211,6 @@ def __init__( # noqa: PLR0913
self._event_store = event_store
self._retry_interval = retry_interval
self._custom_starlette_routes: list[Route] = []
self.dependencies = self.settings.dependencies
self._session_manager: StreamableHTTPSessionManager | None = None

# Set up MCP protocol handlers
Expand Down Expand Up @@ -835,8 +807,6 @@ def _normalize_path(self, mount_path: str, endpoint: str) -> str:

def sse_app(self, mount_path: str | None = None) -> Starlette:
"""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
if mount_path is not None:
Expand All @@ -855,11 +825,7 @@ def sse_app(self, mount_path: str | None = None) -> Starlette:
async def handle_sse(scope: Scope, receive: Receive, send: Send): # pragma: no cover
# Add client ID from auth context into request context if available

async with sse.connect_sse(
scope,
receive,
send,
) as streams:
async with sse.connect_sse(scope, receive, send) as streams:
await self._mcp_server.run(
streams[0],
streams[1],
Expand Down