Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Ouverte Adaptée aux débutants
#3,673 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

  • #3687 par @Sak3th2004 — fermée sans fusion

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
84/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python
Domaine
cli

Piste de recherche

Lis src/mcp/cli/cli.py, en te concentrant sur _get_npx_command, _import_server et _check_server_object. Vérifie comment la vérification de npx sous Windows gère l’absence de l’exécutable, puis exécute les tests CLI pertinents ainsi que les vérifications Ruff et Pyright indiquées. Le travail est terminé lorsque l’exception est gérée et que les annotations demandées passent ces vérifications.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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).

Langage dominant
Python
Étoiles
24.5k
Forks
4k
Merge moyen
18 h 19 min
PR mergées (30 j)
36

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de modelcontextprotocol/python-sdk

Toutes les issues de modelcontextprotocol/python-sdk

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.