File python-mcp.spec of Package python-mcp

#
# spec file for package python-mcp
#
# Copyright (c) 2025 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/

%{?sle15_python_module_pythons}
%global flavor @BUILD_FLAVOR@%{nil}
%if "%{flavor}" == "test"
%define psuffix -test
%bcond_without test
%else
%define psuffix %{nil}
%bcond_with test
%endif
%bcond_without libalternatives
Name:           python-mcp%{psuffix}
Version:        1.15.0
Release:        0
Summary:        Model Context Protocol SDK
License:        MIT
URL:            https://modelcontextprotocol.io
Group:          Development/Languages/Python
Source:         https://files.pythonhosted.org/packages/source/m/mcp/mcp-%{version}.tar.gz
BuildRequires:  alts
BuildRequires:  python-rpm-macros
BuildRequires:  %{python_module hatchling}
BuildRequires:  %{python_module pip}
BuildRequires:  %{python_module uv-dynamic-versioning}
# SECTION test requirements
BuildRequires:  %{python_module anyio >= 4.5}
BuildRequires:  %{python_module httpx >= 0.27.1}
BuildRequires:  %{python_module httpx-sse >= 0.4}
BuildRequires:  %{python_module jsonschema >= 4.20.0}
BuildRequires:  %{python_module pydantic >= 2.11.0}
BuildRequires:  %{python_module pydantic-settings >= 2.5.2}
BuildRequires:  %{python_module python-multipart >= 0.0.9}
BuildRequires:  %{python_module sse-starlette >= 1.6.1}
BuildRequires:  %{python_module starlette >= 0.27}
BuildRequires:  %{python_module uvicorn >= 0.31.1}
# /SECTION
BuildRequires:  fdupes
Requires:       alts
Requires:       python-anyio >= 4.5
Requires:       python-httpx >= 0.27.1
Requires:       python-httpx-sse >= 0.4
Requires:       python-jsonschema >= 4.20.0
Requires:       python-pydantic >= 2.11.0
Requires:       python-pydantic-settings >= 2.5.2
Requires:       python-python-multipart >= 0.0.9
Requires:       python-sse-starlette >= 1.6.1
Requires:       python-starlette >= 0.27
Requires:       python-uvicorn >= 0.31.1
Suggests:       python-rich >= 13.9.4
Suggests:       python-typer >= 0.16.0
Suggests:       python-python-dotenv >= 1.0.0
Suggests:       python-websockets >= 15.0.1
BuildArch:      noarch
%python_subpackages

%description
Model Context Protocol (or Master Control Program?) implementation
for python.

%prep
%autosetup -p1 -n mcp-%{version}

%build
%if !%{with test}
# This is an ugly hack, should not be necessary, but is to build on SLE 15 with Python 3.11
# MgE, 2025-06-19
%if 0%{?suse_version} < 1600
sed -i -e "s/3.12/3.11/g" pyproject.toml
sed -i -e "s/3.13/3.11/g" pyproject.toml
%endif
%pyproject_wheel
%endif

%install
%if !%{with test}
%pyproject_install
%fdupes %{buildroot}%{python_sitelib}
%python_expand %fdupes %{buildroot}%{$python_sitelib}
%python_clone -a %{buildroot}%{_bindir}/mcp
%endif

%check
%if %{with test}
sed -i 's/"python"/"python3"/' tests/client/test_stdio.py
# test_command_execution needs full package including docs
donttest="test_command_execution"
# https://github.com/modelcontextprotocol/python-sdk/commit/17f9c00c53b4463ac1a449d601c2d181664ab857 dropped test_build_metadata[with-path-param]
donttest+=" or test_build_metadata[with-path-param]"
# test_client_session_version_negotiation_failure failure probably related to https://github.com/modelcontextprotocol/python-sdk/issues/1018
donttest+=" or test_client_session_version_negotiation_failure"
# flaky tests on aarch64
donttest+=" or test_streamablehttp_client_get_stream or test_streamablehttp_client_resumption"
%pytest -k "not ($donttest or OAuth)"
# problems with unawaited coroutines
%pytest -k "OAuth" --asyncio-mode=auto
%endif

%if !%{with test}
%files %{python_files}
%license LICENSE
%doc README.md
%python_alternative %{_bindir}/mcp
%{python_sitelib}/mcp
%{python_sitelib}/mcp-%{version}.dist-info
%endif

%changelog
openSUSE Build Service is sponsored by