Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Type annotation gaps and unhandled FileNotFoundError in src/mcp/cli/cli.py

未關閉 適合新手
#3,673 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
84/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
cli

研究方向

閱讀 src/mcp/cli/cli.py,重點查看 _get_npx_command、_import_server 和 _check_server_object。檢查 Windows 上的 npx 探測如何處理執行檔缺失的情況,接著執行相關的 CLI 測試,以及指定的 Ruff 和 Pyright 檢查。例外獲得處理,且要求的註解通過這些檢查後,即表示完成。

由索引模型根據 Issue 內容生成。

描述

enhancement
Environment / Context

While running static analysis (ruff check --select ANN and pyright) on src/mcp/cli/cli.py during local development, I noticed a few missing type annotations and an uncaught exception edge case on Windows.

Description
  1. Unhandled FileNotFoundError in _get_npx_command:
    In src/mcp/cli/cli.py, _get_npx_command() attempts to probe for npx executables on Windows inside a try...except subprocess.CalledProcessError: block. If npx.cmd or npx.exe is missing from the system entirely, subprocess.run raises FileNotFoundError before CalledProcessError can be raised, causing an unexpected crash instead of returning None.

  2. Missing Return Type Annotations (ANN202):

    • _get_npx_command() lacks a return type annotation (returns str | None).
    • _import_server() lacks a return type annotation.
    • _check_server_object() lacks a return type annotation (-> bool).
  3. Any Type Usage (ANN401):

    • _check_server_object() uses server_object: Any, which can be tightened to object since it performs runtime isinstance checks.
Proposed Fix
  • Update _get_npx_command() to catch (subprocess.CalledProcessError, FileNotFoundError) and return str | None.
  • Add explicit return type annotations to _import_server and _check_server_object.
  • Replace server_object: Any with server_object: object.

I would be happy to submit a PR for this if a maintainer is willing to assign the issue to me!
I know that the contributing guidelines for this project forbid direct PRs about formatting and such without assigning, so just putting this out there.

(Note: Disclosing per guidelines that AI tools were used to assist in local testing and analysis; I am ready to own, test, and answer questions on the proposed changes).

主要語言
Python
星號
24.5k
分支
4k
平均合併
15 小時 19 分鐘
30 天內合併 PR
32

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。