%bcond tests 1 # Only enable extras whose dependencies are currently packaged in Fedora. # Omitted upstream extras require unpackaged or outdated dependencies: # - anthropic (requires anthropic) # - apps (requires prefab-ui) # - azure (requires PyJWT >= 2.12.0; Fedora 44 ships 2.10.1) # - code-mode (requires pydantic-monty) # - tasks (requires pydocket >= 0.19.0) # Note: client, mcp, and server are extras on fastmcp-slim only; the # fastmcp wrapper includes them in its base dependencies. %global slim_extras client,gemini,mcp,openai,server %global extras gemini,openai Name: python-fastmcp Version: 3.4.11 Release: %autorelease Summary: The fast, Pythonic way to build MCP servers and clients. License: Apache-2.0 URL: https://gofastmcp.com Source: %{pypi_source fastmcp} Patch0: 0001-stub-otel-sdk-imports.patch BuildArch: noarch BuildRequires: python3-devel BuildRequires: tomcli %if %{with tests} BuildRequires: python3-dirty-equals BuildRequires: python3-fastapi BuildRequires: python3-inline-snapshot BuildRequires: python3-psutil BuildRequires: python3-pytest BuildRequires: python3-pytest-asyncio BuildRequires: python3-pytest-httpx BuildRequires: python3-pytest-timeout %endif %global _description %{expand: FastMCP is a high-level framework for building Model Context Protocol (MCP) servers and clients.} %description %_description %package -n python3-fastmcp-slim Summary: Core lightweight engine for FastMCP %description -n python3-fastmcp-slim Core implementation and protocol engine for FastMCP without extra dependencies. %pyproject_extras_subpkg --name python3-fastmcp-slim --dist-name fastmcp-slim %{slim_extras} %package -n python3-fastmcp Summary: %{summary} Requires: python3-fastmcp-slim = %{version}-%{release} %description -n python3-fastmcp %_description %pyproject_extras_subpkg --name python3-fastmcp --dist-name fastmcp %{extras} %prep %autosetup -p1 -n fastmcp-%{version} %if 0%{?fedora} == 44 # Fedora 44 ships python3-starlette 0.52.1; F45+ has 1.7.0+ %pyproject_patch_dependency starlette:set_lower:0.52.1 %endif # Fedora's python3-certifi points to the system CA bundle (/etc/pki/tls/certs/ca-bundle.crt), # so the upstream version floor for the bundled cacert.pem is unnecessary. %pyproject_patch_dependency certifi:drop_constraints # Source tarballs lack .git metadata, causing uv-dynamic-versioning to fall # back to 0.0.0 unless fallback-version is explicitly set to %%{version}. tomcli set pyproject.toml str \ tool.uv-dynamic-versioning.fallback-version '%{version}' tomcli set fastmcp_slim/pyproject.toml str \ tool.uv-dynamic-versioning.fallback-version '%{version}' %pyproject_patch_dependency fastmcp-slim:ignore:br_only %generate_buildrequires %pyproject_buildrequires --directory fastmcp_slim -x %{slim_extras} %pyproject_buildrequires -x %{extras} %build %pyproject_wheel --directory fastmcp_slim %pyproject_wheel %install %pyproject_install %pyproject_save_files --dist-name fastmcp-slim fastmcp %pyproject_save_files -M --dist-name fastmcp %check %pyproject_check_import -D fastmcp-slim -e "fastmcp.apps.*" -e "fastmcp.client.sampling.handlers.anthropic" -e "fastmcp.server.tasks.*" %if %{with tests} deselected_funcs=( # Requires pydocket >= 0.19.0 to prevent memory transport teardown hangs "test_task_teardown_does_not_hang" "test_background_task_can_read_snapshotted_request_headers" "test_background_task_current_http_dependencies_restore_headers" "test_injected_task_tool_runs_as_task" "test_background_task_runs_the_injected_tool_when_its_name_is_shared" "test_background_task_runs_the_injected_tool_when_signatures_differ" "test_background_task_runs_the_injected_tool_over_a_mounted_tool" "test_task_discovery_lists_one_tool_for_a_shared_name" "test_task_discovery_skips_a_mounted_tool_shadowed_by_an_injected_tool" "test_task_discovery_skips_a_registered_tool_shadowed_by_a_synchronous_injected_tool" "test_background_tasks_run_for_tools_with_distinct_names" "test_mounted_server_does_not_have_docket" "test_get_tasks_returns_task_eligible_tools" "test_is_docket_available" "test_require_docket_passes_when_installed" "test_task_execution_auto_populated_for_task_enabled_tool" "test_timeout_with_task_mode" "test_function_tool_task_config_still_works" "test_async_partial_with_task_true_does_not_raise" "test_sync_partial_with_task_true_raises" # Shared() falls back to request scope without lifespan/docket SharedContext (upstream #5816) "TestSharedDependencies" # Requires dev apps server environment not present in build chroot "test_run_dev_apps_with_host" # Requires dev log panel UI components from unpackaged prefab-ui "test_run_dev_apps_log_panel_propagation" ) k_expr=$(printf "not %s and " "${deselected_funcs[@]}") k_expr="${k_expr% and }" # Define pytest options as a bash array to enable structured comments pytest_opts=( -k "$k_expr" # --- Omitted Optional Extra: apps (requires unpackaged prefab-ui) --- --ignore="tests/apps" --ignore="tests/cli/test_apps_dev_server.py" --ignore="tests/test_apps.py" --ignore="tests/test_apps_prefab.py" --ignore="tests/test_fastmcp_app.py" # --- Omitted Optional Extra: code-mode (requires unpackaged pydantic-monty) --- --ignore="tests/experimental" # --- Omitted Optional Extra: tasks (requires pydocket >= 0.19.0) --- --ignore="tests/client/tasks" --ignore="tests/server/tasks" --ignore="tests/server/test_server_docket.py" # --- Requires Unpackaged opentelemetry-sdk --- --ignore="tests/client/telemetry" --ignore="tests/server/telemetry" --ignore="tests/telemetry" # --- Requires Unpackaged python3-pytest-examples --- --ignore="tests/docs/test_doc_examples.py" # --- Repo-Internal GitHub Automation Scripts (Not Shipped in Package) --- --ignore="tests/scripts" # --- Omitted Optional Extra: anthropic (requires unpackaged anthropic) --- --ignore="tests/client/sampling/handlers/test_anthropic_handler.py" ) # Run pytest in an isolated directory using a lightweight venv with a .pth file # and a rewritten fastmcp shebang. Stdio server subprocesses strip PYTHONPATH # (and Fedora's -sP shebang ignores it), so this ensures spawned processes # resolve fastmcp from %{buildroot} rather than failing to import it. mkdir -p _check cp -a tests _check/ python3 -m venv --system-site-packages --without-pip _check/_venv echo "%{buildroot}%{python3_sitelib}" > _check/_venv/lib/python%{python3_version}/site-packages/_buildroot.pth cp -a %{buildroot}%{_bindir}/fastmcp _check/_venv/bin/fastmcp sed -i "1s|.*|#!$PWD/_check/_venv/bin/python3|" _check/_venv/bin/fastmcp pushd _check PYTHONDONTWRITEBYTECODE=1 \ PATH="$PWD/_venv/bin:%{buildroot}%{_bindir}:$PATH" \ _venv/bin/python3 -m pytest "${pytest_opts[@]}" popd %endif %files -n python3-fastmcp-slim -f %{pyproject_files --dist-name fastmcp-slim} %doc fastmcp_slim/README.md %license LICENSE %files -n python3-fastmcp -f %{pyproject_files --dist-name fastmcp} %doc README.md %license LICENSE %{_bindir}/fastmcp %changelog %autochangelog