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