Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 7 # build-system 8 hatchling, 9 10 # dependencies 11 anyio, 12 httpx, 13 httpx-sse, 14 pydantic, 15 pydantic-settings, 16 python-multipart, 17 sse-starlette, 18 starlette, 19 uvicorn, 20 21 # optional-dependencies 22 # cli 23 python-dotenv, 24 typer, 25 # rich 26 rich, 27 # ws 28 websockets, 29 30 # tests 31 inline-snapshot, 32 pytest-asyncio, 33 pytest-examples, 34 pytest-xdist, 35 pytestCheckHook, 36 requests, 37}: 38 39buildPythonPackage rec { 40 pname = "mcp"; 41 version = "1.9.4"; 42 pyproject = true; 43 44 src = fetchFromGitHub { 45 owner = "modelcontextprotocol"; 46 repo = "python-sdk"; 47 tag = "v${version}"; 48 hash = "sha256-VXbu/wHbXGS+cISJVUgCVEpTmZc0VfckNRoMj3GDi/A="; 49 }; 50 51 postPatch = '' 52 substituteInPlace pyproject.toml \ 53 --replace-fail ', "uv-dynamic-versioning"' "" \ 54 --replace-fail 'dynamic = ["version"]' 'version = "${version}"' 55 ''; 56 57 build-system = [ hatchling ]; 58 59 pythonRelaxDeps = [ 60 "pydantic-settings" 61 ]; 62 63 dependencies = [ 64 anyio 65 httpx 66 httpx-sse 67 pydantic 68 pydantic-settings 69 python-multipart 70 sse-starlette 71 starlette 72 uvicorn 73 ]; 74 75 optional-dependencies = { 76 cli = [ 77 python-dotenv 78 typer 79 ]; 80 rich = [ 81 rich 82 ]; 83 ws = [ 84 websockets 85 ]; 86 }; 87 88 pythonImportsCheck = [ "mcp" ]; 89 90 nativeCheckInputs = [ 91 inline-snapshot 92 pytest-asyncio 93 pytest-examples 94 pytest-xdist 95 pytestCheckHook 96 requests 97 ] 98 ++ lib.flatten (lib.attrValues optional-dependencies); 99 100 pytestFlags = [ 101 "-Wignore::pydantic.warnings.PydanticDeprecatedSince211" 102 ]; 103 104 disabledTests = [ 105 # attempts to run the package manager uv 106 "test_command_execution" 107 108 # performance-dependent test 109 "test_messages_are_executed_concurrently" 110 111 # ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) 112 "test_client_session_version_negotiation_failure" 113 114 # AttributeError: 'coroutine' object has no attribute 'client_metadata' 115 "TestOAuthClientProvider" 116 117 # inline_snapshot._exceptions.UsageError: snapshot value should not change. Use Is(...) for dynamic snapshot parts 118 "test_build_metadata" 119 ] 120 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 121 # Flaky: ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) 122 "test_notification_validation_error" 123 ]; 124 125 __darwinAllowLocalNetworking = true; 126 127 meta = { 128 changelog = "https://github.com/modelcontextprotocol/python-sdk/releases/tag/${src.tag}"; 129 description = "Official Python SDK for Model Context Protocol servers and clients"; 130 homepage = "https://github.com/modelcontextprotocol/python-sdk"; 131 license = lib.licenses.mit; 132 maintainers = with lib.maintainers; [ josh ]; 133 }; 134}