Fix protocol schemas so that they work with pydantic #361
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds the @typing.runtime_checkable decorator to the following protocols:
Motivation
When these protocols are used as type hints within Pydantic V2 models (specifically when arbitrary_types_allowed=True is set), Pydantic attempts to automatically generate an isinstance validator for the field.
Because these protocols were not marked as runtime checkable, standard Python isinstance() checks fail, causing Pydantic to raise a SchemaError during model creation.
Adding @runtime_checkable allows isinstance() to work correctly with these protocols, enabling downstream users to include standard LangChain MCP callbacks and interceptors directly in their Pydantic models without needing to type them as Any.
Error Reference
Without this change, attempting to use these types in a Pydantic V2 model results in tracebacks similar to:
Test Plan
[x] Verified that Pydantic V2 models can now successfully use these types as fields without raising SchemaError.