EVEMISSTechnology

Repository 指南 · 概覽 · v2

modelcontextprotocol / python-sdk

“The official Python SDK for Model Context Protocol servers and clients” — 作者自述

  • AI Infrastructure
  • Python
  • MIT · 開源授權
來源平台
GitHub
擁有者 / 組織
modelcontextprotocol
授權
MIT · 開源授權
分析的版本
77001c96f9507be0f4d009b83210a384a5e08bda
最後驗證

2026-11-15 檢查過原始專案:預設分支仍在分析的版本。

本頁中文由負責的 AI 編輯依英文正式版本 v2 翻譯;程式碼名稱、路徑、行號與數字都經確定性檢查,與英文版一致。陳述與依據表保留英文原文,因為那是獨立驗證者核對過的紀錄。看英文原文

modelcontextprotocol/python-sdk:Repository 概覽

本頁用語說明
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 本身的審查。

這是一個 Python repository,其 GitHub 描述稱它是 Model Context Protocol 伺服器與用戶端的官方 Python SDK。程式碼分布在 src、tests、examples、docs_src 和 i18n 等目錄樹中。靜態分析找到許多 __main__ 進入點,並記錄了 47,493 個靜態關係,其中只有 6,041 個解析到本地目標。

它是什麼

這個 repository 的 GitHub 描述稱它是 Model Context Protocol(MCP)伺服器與用戶端的官方 Python SDK。這是作者的說法,本分析沒有加以查核。

平台 metadata 顯示:

  • 主要語言為 Python
  • 採用 MIT 授權
  • 主題為 mcp、mcp-client、mcp-server 和 python
  • 最新 release 標記為 v2.3.0

在結構上,src/mcp 包含各自獨立的 cli、client 和 server 套件,每個套件都有一個 __main__ 守衛。分析器在 src、tests、examples、docs_src、docs 和 i18n 等頂層目錄中盤點了 1726 個檔案。

如何啟動

分析器回報了 178 個進入點。在列出的進入點中,有九個只是依檔名啟發式規則標記,包括 src/mcp/cli/cli.py、src/mcp/server/lowlevel/server.py 和 src/mcp/server/mcpserver/server.py。

在函式庫內部,由三個套件守衛負責啟動:

  • src/mcp/cli/__init__.py 的守衛呼叫 app()
  • src/mcp/client/__main__.py 的守衛呼叫 cli()
  • src/mcp/server/__main__.py 透過 anyio 以 trio 後端執行 main:anyio.run(main, backend="trio")

在 examples/stories 底下,成對的 client.py 與 server.py 檔案會呼叫 run_client(main) 和 run_server_from_args(build_server) 等輔助函式。它們旁邊常常放著一個 server_lowlevel.py 變體。

分析器選擇 .github/actions/conformance/client.py 作為主要起點,它的守衛呼叫 main()。從這裡追蹤的路徑會立刻停在 print、len 和 sys.exit 等未解析的呼叫上。由於這個檔案屬於 CI 工具,這條靜態核心流程對 SDK 本身如何運作說明有限。

結構

各頂層目錄的檔案數為:i18n 664、examples 298、tests 285、docs_src 218、src 140、docs 58、.github 27、scripts 12 和 schema 4。分析器把 docs、docs_src、src 和 tests 視為子系統。

靜態圖共有 47,493 條邊:38,302 個呼叫和 9,191 個 import。其中只有 6,041 條邊解析到本地目標。

已解析的跨模組呼叫度數最高的模組全都位在 tests/ 底下:

  • tests/interaction/_connect.py:177 個呼入
  • tests/interaction/auth/_harness.py:145 個呼入
  • tests/shared/test_dispatcher.py:117 個呼入
  • tests/shared/test_jsonrpc_dispatcher.py:79 個呼出

這暗示共用的連線與 auth fixture 支撐了測試套件的大部分內容。這也代表度數排名並沒有指向 src 中的函式庫模組。

值得注意的符號

在 tests/interaction/_connect.py 中,Connect 類別旁邊有 connect_in_memory、connect_over_streamable_http 和 connect_over_sse 等工廠函式。這些名稱暗示測試會涵蓋多種傳輸方式。

tests/interaction/auth/_provider.py 定義了 InMemoryAuthorizationServerProvider。tests/interaction/_requirements.py 定義了 Requirement 類別,而 tests/interaction/test_coverage.py 包含一個名為 test_every_requirement_is_exercised 的測試。

依賴與測試

依賴記錄來自 18 個 manifest,大多是各範例自己的 pyproject.toml 檔案。

對於根目錄的 pyproject.toml,分析資料記錄了兩類項目:

  • 選用依賴:rich、typer 和 python-dotenv
  • 開發工具:pytest、pytest-xdist、pyright、ruff、trio、coverage、inline-snapshot 和 mkdocstrings

其中沒有出現根套件的 runtime 範圍記錄,因此這裡無法確定它的核心 runtime 需求。根 manifest 中也有 pillow 和 blockbuster 的重複項目,且下限版本不同。

src/mcp-types/pyproject.toml 在兩筆記錄中列出 pydantic(>=2.14.0 和 >=2.12.0),另外還有 typing-extensions。範例通常依賴 mcp,再搭配 click、anyio、httpx2、starlette 或 uvicorn。版本限制依 manifest 中的原始寫法記錄。

分析器計算出 287 個測試或類似測試的檔案,包括 .github/scripts 底下的 JavaScript 測試。Python 測試套件主要位在有 285 個檔案的 tests/ 目錄中。

優先閱讀

  1. 先從 README.md、pyproject.toml 和 LICENSE 開始,分析器把它們標為專案層級的重要檔案。README 中的陳述請視為作者的說法。
  2. 閱讀 src/mcp/cli/__init__.py、src/mcp/client/__main__.py 和 src/mcp/server/__main__.py 中的套件進入守衛。
  3. 查看 src/mcp/server/mcpserver/server.py 和 src/mcp/server/lowlevel/server.py。兩者都只是依檔名啟發式規則被標為進入點。
  4. 打開一份教學範例,例如 docs_src/client/tutorial001_client.py,它因為可能是進入點而被標為重要。
  5. 閱讀被呼叫最多次的測試輔助模組 tests/interaction/_connect.py,了解測試如何連接用戶端與伺服器。

本分析的限制

  • 本分析只做靜態分析。反射、動態 import、runtime 依賴注入、框架接線和動態分派都沒有解析,因此在 runtime 才選定的程式碼不會被追蹤。
  • 47,493 個靜態關係中,有 41,452 個仍屬外部或未解析。
  • 依賴解析涵蓋 requirements 檔案、package.json 和 pyproject.toml。setup.py、setup.cfg、Pipfile 和 lock 檔案不會被解析。
  • 安裝、執行和建置方式的推論並不完整。沒有查核任何安裝指令,也沒有執行任何東西。
  • 大型檔案、壓縮過的 bundle 和 vendored 目錄只會被盤點,不會被解析。關係擷取在每個檔案和每個 repository 上都有數量上限。
  • 分析器有一項教學陳述說不存在有界執行路徑,但分析資料中卻包含已追蹤的路徑。請審慎看待分析器的摘要。

這次分析無法確定的事

這些是撰寫模型對分析記錄自己的說明。lim_3、exec_* 或 claim_… 這類識別碼指的是那次分析裡的記錄;陳述與依據表引用的也是同一批記錄。

  • 分析資料中沒有根目錄 pyproject.toml 的 runtime 範圍依賴記錄,因此主套件的核心 runtime 需求未知;依賴清單被標為不完整。
  • 分析器有一項教學陳述說不存在有界執行路徑,但分析資料列出了已追蹤的執行路徑記錄,並回報 658 條有界路徑。
  • 分析器選定的主要起點是一個 CI conformance 用戶端,不是函式庫程式碼,因此它的核心流程並不能描述 SDK 的內部行為。
  • 模組度數排名只涵蓋測試模組;分析資料沒有描述 src/mcp 內部的呼叫結構。
  • 依賴名稱 'httpx2' 是依範例 manifest 中的原始寫法回報;它是刻意如此還是記錄時產生的誤差,目前無法確定。
  • 回報的 178 個進入點中,只有部分列在分析資料裡,因此這裡看不到完整的進入點集合。
陳述與依據 — 35 條陳述,35 條經獨立驗證者確認(英文原文)

上面每一句都是一條陳述,各自引用分析裡的依據編號。編號是這次分析內部的;表格列出每條陳述靠的是什麼、依據有多強。

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 GitHub description presents the repository as the official Python SDK for Model Context Protocol servers and clients. author_claimed supported analysis_f7d9a9f9559ef565:meta_description
c2 Platform metadata lists Python as primary language, an MIT license, topics mcp, mcp-client, mcp-server and python, and a latest release tagged v2.3.0. observed supported analysis_f7d9a9f9559ef565:meta_primary_language, analysis_f7d9a9f9559ef565:meta_license, analysis_f7d9a9f9559ef565:meta_topics, analysis_f7d9a9f9559ef565:meta_latest_release
c3 The analyzer inventoried 1726 files across top-level directories including src, tests, examples, docs_src, docs and i18n. inferred supported analysis_f7d9a9f9559ef565:summary_repository
c4 src/mcp/cli/__init__.py, src/mcp/client/__main__.py and src/mcp/server/__main__.py each contain a __main__ execution guard. observed supported analysis_f7d9a9f9559ef565:py_entry_d9208a18098d, analysis_f7d9a9f9559ef565:py_entry_b9466646417f, analysis_f7d9a9f9559ef565:py_entry_f9a552a95482
c5 The analyzer's architecture reconstruction reports 178 entrypoints in the repository. inferred supported analysis_f7d9a9f9559ef565:claim_f35a48536d91, analysis_f7d9a9f9559ef565:architecture_reconstruction
c6 Some entrypoints, including src/mcp/cli/cli.py, src/mcp/server/lowlevel/server.py and src/mcp/server/mcpserver/server.py, are detected only by a filename heuristic. inferred supported analysis_f7d9a9f9559ef565:entry_166, analysis_f7d9a9f9559ef565:entry_169, analysis_f7d9a9f9559ef565:entry_170
c7 The CLI package guard calls app(), the client package guard calls cli(), and the server package guard calls anyio.run(main, backend="trio"). observed supported analysis_f7d9a9f9559ef565:py_entry_d9208a18098d, analysis_f7d9a9f9559ef565:py_entry_b9466646417f, analysis_f7d9a9f9559ef565:py_entry_f9a552a95482
c8 Files under examples/stories call run_client(main) or run_server_from_args(build_server) in their guards, and server_lowlevel.py variants exist. observed supported analysis_f7d9a9f9559ef565:py_entry_5a0eebfe2abe, analysis_f7d9a9f9559ef565:py_entry_b93c5a9e94d4, analysis_f7d9a9f9559ef565:py_entry_b234a8aa3a3b
c9 The analyzer names .github/actions/conformance/client.py as the main starting place, and its guard calls main(). inferred supported analysis_f7d9a9f9559ef565:summary_repository, analysis_f7d9a9f9559ef565:py_entry_7ed4238a8b5b
c10 Traced paths from the conformance client's main end immediately at unresolved calls such as print, len and sys.exit, so they reveal little about SDK internals. inferred supported analysis_f7d9a9f9559ef565:exec_fad222196619, analysis_f7d9a9f9559ef565:exec_f72d6b612163, analysis_f7d9a9f9559ef565:exec_e615ffc0aac8
c11 Top-level file counts are i18n 664, examples 298, tests 285, docs_src 218, src 140, docs 58, .github 27, scripts 12, schema 4. inferred supported analysis_f7d9a9f9559ef565:summary_repository
c12 The analyzer records docs, docs_src, src and tests as subsystem directories. observed supported analysis_f7d9a9f9559ef565:subsys_1, analysis_f7d9a9f9559ef565:subsys_2, analysis_f7d9a9f9559ef565:subsys_3, analysis_f7d9a9f9559ef565:subsys_4
c13 The static graph holds 47,493 relations: 38,302 calls and 9,191 imports, with 6,041 resolved locally. observed supported analysis_f7d9a9f9559ef565:relation_counts
c14 The highest resolved cross-module call degrees belong to test modules: _connect.py (177 in), auth/_harness.py (145 in), test_dispatcher.py (117 in), test_jsonrpc_dispatcher.py (79 out). inferred supported analysis_f7d9a9f9559ef565:role_263, analysis_f7d9a9f9559ef565:role_267, analysis_f7d9a9f9559ef565:role_309, analysis_f7d9a9f9559ef565:role_310
c15 The degree ranking suggests shared connection and auth fixtures support much of the test suite and does not highlight library modules in src. inferred supported analysis_f7d9a9f9559ef565:role_263, analysis_f7d9a9f9559ef565:role_267, analysis_f7d9a9f9559ef565:role_309, analysis_f7d9a9f9559ef565:role_310
c16 tests/interaction/_connect.py defines Connect plus connect_in_memory, connect_over_streamable_http and connect_over_sse, hinting at tests across several transports. inferred supported analysis_f7d9a9f9559ef565:py_class_07e65be2dfad, analysis_f7d9a9f9559ef565:py_func_b92227bacd2e, analysis_f7d9a9f9559ef565:py_func_8f72ecdab61c, analysis_f7d9a9f9559ef565:py_func_aba9d88934fe
c17 InMemoryAuthorizationServerProvider and a Requirement class are defined in test helpers, and test_coverage.py contains test_every_requirement_is_exercised. observed supported analysis_f7d9a9f9559ef565:py_class_c648bad31f94, analysis_f7d9a9f9559ef565:py_class_3c0016ca138c, analysis_f7d9a9f9559ef565:py_func_5d442e95efd7
c18 The repository contains 18 build/dependency manifests, many of them per-example pyproject.toml files. observed supported analysis_f7d9a9f9559ef565:ev_manifest_1, analysis_f7d9a9f9559ef565:dep_1, analysis_f7d9a9f9559ef565:dep_21
c19 The root pyproject.toml records optional rich, typer and python-dotenv, and dev tools including pytest, pytest-xdist, pyright, ruff, trio, coverage, inline-snapshot and mkdocstrings. observed supported analysis_f7d9a9f9559ef565:dep_99, analysis_f7d9a9f9559ef565:dep_100, analysis_f7d9a9f9559ef565:dep_101, analysis_f7d9a9f9559ef565:dep_106, analysis_f7d9a9f9559ef565:dep_110, analysis_f7d9a9f9559ef565:dep_105, analysis_f7d9a9f9559ef565:dep_107, analysis_f7d9a9f9559ef565:dep_108, analysis_f7d9a9f9559ef565:dep_115, analysis_f7d9a9f9559ef565:dep_113, analysis_f7d9a9f9559ef565:dep_124
c20 No runtime-scope dependency record for the root package appears in the packet; the main package's core runtime requirements are not established. unresolved supported analysis_f7d9a9f9559ef565:lim_3a
c21 src/mcp-types/pyproject.toml records pydantic twice (>=2.14.0 and >=2.12.0) and typing-extensions >=4.13.0. observed supported analysis_f7d9a9f9559ef565:dep_130, analysis_f7d9a9f9559ef565:dep_131, analysis_f7d9a9f9559ef565:dep_132
c22 Example manifests record mcp with click, anyio, httpx2, starlette or uvicorn; version constraints are recorded as written. observed supported analysis_f7d9a9f9559ef565:dep_22, analysis_f7d9a9f9559ef565:dep_23, analysis_f7d9a9f9559ef565:dep_24, analysis_f7d9a9f9559ef565:dep_25, analysis_f7d9a9f9559ef565:dep_26, analysis_f7d9a9f9559ef565:dep_27, analysis_f7d9a9f9559ef565:dep_31, analysis_f7d9a9f9559ef565:dep_32, analysis_f7d9a9f9559ef565:dep_33, analysis_f7d9a9f9559ef565:dep_34, analysis_f7d9a9f9559ef565:dep_38, analysis_f7d9a9f9559ef565:dep_63, analysis_f7d9a9f9559ef565:dep_64, analysis_f7d9a9f9559ef565:dep_65, analysis_f7d9a9f9559ef565:dep_66, analysis_f7d9a9f9559ef565:dep_67, analysis_f7d9a9f9559ef565:dep_68, analysis_f7d9a9f9559ef565:lim_3a
c23 The root pyproject.toml has two pillow records and two blockbuster records with different lower bounds. observed supported analysis_f7d9a9f9559ef565:dep_116, analysis_f7d9a9f9559ef565:dep_117, analysis_f7d9a9f9559ef565:dep_121, analysis_f7d9a9f9559ef565:dep_122
c24 There are 287 test or test-like files, including JavaScript tests in .github/scripts; the 285-file tests directory holds most of them. inferred supported analysis_f7d9a9f9559ef565:ev_tests_1, analysis_f7d9a9f9559ef565:summary_repository
c25 README.md, pyproject.toml and LICENSE are marked as project-level important files; README-derived content stays author_claimed. observed supported analysis_f7d9a9f9559ef565:important_1, analysis_f7d9a9f9559ef565:important_2, analysis_f7d9a9f9559ef565:important_3, analysis_f7d9a9f9559ef565:lim_4a
c26 The cli, client and server packages under src/mcp each have a __main__ guard worth reading early. observed supported analysis_f7d9a9f9559ef565:py_entry_d9208a18098d, analysis_f7d9a9f9559ef565:py_entry_b9466646417f, analysis_f7d9a9f9559ef565:py_entry_f9a552a95482
c27 src/mcp/server/mcpserver/server.py and src/mcp/server/lowlevel/server.py are flagged as likely entrypoints by filename heuristic only. inferred supported analysis_f7d9a9f9559ef565:entry_170, analysis_f7d9a9f9559ef565:entry_169
c28 docs_src/client/tutorial001_client.py is marked important because it is likely an entrypoint. observed supported analysis_f7d9a9f9559ef565:important_7
c29 tests/interaction/_connect.py, with the highest incoming call count and a Connect class, is a useful view of how tests connect clients and servers. inferred supported analysis_f7d9a9f9559ef565:role_263, analysis_f7d9a9f9559ef565:py_class_07e65be2dfad
c30 The analysis is static only; reflection, runtime dependency injection, dynamic imports, framework wiring and dynamic dispatch are not resolved. observed supported analysis_f7d9a9f9559ef565:lim_1
c31 41,452 of 47,493 static relations remain external or unresolved. observed supported analysis_f7d9a9f9559ef565:relation_counts
c32 Dependency records come from requirements files, package.json and pyproject.toml; setup.py, setup.cfg, Pipfile and lock files are not parsed. observed supported analysis_f7d9a9f9559ef565:lim_3a
c33 Install, run and build inference is partial, installation commands are not verified, and the analysis is static only. observed supported analysis_f7d9a9f9559ef565:lim_2, analysis_f7d9a9f9559ef565:lim_1
c34 Files over 400 kB, minified bundles and vendored directories are inventoried but not parsed; relation extraction is capped per file and per repository. observed supported analysis_f7d9a9f9559ef565:lim_6
c35 An analyzer teaching claim states no bounded execution path is available, which conflicts with the traced execution paths present in the packet. inferred supported analysis_f7d9a9f9559ef565:claim_4d30ade3e21e, analysis_f7d9a9f9559ef565:exec_fad222196619

來源、權利與說明 · 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 協力審閱。 · 回報權利疑慮 · 所有 repository 指南