Repository 指南 · 入門 · v1
modelcontextprotocol / python-sdk · 入門
這是一個 Python repository,它的 GitHub 描述稱它是 Model Context Protocol 伺服器與客戶端的官方 Python SDK。它採用 MIT 授權,分析器計有 1,726 個檔案,其中包括 287 個類測試檔案。Manifest 和帶有 __main__ 守衛的腳本可以靜態閱讀,但安裝和執行指令未驗證。
- 原始 repository
- modelcontextprotocol/python-sdk
- 授權
- MIT · 開源授權
- 分析的版本 · 最後驗證
- 77001c96f9507be0f4d009b83210a384a5e08bda ·
本頁中文由負責的 AI 編輯依英文正式版本 v1 翻譯;程式碼名稱、路徑、行號與數字都經確定性檢查,與英文版一致。陳述與依據表保留英文原文,因為那是獨立驗證者核對過的紀錄。看英文原文
modelcontextprotocol/python-sdk 入門
本頁用語說明
- Entrypoint record(進入點記錄)
- 分析器標記為「程式可能從這裡開始執行」的檔案。附有 __main__ guard 摘錄時,表示檔案裡有 if __name__ == "__main__": 區塊,摘錄顯示它呼叫了什麼;沒有摘錄時,只是依檔名判斷。
- Bounded static execution path(有界靜態執行路徑)
- 不執行程式、直接從原始碼重建出的呼叫鏈,走到固定步數就停。它說明在紙面上能追到多遠,不代表實際執行時會發生什麼。
- Unresolved boundary(未解析邊界)
- 靜態路徑停下的地方:下一個呼叫進入外部函式庫,或不執行就無法確定。這是本次分析的邊界,不是 repository 的缺陷。
- Static relations(靜態關係)
- 在原始碼中找到的呼叫與 import。「external or unresolved」表示指向分析範圍以外。
- Module role(模組角色)
- 分析器依呼叫進出次數推論的檔案標籤(例如 core、entry/orchestration、leaf)。它描述的是在呼叫圖中的位置,不是作者的設計意圖。
- Test-like files(類測試檔案)
- 名稱或位置看起來像測試的檔案。本次分析只計數,不執行。
- Observed · inferred · author-claimed · unresolved
- 每句話的依據:直接讀自分析的檔案;由分析器從檔案推論;repository 作者自述(metadata、README);或本次分析無法確定。
- Verified(已驗證)
- 本頁有兩種用法。在分析器的記錄裡(「verified provenance」「verified entrypoint」),它表示這筆記錄是直接從分析的檔案讀到的,也就是本指南所說的 observed;以進入點來說,就是檔案裡確實有 __main__ guard 的文字。分析器在 2026-10-04 修正後,只有 cli.py、main.py 這類像進入點的檔名、沒有 guard 的檔案,會記為 inferred(推測);在那之前分析的指南仍把這類檔案標成 verified,它依然只是對檔案用途的推測。它不代表程式被執行或測試過。「最後驗證」是這份指南最後一次通過本實驗室檢查的日期,檢查對象是所標示版本的分析記錄,不是對 repository 本身的審查。
你正在看的是什麼
GitHub 描述稱它是 Model Context Protocol 伺服器與客戶端的官方 Python SDK。這是作者自己的描述,本分析沒有查證。列出的首頁指向 modelcontextprotocol.io 子網域上的一個網站,這同樣由作者提供。
- 主題:mcp、mcp-client、mcp-server、python。
- 主要語言:Python,幾乎占了全部的語言位元組。Shell、JavaScript 和 HTML 只少量出現。
- 授權:MIT,依據 GitHub API 和 repository 的 LICENSE 檔案。
- 最新 release:v2.3.0,發布於 2026-10-02。GitHub 在 2026-11-15 回報 24,868 個 star。
- 規模:分析器的摘要計有 1,726 個已分析檔案、287 個類測試檔案、18 個 manifest 檔案和 178 筆進入點記錄。
它需要什麼
分析器計有 18 個已解析的 manifest:根目錄的 pyproject.toml、src/mcp-types/pyproject.toml,以及 examples/ 底下的十六個(十五個 pyproject.toml 檔案和一個 requirements.txt)。
- 根目錄 pyproject.toml:沒有出現 runtime 範圍的記錄,只有選用套件 rich、typer 和 python-dotenv。它是否宣告了分析器沒有記錄到的 runtime 依賴,尚未確定。
- 根目錄的 dev 記錄包括 pyright、pytest、ruff、trio、pytest-xdist 和 coverage。另外也包括精確釘定版本的套件 zensical、mkdocstrings 和 mkdocstrings-python,以及未指定版本的 mcp 和 mcp-example-stories。
- pillow 和 blockbuster 在根目錄 dev 範圍中各出現兩次,下限不同,依原文記錄。
- src/mcp-types/pyproject.toml 將 pydantic 列了兩次(>=2.14.0 和 >=2.12.0),並將 typing-extensions >=4.13.0 列為 runtime 依賴。
- examples/servers/simple-tool/pyproject.toml 是範例 manifest 之一。它列出未指定版本的 mcp,另有 anyio >=4.5、click >=8.2.0,以及一個記錄為 httpx2 >=2.5.0 的名稱。
Lock 檔、setup.py、setup.cfg 和 Pipfile 不會被解析。
它如何啟動
分析器計有 178 筆進入點記錄。其中二十筆可供本分析使用,這二十筆都帶有 __main__ 守衛。
- .github/actions/conformance/client.py:守衛呼叫
main()。 - scripts/gen_surface_types.py 將
main()的結果傳給sys.exit。scripts/update_readme_snippets.py 呼叫main()。 - 其餘 17 個檔案位於 docs_src/ 底下(client、extensions、apps、caching、pagination、first_steps、legacy_clients、protocol_versions)。它們的守衛都呼叫
anyio.run(main)。
有一項教學陳述將 src/mcp/cli/cli.py 指為偵測到的起點。它的進入點記錄沒有列出,因此它如何啟動尚未確定。
分析器回報 658 條有界執行路徑,列出了 5 條,全部來自 conformance client。每條都在一到兩步後停在未解析的邊界:logging.basicConfig、logging.getLogger、os.environ.get,或是經由本地 main 到達的 len 和 print。
超出這些記錄的 runtime 行為尚未確定。
先看哪裡
分析器將 README.md、pyproject.toml 和 LICENSE 標為專案層級的重要檔案。它也將 .github/actions/conformance/client.py 和幾個 docs_src 教學檔案標為重要,因為它們很可能是進入點。
它的學習路徑陳述建議先從 manifest 和重要符號開始,接著追蹤有界執行路徑,並在修改程式碼前檢查未解析的邊界。它的修改指南陳述指出 src/mcp/cli/cli.py 是起點,下游影響則需手動檢查。
依檔案數排列的頂層目錄:i18n (664)、examples (298)、tests (285)、docs_src (218)、src (140)、docs (58)、.github (27)、根目錄 (18)、scripts (12)、schema (4)、.claude (2)。
測試是存在的。分析器計有 287 個類測試檔案,tests/ 目錄則有 285 個檔案。
這份分析無法告訴你的事
- 安裝、建置和執行指令未驗證,因此這裡不提供任何指令。
- 依賴記錄只來自 requirements 檔案、package.json 和 pyproject.toml。setup.py、setup.cfg、Pipfile 和 lock 檔不會被解析,版本限制依原文記錄。
- README 文字是逐行擷取的,充其量仍屬作者自述。
- 本分析是靜態的。反射、動態 import、runtime 依賴注入、產生的程式碼和框架接線都不會被解析。
- 超過 400 kB 的檔案、minified bundle 和 vendored 目錄會列入清冊,但不會被解析。
分析資料內含兩處內部不一致:
- 有一項教學陳述說沒有可用的有界執行路徑,但分析器回報 658 條路徑並列出了五條。
- 有一項教學陳述將 src/mcp/cli/cli.py 指為起點,但分析器的摘要指的是 .github/actions/conformance/client.py。
這次分析無法確定的事
這些是撰寫模型對分析記錄自己的說明。lim_3、exec_* 或 claim_… 這類識別碼指的是那次分析裡的記錄;陳述與依據表引用的也是同一批記錄。
- 只有 20 筆(共 178 筆)進入點記錄和 5 條(共 658 條)有界執行路徑可用;關於進入點的陳述僅限於這些記錄。
- src/mcp/cli/cli.py 的進入點記錄沒有列出,因此它是有 __main__ 守衛,還是由檔名啟發式偵測到的,尚未確定。
- 根目錄 pyproject.toml 沒有 runtime 範圍的依賴記錄;runtime 依賴是否以未記錄的形式宣告,尚未確定。
- 依賴名稱 httpx2 在數個範例 manifest 中依原文記錄;它是否就是預期的發行套件名稱,尚未確定。
- manifest 清冊中出現一個 uv.lock 檔案,但 lock 檔不會被解析,因此它的內容沒有反映在依賴記錄中。
- 287 個類測試檔案和 tests/ 中的 285 個檔案是分開的計數;兩者如何重疊尚未確定。
陳述與依據 — 37 條陳述,37 條經獨立驗證者確認(英文原文)
Every substantive statement above is a claim bound to grounding IDs of the analyzed revision. Global grounding IDs are namespaced by the analysis run.
| Claim | Epistemic status | Verifier | Grounding (global IDs) |
|---|---|---|---|
| c1 The repository's GitHub description presents it as the official Python SDK for Model Context Protocol servers and clients. | author_claimed | supported | analysis_f7d9a9f9559ef565:meta_description |
| c2 The platform-listed homepage points to a site on a modelcontextprotocol.io subdomain. | author_claimed | supported | analysis_f7d9a9f9559ef565:meta_homepage |
| c3 The repository topics are mcp, mcp-client, mcp-server and python. | observed | supported | analysis_f7d9a9f9559ef565:meta_topics |
| c4 The primary language is Python, which accounts for almost all language bytes; Shell, JavaScript and HTML appear in small amounts. | observed | supported | analysis_f7d9a9f9559ef565:meta_primary_language, analysis_f7d9a9f9559ef565:meta_language_bytes |
| c5 The license is MIT according to the GitHub API and the repository file, and LICENSE is a project-level important file. | observed | supported | analysis_f7d9a9f9559ef565:meta_license, analysis_f7d9a9f9559ef565:important_3 |
| c6 The latest release is v2.3.0, published 2026-10-02; GitHub reported 24,868 stargazers on 2026-11-15. | observed | supported | analysis_f7d9a9f9559ef565:meta_latest_release, analysis_f7d9a9f9559ef565:meta_stars |
| c7 The analyzer's summary counts 1,726 analyzed files, 287 test-like files, 18 manifest files and 178 entrypoint records. | inferred | supported | analysis_f7d9a9f9559ef565:summary_repository, analysis_f7d9a9f9559ef565:claim_f35a48536d91 |
| c8 Eighteen manifests were parsed: the root pyproject.toml, src/mcp-types/pyproject.toml, and sixteen under examples/, fifteen pyproject.toml files and one requirements.txt. | inferred | supported | analysis_f7d9a9f9559ef565:summary_repository, analysis_f7d9a9f9559ef565:dep_99, analysis_f7d9a9f9559ef565:dep_130, analysis_f7d9a9f9559ef565:dep_6, analysis_f7d9a9f9559ef565:dep_2, analysis_f7d9a9f9559ef565:dep_11, analysis_f7d9a9f9559ef565:dep_17, analysis_f7d9a9f9559ef565:dep_21, analysis_f7d9a9f9559ef565:dep_25, analysis_f7d9a9f9559ef565:dep_34, analysis_f7d9a9f9559ef565:dep_45, analysis_f7d9a9f9559ef565:dep_52, analysis_f7d9a9f9559ef565:dep_59, analysis_f7d9a9f9559ef565:dep_66, analysis_f7d9a9f9559ef565:dep_75, analysis_f7d9a9f9559ef565:dep_84, analysis_f7d9a9f9559ef565:dep_91, analysis_f7d9a9f9559ef565:dep_97, analysis_f7d9a9f9559ef565:dep_98 |
| c9 The root pyproject.toml has optional-scope records for rich >=13.9.4, typer >=0.16.0 and python-dotenv >=1.0.0, and no runtime-scope record among the listed dependency records. | observed | supported | analysis_f7d9a9f9559ef565:dep_99, analysis_f7d9a9f9559ef565:dep_100, analysis_f7d9a9f9559ef565:dep_101, analysis_f7d9a9f9559ef565:important_2 |
| c10 The root pyproject.toml dev scope includes pyright >=1.1.400, pytest >=8.4.0, ruff >=0.8.5, trio >=0.26.2, pytest-xdist >=3.6.1 and coverage >=7.10.7,<=7.13. | observed | supported | analysis_f7d9a9f9559ef565:dep_105, analysis_f7d9a9f9559ef565:dep_106, analysis_f7d9a9f9559ef565:dep_107, analysis_f7d9a9f9559ef565:dep_108, analysis_f7d9a9f9559ef565:dep_110, analysis_f7d9a9f9559ef565:dep_115 |
| c11 The root dev scope also lists zensical ==0.0.50, mkdocstrings ==1.0.4, mkdocstrings-python ==2.0.5, and mcp and mcp-example-stories without versions. | observed | supported | analysis_f7d9a9f9559ef565:dep_123, analysis_f7d9a9f9559ef565:dep_124, analysis_f7d9a9f9559ef565:dep_125, analysis_f7d9a9f9559ef565:dep_102, analysis_f7d9a9f9559ef565:dep_103 |
| c12 pillow appears twice in the root dev scope (>=12.3 and >=12.0), as does blockbuster (>=1.5.29 and >=1.5.27); constraints are recorded as written. | observed | supported | analysis_f7d9a9f9559ef565:dep_116, analysis_f7d9a9f9559ef565:dep_117, analysis_f7d9a9f9559ef565:dep_121, analysis_f7d9a9f9559ef565:dep_122, analysis_f7d9a9f9559ef565:lim_3a |
| c13 src/mcp-types/pyproject.toml lists pydantic twice (>=2.14.0 and >=2.12.0) and typing-extensions >=4.13.0 as runtime dependencies. | observed | supported | analysis_f7d9a9f9559ef565:dep_130, analysis_f7d9a9f9559ef565:dep_131, analysis_f7d9a9f9559ef565:dep_132 |
| c14 examples/servers/simple-tool/pyproject.toml lists runtime dependencies mcp without a version, anyio >=4.5, click >=8.2.0 and a name recorded as httpx2 >=2.5.0. | observed | supported | analysis_f7d9a9f9559ef565:dep_84, analysis_f7d9a9f9559ef565:dep_81, analysis_f7d9a9f9559ef565:dep_82, analysis_f7d9a9f9559ef565:dep_83 |
| c15 Whether the root pyproject.toml declares runtime dependencies in a form the analyzer did not record is not established by the packet. | unresolved | supported | analysis_f7d9a9f9559ef565:dep_99, analysis_f7d9a9f9559ef565:dep_100, analysis_f7d9a9f9559ef565:dep_101, analysis_f7d9a9f9559ef565:lim_3a |
| c16 Lock files, setup.py, setup.cfg and Pipfile are not parsed for dependency records. | observed | supported | analysis_f7d9a9f9559ef565:lim_3a |
| c17 The analyzer counts 178 entrypoint records; the 20 available records each contain a Python __main__ guard. | inferred | supported | analysis_f7d9a9f9559ef565:claim_f35a48536d91, analysis_f7d9a9f9559ef565:py_entry_7ed4238a8b5b, analysis_f7d9a9f9559ef565:py_entry_6211bb69c81e, analysis_f7d9a9f9559ef565:py_entry_34629f3fb6b3, analysis_f7d9a9f9559ef565:py_entry_5d442081d210, analysis_f7d9a9f9559ef565:py_entry_fb08908da90c, analysis_f7d9a9f9559ef565:py_entry_2f2371a70335, analysis_f7d9a9f9559ef565:py_entry_5e69a082cd28, analysis_f7d9a9f9559ef565:py_entry_e6563cc9ae9c, analysis_f7d9a9f9559ef565:py_entry_d86f6ca7aa9d, analysis_f7d9a9f9559ef565:py_entry_fa6382bc744e, analysis_f7d9a9f9559ef565:py_entry_88464f30ad02, analysis_f7d9a9f9559ef565:py_entry_49eb33872d36, analysis_f7d9a9f9559ef565:py_entry_4e3973bc283a, analysis_f7d9a9f9559ef565:py_entry_b7441e2ca64b, analysis_f7d9a9f9559ef565:py_entry_39b5fd30e9a3, analysis_f7d9a9f9559ef565:py_entry_8f622205bd2f, analysis_f7d9a9f9559ef565:py_entry_11225e9c9110, analysis_f7d9a9f9559ef565:py_entry_5e73d47c3e6d, analysis_f7d9a9f9559ef565:py_entry_10190532b8cf, analysis_f7d9a9f9559ef565:py_entry_8d4ba4b8f2e4 |
| c18 The __main__ guard in .github/actions/conformance/client.py calls main(). | observed | supported | analysis_f7d9a9f9559ef565:py_entry_7ed4238a8b5b |
| c19 The guard in scripts/gen_surface_types.py passes main()'s result to sys.exit; the guard in scripts/update_readme_snippets.py calls main(). | observed | supported | analysis_f7d9a9f9559ef565:py_entry_6211bb69c81e, analysis_f7d9a9f9559ef565:py_entry_34629f3fb6b3 |
| c20 The other 17 listed guarded files are under docs_src/ and each guard calls anyio.run(main). | observed | supported | analysis_f7d9a9f9559ef565:py_entry_5d442081d210, analysis_f7d9a9f9559ef565:py_entry_fb08908da90c, analysis_f7d9a9f9559ef565:py_entry_2f2371a70335, analysis_f7d9a9f9559ef565:py_entry_5e69a082cd28, analysis_f7d9a9f9559ef565:py_entry_e6563cc9ae9c, analysis_f7d9a9f9559ef565:py_entry_d86f6ca7aa9d, analysis_f7d9a9f9559ef565:py_entry_fa6382bc744e, analysis_f7d9a9f9559ef565:py_entry_88464f30ad02, analysis_f7d9a9f9559ef565:py_entry_49eb33872d36, analysis_f7d9a9f9559ef565:py_entry_4e3973bc283a, analysis_f7d9a9f9559ef565:py_entry_b7441e2ca64b, analysis_f7d9a9f9559ef565:py_entry_39b5fd30e9a3, analysis_f7d9a9f9559ef565:py_entry_8f622205bd2f, analysis_f7d9a9f9559ef565:py_entry_11225e9c9110, analysis_f7d9a9f9559ef565:py_entry_5e73d47c3e6d, analysis_f7d9a9f9559ef565:py_entry_10190532b8cf, analysis_f7d9a9f9559ef565:py_entry_8d4ba4b8f2e4 |
| c21 A teaching claim names src/mcp/cli/cli.py as a detected starting point, but its entrypoint record is not listed, so how it starts is not established. | unresolved | supported | analysis_f7d9a9f9559ef565:claim_8229d87e32b7 |
| c22 The analyzer reports 658 bounded execution paths; 5 are listed, all starting at .github/actions/conformance/client.py. | inferred | supported | analysis_f7d9a9f9559ef565:claim_f35a48536d91, analysis_f7d9a9f9559ef565:exec_5e86e34bd295, analysis_f7d9a9f9559ef565:exec_e6323d56ad9b, analysis_f7d9a9f9559ef565:exec_7bf8b1b02bf8, analysis_f7d9a9f9559ef565:exec_fad222196619, analysis_f7d9a9f9559ef565:exec_f72d6b612163 |
| c23 The five listed paths stop at unresolved boundaries after one or two steps: logging.basicConfig, logging.getLogger, os.environ.get, or len and print reached via the local main. | inferred | supported | analysis_f7d9a9f9559ef565:exec_5e86e34bd295, analysis_f7d9a9f9559ef565:exec_e6323d56ad9b, analysis_f7d9a9f9559ef565:exec_7bf8b1b02bf8, analysis_f7d9a9f9559ef565:exec_fad222196619, analysis_f7d9a9f9559ef565:exec_f72d6b612163 |
| c24 Runtime behaviour beyond these static records is not established, because the analysis is static only and run inference is partial. | observed | supported | analysis_f7d9a9f9559ef565:lim_1, analysis_f7d9a9f9559ef565:lim_2 |
| c25 README.md, pyproject.toml and LICENSE are classified as project-level important files. | observed | supported | analysis_f7d9a9f9559ef565:important_1, analysis_f7d9a9f9559ef565:important_2, analysis_f7d9a9f9559ef565:important_3 |
| c26 .github/actions/conformance/client.py and docs_src tutorial files are flagged as important because they are likely entrypoints. | observed | supported | analysis_f7d9a9f9559ef565:important_4, analysis_f7d9a9f9559ef565:important_5, analysis_f7d9a9f9559ef565:important_6, analysis_f7d9a9f9559ef565:important_7, analysis_f7d9a9f9559ef565:important_8 |
| c27 The analyzer's learning-path claim suggests starting with manifests and important symbols, then tracing the bounded execution path and inspecting unresolved boundaries before changing code. | inferred | supported | analysis_f7d9a9f9559ef565:claim_e56db45165bf |
| c28 The analyzer's modify-guide claim says to begin at src/mcp/cli/cli.py and verify downstream effects manually. | inferred | supported | analysis_f7d9a9f9559ef565:claim_00634b33603f |
| c29 Top-level directory file counts are i18n 664, examples 298, tests 285, docs_src 218, src 140, docs 58, .github 27, root 18, scripts 12, schema 4, .claude 2. | inferred | supported | analysis_f7d9a9f9559ef565:summary_repository |
| c30 Tests exist: the analyzer counts 287 test-like files, and the tests directory holds 285 files. | inferred | supported | analysis_f7d9a9f9559ef565:summary_repository |
| c31 Install, run and build inference is partial and installation commands are not verified. | observed | supported | analysis_f7d9a9f9559ef565:lim_2 |
| c32 Dependency records come from requirements files, package.json and pyproject.toml; setup.py, setup.cfg, Pipfile and lock files are not parsed, and constraints are recorded as written. | observed | supported | analysis_f7d9a9f9559ef565:lim_3a |
| c33 README claim extraction is line-based and every README claim remains author_claimed at best. | observed | supported | analysis_f7d9a9f9559ef565:lim_4a |
| c34 The analysis is static only; reflection, dynamic imports, runtime dependency injection, generated code and framework wiring are not resolved. | observed | supported | analysis_f7d9a9f9559ef565:lim_1 |
| c35 Files over 400 kB, minified bundles and vendored directories are inventoried but not parsed. | observed | supported | analysis_f7d9a9f9559ef565:lim_6 |
| c36 One teaching claim says no bounded execution path is available, while the analyzer reports 658 paths and lists five, which is a packet-internal inconsistency. | inferred | supported | analysis_f7d9a9f9559ef565:claim_4d30ade3e21e, analysis_f7d9a9f9559ef565:claim_f35a48536d91, analysis_f7d9a9f9559ef565:exec_5e86e34bd295 |
| c37 A teaching claim names src/mcp/cli/cli.py as the starting point, while the analyzer's summary names .github/actions/conformance/client.py. | inferred | supported | analysis_f7d9a9f9559ef565:claim_8229d87e32b7, analysis_f7d9a9f9559ef565:summary_repository |
來源、權利與說明 · attribution-license-templates/v0.1
權利聲明。原始 repository 託管於 GitHub。其原始碼、文件、名稱、媒體與相關素材的權利,仍屬各自的作者、貢獻者與其他權利人所有,並受該 repository 的授權條款約束。
Original repository hosted on GitHub. Repository source code, documentation, names, media, and related project materials remain subject to the rights of their respective authors, contributors, and other rights holders and to applicable repository license terms.
平台聲明。GitHub 是所連結 repository 的來源託管平台。GitHub 與相關標誌為 GitHub, Inc. 的商標。除非另有明確說明,EVEMISS Technology 與 GitHub 之間沒有隸屬或背書關係。
GitHub is the source hosting platform for the linked repository. GitHub and related marks are trademarks of GitHub, Inc. EVEMISS Technology is not affiliated with or endorsed by GitHub unless explicitly stated otherwise.
這一頁怎麼來的。本頁由對應版本的 repository 分析與 AI 輔助的編輯工具產生。技術陳述綁定所分析的版本;原始 repository 更新後,可能重新驗證。
This page was produced using revision-aware repository analysis and AI-assisted editorial tooling. Technical claims are tied to the analyzed repository revision and may be revalidated when the source repository changes.
本頁包含 AI 輔助分析,並經 EVEMISS Technology 人工與 AI 協力審閱。 · 回報權利疑慮 · 回到概覽