rust-sdk/crates/rmcp/Cargo.toml
Stanley Horwood e9a5ae9901
feat(model): add json schema generation support for all model types (#176)
* feat(model): add json schema generation support for all model types

This commit adds JSON Schema support for all model types by implementing
`schemars::JsonSchema` trait. The feature is gated behind the new
`schemars` feature flag. This enables automatic schema generation for
API documentation and validation purposes. Added tests to verify schema
generation for client and server JSON-RPC messages.

* fix(model): add manual json schema implementation for `NumberOrString`

This commit adds a manual implementation of `JsonSchema` trait for the
`NumberOrString` enum to properly represent its union type nature in
JSON Schema. The schema now correctly specifies that the type can be
either a number or a string using the `oneOf` validation keyword.

* fix(model): skip extensions field in json schema generation

The `Extensions` type was incorrectly included in JSON schema
generation, which could lead to confusing API documentation. This commit
adds `#[schemars(skip)]` attribute to all `extensions` fields in request
and notification structs, and removes the manual `JsonSchema`
implementation for the `Extensions` type since it's an internal
implementation detail that shouldn't be exposed in the schema.
2025-05-15 23:56:31 +08:00

139 lines
3.9 KiB
TOML

[package]
name = "rmcp"
license = { workspace = true }
version = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
homepage = { workspace = true }
readme = { workspace = true }
description = "Rust SDK for Model Context Protocol"
documentation = "https://docs.rs/rmcp"
[package.metadata.docs.rs]
all-features = true
[dependencies]
serde = { version = "1.0", features = ["derive", "rc"] }
serde_json = "1.0"
thiserror = "2"
chrono = { version = "0.4.38", features = ["serde"] }
tokio = { version = "1", features = ["sync", "macros", "rt", "time"] }
futures = "0.3"
tracing = { version = "0.1" }
tokio-util = { version = "0.7" }
pin-project-lite = "0.2"
paste = { version = "1", optional = true }
# oauth2 support
oauth2 = { version = "5.0", optional = true }
# for auto generate schema
schemars = { version = "0.8", optional = true, features = ["chrono"] }
# for image encoding
base64 = { version = "0.21", optional = true }
# for SSE client
reqwest = { version = "0.12", default-features = false, features = [
"json",
"stream",
], optional = true }
sse-stream = { version = "0.1.3", optional = true }
url = { version = "2.4", optional = true }
# For tower compatibility
tower-service = { version = "0.3", optional = true }
# for ws transport
# tokio-tungstenite ={ version = "0.26", optional = true }
# for http-server transport
axum = { version = "0.8", features = [], optional = true }
rand = { version = "0.9", optional = true }
tokio-stream = { version = "0.1", optional = true }
uuid = { version = "1", features = ["v4"], optional = true }
# macro
rmcp-macros = { version = "0.1", workspace = true, optional = true }
[features]
default = ["base64", "macros", "server"]
client = []
server = ["transport-async-rw", "dep:schemars"]
macros = ["dep:rmcp-macros", "dep:paste"]
__transport-sse = ["dep:reqwest", "dep:sse-stream", "dep:url"]
transport-sse = ["__transport-sse", "reqwest?/rustls-tls"]
transport-sse-tls-no-provider = ["__transport-sse", "reqwest?/rustls-tls-no-provider"]
transport-async-rw = ["tokio/io-util", "tokio-util/codec"]
transport-io = ["transport-async-rw", "tokio/io-std"]
transport-child-process = ["transport-async-rw", "tokio/process"]
transport-sse-server = [
"transport-async-rw",
"dep:axum",
"dep:rand",
"dep:tokio-stream",
"uuid",
]
transport-streamable-http-server = [
"transport-streamable-http-server-session",
"dep:axum",
"uuid",
]
transport-streamable-http-server-session = [
"transport-async-rw",
"dep:tokio-stream",
]
# transport-ws = ["transport-io", "dep:tokio-tungstenite"]
tower = ["dep:tower-service"]
__auth = ["dep:oauth2", "dep:reqwest", "dep:url"]
auth = ["__auth", "reqwest?/rustls-tls"]
auth-tls-no-provider = ["auth", "reqwest?/rustls-tls-no-provider"]
schemars = ["dep:schemars"]
[dev-dependencies]
tokio = { version = "1", features = ["full"] }
schemars = { version = "0.8" }
anyhow = "1.0"
tracing-subscriber = { version = "0.3", features = [
"env-filter",
"std",
"fmt",
] }
async-trait = "0.1"
[[test]]
name = "test_tool_macros"
required-features = ["server"]
path = "tests/test_tool_macros.rs"
[[test]]
name = "test_with_python"
required-features = ["server", "client", "transport-sse-server", "transport-sse", "transport-child-process"]
path = "tests/test_with_python.rs"
[[test]]
name = "test_with_js"
required-features = ["server", "client", "transport-sse-server", "transport-child-process", "transport-streamable-http-server"]
path = "tests/test_with_js.rs"
[[test]]
name = "test_notification"
required-features = ["server", "client"]
path = "tests/test_notification.rs"
[[test]]
name = "test_logging"
required-features = ["server", "client"]
path = "tests/test_logging.rs"
[[test]]
name = "test_message_protocol"
required-features = ["client"]
path = "tests/test_message_protocol.rs"
[[test]]
name = "test_message_schema"
required-features = ["server", "client", "schemars"]
path = "tests/test_message_schema.rs"