nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6
7 # build-system
8 hatchling,
9 uv-dynamic-versioning,
10
11 # dependencies
12 anyio,
13 httpx,
14 httpx-sse,
15 jsonschema,
16 pydantic,
17 pydantic-settings,
18 pyjwt,
19 python-multipart,
20 sse-starlette,
21 starlette,
22 uvicorn,
23
24 # optional-dependencies
25 # cli
26 python-dotenv,
27 typer,
28 # rich
29 rich,
30 # ws
31 websockets,
32
33 # tests
34 dirty-equals,
35 inline-snapshot,
36 pytest-asyncio,
37 pytest-examples,
38 pytest-xdist,
39 pytestCheckHook,
40 requests,
41}:
42
43buildPythonPackage (finalAttrs: {
44 pname = "mcp";
45 version = "1.26.0";
46 pyproject = true;
47
48 src = fetchFromGitHub {
49 owner = "modelcontextprotocol";
50 repo = "python-sdk";
51 tag = "v${finalAttrs.version}";
52 hash = "sha256-TGkAyuBcIstL2BCZYBWoi7PhnhoBvap67sLWGe0QUoU=";
53 };
54
55 # time.sleep(0.1) feels a bit optimistic and it has been flaky whilst
56 # testing this on macOS under load.
57 postPatch = lib.optionalString stdenv.buildPlatform.isDarwin ''
58 substituteInPlace tests/client/test_stdio.py \
59 --replace-fail "time.sleep(0.1)" "time.sleep(1)"
60 '';
61
62 build-system = [
63 hatchling
64 uv-dynamic-versioning
65 ];
66
67 pythonRelaxDeps = [
68 "pydantic-settings"
69 ];
70
71 dependencies = [
72 anyio
73 httpx
74 httpx-sse
75 jsonschema
76 pydantic
77 pydantic-settings
78 pyjwt
79 python-multipart
80 sse-starlette
81 starlette
82 uvicorn
83 ];
84
85 optional-dependencies = {
86 cli = [
87 python-dotenv
88 typer
89 ];
90 rich = [
91 rich
92 ];
93 ws = [
94 websockets
95 ];
96 };
97
98 pythonImportsCheck = [ "mcp" ];
99
100 nativeCheckInputs = [
101 dirty-equals
102 inline-snapshot
103 pytest-asyncio
104 pytest-examples
105 pytest-xdist
106 pytestCheckHook
107 requests
108 ]
109 ++ lib.flatten (builtins.attrValues finalAttrs.passthru.optional-dependencies);
110
111 disabledTests = [
112 # attempts to run the package manager uv
113 "test_command_execution"
114
115 # ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
116 "test_lifespan_cleanup_executed"
117
118 # AssertionError: Child process should be writing
119 "test_basic_child_process_cleanup"
120
121 # AssertionError: parent process should be writing
122 "test_nested_process_tree"
123
124 # AssertionError: Child should be writing
125 "test_early_parent_exit"
126
127 # pytest.PytestUnraisableExceptionWarning: Exception ignored in: <_io.FileIO ...
128 "test_list_tools_returns_all_tools"
129
130 # AssertionError: Server startup marker not created
131 "test_stdin_close_triggers_cleanup"
132
133 # pytest.PytestUnraisableExceptionWarning: Exception ignored in: <function St..
134 "test_resource_template_client_interaction"
135
136 # Flaky: https://github.com/modelcontextprotocol/python-sdk/pull/1171
137 "test_notification_validation_error"
138
139 # Flaky: httpx.ConnectError: All connection attempts failed
140 "test_sse_security_"
141 "test_streamable_http_"
142
143 # This just feels a bit optimistic...
144 # assert duration < 3 * _sleep_time_seconds
145 # AssertionError: assert 0.0733884589999434 < (3 * 0.01)
146 "test_messages_are_executed_concurrently"
147
148 # ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
149 "test_tool_progress"
150 ];
151
152 __darwinAllowLocalNetworking = true;
153
154 meta = {
155 changelog = "https://github.com/modelcontextprotocol/python-sdk/releases/tag/${finalAttrs.src.tag}";
156 description = "Official Python SDK for Model Context Protocol servers and clients";
157 homepage = "https://github.com/modelcontextprotocol/python-sdk";
158 license = lib.licenses.mit;
159 maintainers = with lib.maintainers; [
160 bryanhonof
161 josh
162 ];
163 };
164})