File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -81,17 +81,11 @@ def validate_api_key(api_key: str | None = None) -> str:
8181
8282 api_key = SETTINGS .get ("PMG_MAPI_KEY" )
8383
84- if not api_key :
85- raise ValueError (
86- "Please obtain an API key from https://materialsproject.org/api "
87- "and export it as an environment variable `MP_API_KEY`."
88- )
89-
90- if api_key and len (api_key ) != 32 :
84+ if not api_key or (wrong_len := len (api_key ) != 32 ):
85+ addendum = " Valid API keys are 32 characters." if wrong_len else ""
9186 raise ValueError (
92- "Please use a new API key from https://materialsproject.org/api "
93- "Keys for the new API are 32 characters, whereas keys for the legacy "
94- "API are 16 characters."
87+ "Please obtain a valid API key from https://materialsproject.org/api "
88+ f"and export it as an environment variable `MP_API_KEY`.{ addendum } "
9589 )
9690
9791 return api_key
Original file line number Diff line number Diff line change @@ -20,12 +20,12 @@ class MPMcp(BaseModel):
2020 @property
2121 def client (self ) -> MPRester :
2222 # Always return JSON compliant output for MCP
23- kwargs = {
24- ** (self .client_kwargs or {}),
25- "use_document_model" : False ,
26- "monty_decode" : False ,
27- }
2823 if not self ._client :
24+ kwargs = {
25+ ** (self .client_kwargs or {}),
26+ "use_document_model" : False ,
27+ "monty_decode" : False ,
28+ }
2929 self ._client = MPRester (** kwargs )
3030 return self ._client
3131
You can’t perform that action at this time.
0 commit comments