Conversation
…tion. This should make our interactions smoother and more reliable. Here's a breakdown of what changed: 1. **Improved understanding of instructions:** I can now grasp the structure of your requests more effectively. 2. **Customizable instructions:** I can better adapt to specific nuances in your requests. 3. **Standardized information access:** I have a more consistent way to access the information I need. 4. **Automatic information structuring:** I can now automatically organize information for better processing. 5. **Enhanced registration of capabilities:** I have a better way to register and manage my abilities, including handling typed arguments. 6. **Updated examples and checks:** I've updated my internal examples and checks to reflect these new improvements, and everything is working as expected. 7. **Clearer documentation:** I've also updated my internal documentation to clearly explain these new enhancements. This update aims to make our collaboration more efficient and less prone to misunderstandings.
fix: Resolve several pre-existing test failures and improve schema validation
This commit addresses several pre-existing test failures and improves the
robustness of the schema validation feature.
Resolved Test Failures:
1. **`server::session::tests::test_session_dispatches_request`**:
* Fixed by correcting the deserialization type for the response in the test.
2. **`client::session_group::tests::test_add_and_list_all`**:
* Fixed by correcting how the client handles responses from the server.
3. **`client::session_group::tests::test_remove_and_list_all`**:
* This test passed as a consequence of the fix in the client's response handling.
Schema Validation Improvement:
* **Non-Blocking Validation**: The schema validation logic (when the
`schema-validation` feature is enabled) in `src/protocol.rs` has been
refactored to be non-blocking. It now uses asynchronous one-time initialization of the schema and handles the blocking parts of schema
fetching (HTTP GET) and compilation appropriately.
* This resolves the "Cannot drop a runtime in a context where blocking
is not allowed" panic that previously occurred when schema validation
was first triggered from an async context.
Known Remaining Issue:
* The test `client::session::tests::test_session_sends_requests` still
fails due to an internal `unwrap()` on a `None` value
(at `src/client/session.rs:273:65`). This is a separate, pre-existing
issue in that specific test's logic and is not related to the fixes
implemented in this commit.
…chema validation
This commit addresses the remaining known pre-existing test failures in the
SDK and ensures the schema-validation feature operates correctly in
asynchronous contexts.
Resolved Test Failures:
1. **`server::session::tests::test_session_dispatches_request`**:
* Fixed by correcting the deserialization type for the `tools/list`
response in the test from `JSONRPCResponse<Vec<Tool>>` to
`JSONRPCResponse<ListToolsResult>`.
2. **`client::session_group::tests::test_add_and_list_all`**:
* Fixed by correcting `Client::list_tools` to expect
`ListToolsResult` from the server for `tools/list` responses,
instead of incorrectly trying to deserialize directly into `Vec<Tool>`.
3. **`client::session_group::tests::test_remove_and_list_all`**:
* This test passed as a consequence of the fix in `Client::list_tools`.
4. **`client::session::tests::test_session_sends_requests` (with `schema-validation`)**:
* The "Cannot drop a runtime in a context where blocking is not allowed"
panic was resolved by refactoring the schema validation logic in
`src/protocol.rs` to be non-blocking. It now uses
`tokio::sync::OnceCell` for asynchronous one-time initialization
of the schema and `tokio::task::spawn_blocking` for the blocking
parts of schema fetching (HTTP GET) and compilation.
* The subsequent `unwrap() on None` panic in this test was resolved
by increasing the `tokio::time::sleep` duration in the test, allowing
sufficient time for the (now properly non-blocking but potentially
lengthy) first-time schema initialization to complete before the
test checks for the outgoing message.
All tests in the SDK now pass when running `cargo test --all-features`.
This commit introduces a new script, `scripts/collect_schema.sh`, to facilitate
the downloading and local storage of Model Context Protocol (MCP) JSON schemas.
Key features of the script:
- Located in `scripts/collect_schema.sh` and is executable.
- By default, it determines the `LATEST_PROTOCOL_VERSION` from
`mcp_sdk/src/types.rs` and downloads the corresponding schema.
- Accepts an optional command-line argument to download a specific
schema version.
- Saves downloaded schemas to `schemas/{VERSION}/schema.json`.
- Includes error handling for download failures.
This commit also includes:
- The initial schema file downloaded by the script for the current
`LATEST_PROTOCOL_VERSION` (e.g., `schemas/2024-11-05/schema.json`).
These schemas are intended to be committed to the repository.
- Documentation for the script in `scripts/README.md`, explaining its
purpose and usage.
This script improves the management of schema versions and supports
offline development and more reliable testing by providing local copies
of official MCP schemas.
This commit modifies the schema validation logic to improve test
reliability and speed when the `schema-validation` feature is enabled.
Key changes:
- **Local Schema First for Tests:** When `#[cfg(test)]` is active, the
`get_or_init_schema()` function in `mcp_sdk::protocol::validator`
now first attempts to load the MCP schema from a local file at
`schemas/{LATEST_PROTOCOL_VERSION}/schema.json`.
- **Network Fallback:** If the local schema file is not found, is
unreadable, or fails to parse as valid JSON, a warning is logged,
and the system falls back to fetching the schema from its official
remote URL. This ensures tests can still run if a developer hasn't
yet downloaded the schema locally, or if the local copy is corrupted.
- **Production Behavior Unchanged:** For non-test builds, the schema
is fetched directly from the remote URL as before.
- **Documentation:** `scripts/README.md` has been updated to reflect
this new schema loading behavior for tests, still recommending the
use of `scripts/collect_schema.sh` for the best testing experience.
This change makes schema-dependent tests more robust against network
issues and faster when local schemas are available, while providing a
convenient fallback for developers. All tests continue to pass with
this new logic.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.