Commit graph

388 commits

Author SHA1 Message Date
Jean-Marc Le Roux
fbc7ab70ca
feat: Add support for Tool.outputSchema and CallToolResult.structuredContent (#316)
* feat: add output_schema field to Tool struct

- Add optional output_schema field to Tool struct for defining tool
output structure
- Update Tool::new() to initialize output_schema as None

* feat: add structured_content field to CallToolResult

- Add optional structured_content field for JSON object results
- Make content field optional to support either structured or
unstructured results
- Add CallToolResult::structured() and structured_error() constructor
methods

* feat: implement validation for mutually exclusive content/structuredContent

- Add validate() method to ensure content and structured_content are
mutually exclusive
- Implement custom Deserialize to enforce validation during
deserialization
- Update documentation to clarify the mutual exclusivity requirement

* feat: add output_schema support to #[tool] macro

- Add output_schema field to ToolAttribute and ResolvedToolAttribute
structs
- Implement automatic output schema generation from return types
- Support explicit output_schema attribute for manual specification
- Generate schemas for Result<T, E> where T is not CallToolResult
- Update tool generation to include output_schema in Tool struct

* feat: implement IntoCallToolResult for structured content

- Add Structured<T> wrapper type for explicit structured content
- Implement IntoCallToolResult for Structured<T> with JSON serialization
- Add support for Result<Structured<T>, E> conversions
- Enable tools to return structured content through the trait system

* fix: update simple-chat-client example for optional content field

- Handle Option<Vec<Content>> in CallToolResult.content
- Add proper unwrapping for the optional content field
- Fix compilation error in chat.rs

* fix: update examples and tests for optional content field

- Add output_schema field to Tool initialization in sampling_stdio
example
- Update test_tool_macros tests to handle Option<Vec<Content>>
- Use as_ref() before calling first() on optional content field

* feat: implement basic schema validation in conversion logic

- Add validate_against_schema function for basic type validation
- Add note that full JSON Schema validation requires dedicated library
- Document that actual validation should happen in tool handler

* feat: add structured output support for tools

- Add output_schema field to Tool struct for defining output JSON schemas
- Add structured_content field to CallToolResult (mutually exclusive with content)
- Implement Structured<T> wrapper for type-safe structured outputs
- Update #[tool] macro to automatically generate output schemas from return types
- Add validation of structured outputs against their schemas
- Update all examples and tests for breaking change (CallToolResult.content now Option)
- Add comprehensive documentation and rustdoc
- Add structured_output example demonstrating the feature

BREAKING CHANGE: CallToolResult.content is now Option<Vec<Content>> instead of Vec<Content>

Closes #312

* fix: correct structured output doctest to use Parameters wrapper

The #[tool] macro requires Parameters<T> wrapper for tool inputs.
This fixes the pre-existing broken doctest in the structured output
documentation example.

* feat: replace Structured<T> with Json<T> for structured output

- Remove Structured<T> type definition and implementations
- Reuse existing Json<T> wrapper for structured content
- Update IntoCallToolResult implementations to use Json<T>
- Add JsonSchema implementation for Json<T> delegating to T
- Update all examples and tests to use Json<T> instead of Structured<T>
- Update documentation and exports

BREAKING CHANGE: Structured<T> has been replaced with Json<T>. Users must update their code to use Json<T> for structured tool outputs.

* feat: add output_schema() method to IntoCallToolResult trait

- Add output_schema() method with default None implementation
- Implement output_schema() for Json<T> to return cached schema
- Implement output_schema() for Result<Json<T>, E> delegating to Json<T>
- Enable trait-based schema generation for structured outputs

* feat: update macro to detect Json<T> wrapper for output schemas

- Add extract_json_inner_type() helper to detect Json<T> types
- Update schema generation to only occur for Json<T> wrapped types
- Remove generic Result<T, E> detection in favor of specific Json<T> detection
- Add comprehensive tests to verify schema generation behavior

* feat: add builder methods to Tool struct for setting schemas

- Add with_output_schema<T>() method to set output schema from type
- Add with_input_schema<T>() method to set input schema from type
- Both methods use cached_schema_for_type internally
- Add comprehensive tests for builder methods

* fix: address clippy warnings

- Add Default implementation for StructuredOutputServer
- Fix collapsible else-if in simple-chat-client
- No functional changes

* style: apply cargo fmt

Apply automatic formatting changes to:
- examples/simple-chat-client/src/chat.rs - fix line wrapping
- crates/rmcp-macros/src/tool.rs - format method chaining
- examples/servers/src/structured_output.rs - reorder imports and format function signatures

* chore: fix formatting

* chore: fix rustdoc redundant link warning

* refactor: validate_against_schema

* feat: enforce structured_content usage when output_schema is defined

This commit implements strict validation to ensure tools with output_schema
consistently use structured_content for both success and error responses.

Changes:
- Enhanced ToolRouter::call() validation to require structured_content when output_schema is present
- Added validation that tools with output_schema cannot use regular content field
- Added comprehensive tests covering the new strict validation behavior
- Created example demonstrating proper structured output usage
- Updated TODO.md to track validation improvements

This ensures consistent response format and better type safety for MCP clients.

* chore: remove TODO.md

* refactor: simplify output schema extraction logic in tool macro

- Extract complex nested logic into dedicated helper function
- Replace deeply nested if-else chains with functional approach
- Use early returns and ? operator for cleaner code flow
- Reduce 46 lines to 7 lines in main logic while improving readability

* chore: run cargo fmt

* fix: enforce structured_content usage when output_schema is defined

Structured content is returned as a JSON object in the structuredContent
field of a result.For backwards compatibility, a tool that returns
structured content SHOULD also return the serialized JSON in a
TextContent block.

https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content

Tools may also provide an output schema for validation of structured
results. If an output schema is provided:

- Servers MUST provide structured results that conform to this schema.
- Clients SHOULD validate structured results against this schema.

https://modelcontextprotocol.io/specification/2025-06-18/server/tools#output-schema

* chore: cargo fmt
2025-07-31 16:32:24 +08:00
jokemanfire
b1da5e8969
fix(prompt): remove unused code (#343) 2025-07-31 14:41:38 +08:00
github-actions[bot]
ec6bd056d7
chore: release v0.3.2 (#342)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-30 21:21:10 -04:00
John Howard
0a9a0a0b1f
fix(capabilities): do not serialize None as null for list_changed (#341)
The old form violates the spec, and all other `Option<bool>` fields also
behave this way. Concretely https://github.com/upstash/context7/ fails
without this change.
2025-07-30 11:08:31 +08:00
Pedro DiazVargas
855f57e0e7
fix(Transport): close oneshot transport on error (#340) 2025-07-30 11:03:21 +08:00
Brendan Graham
98bf02df89
fix(oauth): expose OAuthTokenResponse publicly (#335) 2025-07-30 10:53:21 +08:00
github-actions[bot]
0e37736a76
chore: release v0.3.1 (#328)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-29 14:41:06 -04:00
Andrew Harvard
7ba1ac4959
fix: use mimeType instead of mime_type for MCP specification compliance (#339)
- Fix ResourceContents enum to properly serialize with camelCase field names
- Add comprehensive tests to verify JSON serialization compliance
- Ensure all resource-related structs use mimeType as per MCP spec
- Add tests for RawResource, ResourceContents, RawImageContent, RawAudioContent
- Add test for prompt message image content serialization
- Update message schema files to reflect mimeType changes
- Fix import ordering to match project formatting standards

This change ensures the Rust SDK is fully compliant with the MCP specification
which requires mimeType (camelCase) for all resource content types.
2025-07-29 12:42:56 -04:00
Liu Xingyu
cdea86fb17
docs(README): update zh_cn README (#336) 2025-07-29 02:41:38 +08:00
Nate Usher
d251800d19
fix: return a 405 for GET and DELETE if stateful_mode=false (#331) 2025-07-29 02:41:17 +08:00
Nate Usher
179296134a
fix: propagate tracing spans when spawning new tokio tasks (#334) 2025-07-29 02:39:42 +08:00
Brett Cannon
9bfe2c9675
Fix formatting in crate descriptions in README.md (#333)
Correct formatting of crate descriptions in README.
2025-07-28 09:13:24 +08:00
dependabot[bot]
ac40e00490
chore(deps): update rig-core requirement from 0.14.0 to 0.15.1 (#327)
Updates the requirements on [rig-core](https://github.com/0xPlaygrounds/rig) to permit the latest version.
- [Release notes](https://github.com/0xPlaygrounds/rig/releases)
- [Commits](https://github.com/0xPlaygrounds/rig/compare/rig-core-v0.14.0...rig-core-v0.15.1)

---
updated-dependencies:
- dependency-name: rig-core
  dependency-version: 0.15.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: jokemanfire <hu.dingyang@zte.com.cn>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-22 09:08:04 +08:00
Peter Nehrer
2077c8faff
fix: Explicitly added client_id as an extra parameter causes bad token requests (#322) 2025-07-22 09:06:52 +08:00
kah
8967daf87f
fix(examples): Prevent transport from closing due to premature client drop (#324) 2025-07-21 09:40:47 +08:00
Kyle Leonhard
f1000930b6
doc(oauth): Update examples in OAUTH_SUPPORT.md (#323) 2025-07-21 09:38:24 +08:00
github-actions[bot]
6728191660
chore: release v0.3.0 (#307)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-16 16:28:56 -04:00
dependabot[bot]
83c15ebcb3
chore(deps): update darling requirement from 0.20 to 0.21 (#318)
Updates the requirements on [darling](https://github.com/TedDriggs/darling) to permit the latest version.
- [Release notes](https://github.com/TedDriggs/darling/releases)
- [Changelog](https://github.com/TedDriggs/darling/blob/master/CHANGELOG.md)
- [Commits](https://github.com/TedDriggs/darling/compare/v0.20.0...v0.21.0)

---
updated-dependencies:
- dependency-name: darling
  dependency-version: 0.21.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: jokemanfire <hu.dingyang@zte.com.cn>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-15 09:15:39 +08:00
dependabot[bot]
a215999bcb
chore(deps): update rig-core requirement from 0.13.0 to 0.14.0 (#317)
Updates the requirements on [rig-core](https://github.com/0xPlaygrounds/rig) to permit the latest version.
- [Release notes](https://github.com/0xPlaygrounds/rig/releases)
- [Commits](https://github.com/0xPlaygrounds/rig/compare/rig-core-v0.13.0...rig-core-v0.14.0)

---
updated-dependencies:
- dependency-name: rig-core
  dependency-version: 0.14.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: jokemanfire <hu.dingyang@zte.com.cn>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-15 09:14:41 +08:00
dependabot[bot]
dd311b72e9
chore(deps): update toml requirement from 0.8 to 0.9 (#319)
Updates the requirements on [toml](https://github.com/toml-rs/toml) to permit the latest version.
- [Commits](https://github.com/toml-rs/toml/compare/toml-v0.8.0...toml-v0.9.2)

---
updated-dependencies:
- dependency-name: toml
  dependency-version: 0.9.2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: jokemanfire <hu.dingyang@zte.com.cn>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-07-15 09:13:19 +08:00
jokemanfire
3196c95f1d
chore(deps): update schemars requirement from 0.8 to 1.0 (#258)
* chore(deps): update schemars requirement from 0.8 to 0.9

* fix: adapt the new openApi structure

* fix : fix the shemar deps in example
2025-07-11 11:15:45 +08:00
4t145
e615300fea
feat: unified error type (#308)
* feat: unified error type

* fix: use type id to compare transport type
2025-07-09 11:23:39 +08:00
Brendan Graham
c74b26b3e3
chore(rmcp): bump rmcp-macros version to match (#311) 2025-07-08 09:02:19 +08:00
TiejunZhou
2d997e18b7
docs: fix packages used for server example (#309) 2025-07-08 01:12:58 +08:00
Brendan Graham
69712e321a
feat(transport): add builder & expose child stderr (#305) 2025-07-05 09:14:43 +08:00
Tyress K
31155a440c
feat(examples): add streamable HTTP section in configs (#296) 2025-07-03 11:07:28 +08:00
github-actions[bot]
ee80903091
chore: release v0.2.1 (#302)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-02 21:55:28 -04:00
Alex Hancock
c6dcbd72e4
chore(docs): Minor README updates (#301)
* chore(docs): minor readme updates

* fix: correct typos in changelog
2025-07-02 21:50:32 -04:00
github-actions[bot]
c0f372001f
chore: release v0.2.0 (#300)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
2025-07-02 14:50:51 -04:00
Alex Hancock
ca36901733
fix(build): cargo.toml cleanup (#298) 2025-07-02 14:26:34 -04:00
Alex Hancock
f5649cae06
feat: set up release-plz integration for publishing to crates.io (#297) 2025-07-02 12:12:21 -04:00
4t145
9ca20c69b2
feat: mark boxed http body as sync (#291) 2025-07-01 11:27:15 +08:00
jokemanfire
1b3db8959c
example: add simpling example and test (#289)
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
2025-06-30 18:18:23 +08:00
Daniel Mangum
b9d7d61ebd
docs: fix grammar in oauth usage steps (#287)
Fixes minor grammatical issues in final oauth usage steps.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2025-06-26 09:36:32 +08:00
jokemanfire
e6effb3278
chore: add update for test_message_schema (#286) 2025-06-25 21:43:58 +08:00
jokemanfire
09caeb3afb
docs: add notion clear in model.rs (#284)
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
2025-06-25 20:29:38 +08:00
4t145
55215b6170
chore: cov settings, and fix serveral building warnings (#281)
* chore: cov settings, update Python test dependencies and adjust command arguments

* fix: remove .vscode dir
2025-06-25 14:30:45 +08:00
4t145
8e1490bcd8
feat: add progress notification handling and related structures (#282)
* feat: add progress notification handling and related structures

also fix some lifetime bugs of tool macro

* fix: fmt
2025-06-25 14:30:22 +08:00
4t145
893969ac77
fix: let users decide what to wrap in child process command (#279) 2025-06-24 15:26:43 +08:00
4t145
57db771a81
fix: cancellable initialization process (#280) 2025-06-24 15:26:03 +08:00
4t145
1f7f4d3055
refactor: refactor tool macros and router implementation (#261)
* refactor: refactor tool macros and router implementation

- Updated the `#[tool(tool_box)]` macro to `#[tool_router]` across various modules for consistency.
- Enhanced the `Calculator`, `Counter`, and `GenericService` structs to utilize `ToolRouter` for handling tool calls.
- Introduced `Parameters` struct for better parameter handling in tool functions.
- Added new methods for listing tools and calling tools in server handlers.
- Improved test cases to reflect changes in tool routing and parameter handling.
- Updated documentation and examples to align with the new router structure.

* fix: fix fmt and build error

* fix: fix test failure

* docs: documents for macros, fix ci

* fix: fix ci

* fix: fix wrongly replaced documents

* fix: remove useless file

* fix: change the parameter format for tool_router

* fix: update extract_doc_line to handle existing documentation and clean up unused code in server handler

* doc: update document for macro and examples

* doc: update readme and add contribute guide

* fix: fix type
2025-06-24 04:01:22 +08:00
4t145
6d3190504c
fix: inject part into extension when handing init req (#275) 2025-06-24 00:52:38 +08:00
Dale Seo
a62c6d1db8
docs: fix broken links in example readme (#273) 2025-06-20 09:42:48 +08:00
John Howard
13e72ec6c4
sse: fix regression in URL joining (#265)
* sse: fix regression in URL joining

This was broken by
https://github.com/modelcontextprotocol/rust-sdk/pull/197.

The URL join behaves like this:

```
$ let baseUrl = "https://example.com/sse";
$ new URL("?sessionId=x", baseUrl).href
'https://example.com/sse?sessionId=x'
$ new URL("/?sessionId=x", baseUrl).href
'https://example.com/?sessionId=x'
```

The PR #197 did not take into account the relative URL

Fixes https://github.com/modelcontextprotocol/rust-sdk/issues/252

* Address review comments
2025-06-19 11:57:17 +08:00
4t145
8a577659f0
fix: streamable http server close request channel on response(#266) (#270)
* fix: improve resource unregistration logic in LocalSessionWorker

* fix: fix typo

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-19 01:09:36 +08:00
4t145
4c34b64b7f
fix: streamable http client close on response (#268) 2025-06-18 13:48:42 +08:00
wenhaozhao
b9bba0be15
Fix: remove erroneous definitions_path (#264)
* fix bug,
1 remove erroneous definitions_path setting,"#/components/schemas/" is used for openapi3
2 show meta_schema

* Update crates/rmcp/src/handler/server/tool.rs

Remove the commented-out settings.inline_subschemas line to avoid confusion and clean up dead code.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: wenhaozhao <wenhaozhao@sohu-inc.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-18 09:07:28 +08:00
Alex Hancock
d45136c3ed
fix(github): add required permission to create labels (#267) 2025-06-18 09:00:14 +08:00
dependabot[bot]
d1884fe598
chore(deps): update tokio-tungstenite requirement from 0.26.2 to 0.27.0 (#263)
Updates the requirements on [tokio-tungstenite](https://github.com/snapview/tokio-tungstenite) to permit the latest version.
- [Changelog](https://github.com/snapview/tokio-tungstenite/blob/master/CHANGELOG.md)
- [Commits](https://github.com/snapview/tokio-tungstenite/compare/v0.26.2...v0.27.0)

---
updated-dependencies:
- dependency-name: tokio-tungstenite
  dependency-version: 0.27.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: jokemanfire <hu.dingyang@zte.com.cn>
2025-06-17 09:51:05 +08:00
John Howard
73188eff6f
feat: allow failable service creation in streamable HTTP tower service (#244)
* feat: allow failable service creation in streamable HTTP tower service

In our setup we need to lookup some info that may fail before we serve
the request.

* Fix examples build
2025-06-16 01:13:35 +08:00