-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix mcp.types.Tool is not following python's naming convention snake_case #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
propose for fix: mcp.types.Tool is not following python's naming convention modelcontextprotocol#97
remove Field as it is 2x
|
Hmm I think this is sensible, but we need to probably wait for SDK 2.0 to introduce this as it is a BC break. I keep it open for now until we start a 2.0 branch. |
|
OK.. Fully understood. class Tool(BaseModel):
"""Definition for a tool the client can call."""
name: str
"""The name of the tool."""
description: str | None = None
"""A human-readable description of the tool."""
input_schema: dict[str, Any]
"""A JSON Schema object defining the expected parameters for the tool."""
model_config = ConfigDict(extra="allow", populate_by_name=True)
@model_validator(mode='before')
@classmethod
def _convert_camel_to_snake_names(cls, data):
if isinstance(data, dict) and 'inputSchema' in data:
data['input_schema'] = data.pop('inputSchema')
return dataThe main differences between the original
Example:# Original version work as:
tool1 = Tool(name="hammer", inputSchema={"type": "object"})
# Proposed version should work in both cases
tool2 = Tool(name="hammer", inputSchema={"type": "object"}) # Still works
tool3 = Tool(name="hammer", input_schema={"type": "object"}) # Also worksIn summary, the second version is more flexible and handles both naming conventions seamlessly. |
sorry totally missed this. I think we should probably do this in the v1.x series and start warning with a deprecation warning if inputSchema is used. Do you mind sending a PR and re-requesting a review @azdolinski ? |
|
Thanks for this @azdolinski we'll want to do this for the whole code base and given it's likely to be a breaking change we're punting this to v2 of the SDK. |
|
Closing this as we're tracking in #1253 |
Renamed the
inputSchemafield toinput_schemain theToolclass to align with Python's naming conventions (snake_case). Added an aliasinputSchemafor backward compatibility.Motivation and Context
The name
inputSchemadoes not follow Python's naming convention (PEP 8). This change improves code readability and consistency. Fix related: #97How Has This Been Tested?
Tested locally by running existing tests.
Breaking Changes
inputSchemafield toinput_schema. Adding an alias is intended to ease the migration.Types of changes
Checklist
Additional context
The addition of the
inputSchemaalias is intended to provide backward compatibility and facilitate the migration process for users.