1{
2 anyio,
3 buildPythonPackage,
4 coreutils,
5 fetchFromGitHub,
6 hatchling,
7 httpx,
8 httpx-sse,
9 lib,
10 pydantic,
11 pydantic-settings,
12 pytest-asyncio,
13 pytest-examples,
14 pytestCheckHook,
15 python-dotenv,
16 rich,
17 sse-starlette,
18 starlette,
19 typer,
20 uvicorn,
21 websockets,
22}:
23
24buildPythonPackage rec {
25 pname = "mcp";
26 version = "1.6.0";
27 pyproject = true;
28
29 src = fetchFromGitHub {
30 owner = "modelcontextprotocol";
31 repo = "python-sdk";
32 tag = "v${version}";
33 hash = "sha256-APm3x4tcDbp8D2ygW43wFyP0llJ6fXZiINHRYShp9ZY=";
34 };
35
36 postPatch = ''
37 substituteInPlace pyproject.toml \
38 --replace-fail ', "uv-dynamic-versioning"' "" \
39 --replace-fail 'dynamic = ["version"]' 'version = "${version}"'
40 substituteInPlace tests/client/test_stdio.py \
41 --replace '/usr/bin/tee' '${lib.getExe' coreutils "tee"}'
42 '';
43
44 build-system = [ hatchling ];
45
46 pythonRelaxDeps = [
47 "pydantic-settings"
48 ];
49
50 dependencies = [
51 anyio
52 httpx
53 httpx-sse
54 pydantic
55 pydantic-settings
56 sse-starlette
57 starlette
58 uvicorn
59 ];
60
61 optional-dependencies = {
62 cli = [
63 python-dotenv
64 typer
65 ];
66 rich = [
67 rich
68 ];
69 ws = [
70 websockets
71 ];
72 };
73
74 pythonImportsCheck = [ "mcp" ];
75
76 nativeCheckInputs = [
77 pytest-asyncio
78 pytest-examples
79 pytestCheckHook
80 ] ++ lib.flatten (lib.attrValues optional-dependencies);
81
82 pytestFlagsArray = [
83 "-W"
84 "ignore::pydantic.warnings.PydanticDeprecatedSince211"
85 ];
86
87 disabledTests = [
88 # attempts to run the package manager uv
89 "test_command_execution"
90 # performance-dependent test
91 "test_messages_are_executed_concurrently"
92 ];
93
94 __darwinAllowLocalNetworking = true;
95
96 meta = {
97 changelog = "https://github.com/modelcontextprotocol/python-sdk/releases/tag/${src.tag}";
98 description = "Official Python SDK for Model Context Protocol servers and clients";
99 homepage = "https://github.com/modelcontextprotocol/python-sdk";
100 license = lib.licenses.mit;
101 maintainers = with lib.maintainers; [ josh ];
102 };
103}