diff --git a/.gitignore b/.gitignore index 65e4aef..0c00796 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/.env **/.venv +mcp-gateway/target/ diff --git a/README.md b/README.md index f97e0e2..fe29961 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ Prototypes and proofs-of-concept | [server](./server) | Example of MCP authentication using OCI IDCS and OAuth | | [infrastructure](./infrastructure) | Example templates that instantiate an OCI GPU compute instance and install the Nvidia stack | | [generator](./generator) | A utility to quickly generate an OCI-specific MCP server using [cookiecutter](https://cookiecutter.readthedocs.io/en/stable/) | +| [mcp-gateway](./mcp-gateway) | A small MCP aggregation service that exposes multiple upstream MCP servers through a single endpoint | ## Getting started diff --git a/mcp-gateway/Cargo.lock b/mcp-gateway/Cargo.lock new file mode 100644 index 0000000..771b480 --- /dev/null +++ b/mcp-gateway/Cargo.lock @@ -0,0 +1,2225 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aho-corasick" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" +dependencies = [ + "memchr", +] + +[[package]] +name = "anstream" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "axum" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b52af3cb4058c895d37317bb27508dccc8e5f2d39454016b297bf4a400597b8" +dependencies = [ + "axum-core", + "axum-macros", + "bytes", + "form_urlencoded", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "itoa", + "matchit", + "memchr", + "mime", + "percent-encoding", + "pin-project-lite", + "serde_core", + "serde_json", + "serde_path_to_error", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-core" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08c78f31d7b1291f7ee735c1c6780ccde7785daae9a9206026862dab7d8792d1" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "http-body-util", + "mime", + "pin-project-lite", + "sync_wrapper", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "axum-macros" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "604fde5e028fea851ce1d8570bbdc034bec850d157f7569d10f347d06808c05c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "bitflags" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" + +[[package]] +name = "bumpalo" +version = "3.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d20789868f4b01b2f2caec9f5c4e0213b41e3e5702a50157d699ae31ced2fcb" + +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + +[[package]] +name = "cc" +version = "1.2.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aebf35691d1bfb0ac386a69bac2fde4dd276fb618cf8bf4f5318fe285e821bb2" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "clap" +version = "4.5.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.5.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831" + +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + +[[package]] +name = "core-foundation" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "crossbeam-utils" +version = "0.8.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" + +[[package]] +name = "dashmap" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf" +dependencies = [ + "cfg-if", + "crossbeam-utils", + "hashbrown 0.14.5", + "lock_api", + "once_cell", + "parking_lot_core", +] + +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "encoding_rs" +version = "0.8.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "fastrand" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" + +[[package]] +name = "find-msvc-tools" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "getrandom" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", + "wasip3", +] + +[[package]] +name = "h2" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f44da3a8150a6703ed5d34e164b875fd14c2cdab9af1252a9a1020bde2bdc54" +dependencies = [ + "atomic-waker", + "bytes", + "fnv", + "futures-core", + "futures-sink", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "http" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ba2a386d7f85a81f119ad7498ebe444d2e22c2af0b86b069416ace48b3311a" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "httpdate" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" + +[[package]] +name = "hyper" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ab2d4f250c3d7b1c9fcdff1cece94ea4e2dfbec68614f7b87cb205f24ca9d11" +dependencies = [ + "atomic-waker", + "bytes", + "futures-channel", + "futures-core", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "pin-utils", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3c93eb611681b207e1fe55d5a71ecf91572ec8a6705cdb6857f7d8d5242cf58" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "rustls-pki-types", + "tokio", + "tokio-rustls", + "tower-service", +] + +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + +[[package]] +name = "hyper-util" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96547c2556ec9d12fb1578c4eaf448b04993e7fb79cbaad930a656880a6bdfa0" +dependencies = [ + "base64", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "system-configuration", + "tokio", + "tower-service", + "tracing", + "windows-registry", +] + +[[package]] +name = "icu_collections" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" +dependencies = [ + "displaydoc", + "potential_utf", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" + +[[package]] +name = "icu_properties" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "020bfc02fe870ec3a66d93e677ccca0562506e5872c650f893269e08615d74ec" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "616c294cf8d725c6afcd8f55abc17c56464ef6211f9ed59cccffe534129c77af" + +[[package]] +name = "icu_provider" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7714e70437a7dc3ac8eb7e6f8df75fd8eb422675fc7678aff7364301092b1017" +dependencies = [ + "equivalent", + "hashbrown 0.16.1", + "serde", + "serde_core", +] + +[[package]] +name = "ipnet" +version = "2.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" + +[[package]] +name = "iri-string" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c91338f0783edbd6195decb37bae672fd3b165faffb89bf7b9e6942f8b1a731a" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "itoa" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2" + +[[package]] +name = "js-sys" +version = "0.3.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7e709f3e3d22866f9c25b3aff01af289b18422cc8b4262fb19103ee80fe513d" +dependencies = [ + "once_cell", + "wasm-bindgen", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "libc" +version = "0.2.182" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6800badb6cb2082ffd7b6a67e6125bb39f18782f793520caee8cb8846be06112" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "matchers" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1525a2a28c7f4fa0fc98bb91ae755d1e2d1505079e05539e35bc876b5d65ae9" +dependencies = [ + "regex-automata", +] + +[[package]] +name = "matchit" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47e1ffaa40ddd1f3ed91f717a33c8c0ee23fff369e3aa8772b9605cc1d22f4c3" + +[[package]] +name = "mcp-gateway" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum", + "clap", + "dashmap", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "toml", + "tower-http", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mime" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" + +[[package]] +name = "mio" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a69bcab0ad47271a0234d9422b131806bf3968021e5dc9328caf2d4cd58557fc" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "native-tls" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "465500e14ea162429d264d44189adc38b199b62b1c21eea9f69e4b73cb03bbf2" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "once_cell" +version = "1.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "openssl" +version = "0.10.75" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08838db121398ad17ab8531ce9de97b244589089e290a384c900cb9ff7434328" +dependencies = [ + "bitflags", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c87def4c32ab89d880effc9e097653c8da5d6ef28e6b539d313baaacfbafcbe" + +[[package]] +name = "openssl-sys" +version = "0.9.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82cab2d520aa75e3c58898289429321eb788c3106963d0dc886ec7a5f4adc321" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" + +[[package]] +name = "potential_utf" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" +dependencies = [ + "zerovec", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b2ebcf727b7760c461f091f9f0f539b77b8e87f2fd88131e7f1b433b3cece4" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "regex-automata" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e1dd4122fc1595e8162618945476892eefca7b88c52820e74af6262213cae8f" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a96887878f22d7bad8a3b6dc5b7440e0ada9a245242924394987b21cf2210a4c" + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64", + "bytes", + "encoding_rs", + "futures-core", + "h2", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "js-sys", + "log", + "mime", + "native-tls", + "percent-encoding", + "pin-project-lite", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-native-tls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + +[[package]] +name = "rustix" +version = "1.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c665f33d38cea657d9614f766881e4d510e0eda4239891eea56b4cadcf01801b" +dependencies = [ + "once_cell", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be040f8b0a225e40375822a563fa9524378b9d63112f53e19ffff34df5d33fdd" +dependencies = [ + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7df23109aa6c1567d1c575b9952556388da57401e4ace1d15f79eedad0d8f53" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", +] + +[[package]] +name = "rustversion" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" + +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + +[[package]] +name = "schannel" +version = "0.1.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891d81b926048e76efe18581bf793546b4c0eaf8448d72be8de2bbee5fd166e1" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "security-framework" +version = "3.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7f4bc775c73d9a02cde8bf7b2ec4c9d12743edf609006c7facc23998404cd1d" +dependencies = [ + "bitflags", + "core-foundation 0.10.1", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2691df843ecc5d231c0b14ece2acc3efb62c0a398c7e1d875f3983ce020e3" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_path_to_error" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a9ff822e371bb5403e391ecd83e182e0e77ba7f6fe0160b795797109d1b457" +dependencies = [ + "itoa", + "serde", + "serde_core", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f4aa3ad99f2088c990dfa82d367e19cb29268ed67c574d10d0a4bfe71f07e0" +dependencies = [ + "libc", + "windows-sys 0.60.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "system-configuration" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a13f3d0daba03132c0aa9767f98351b3488edc2c100cda2d2ec2b04f3d8d3c8b" +dependencies = [ + "bitflags", + "core-foundation 0.9.4", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e1d1b10ced5ca923a1fcb8d03e96b8d3268065d724548c0211415ff6ac6bac4" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "tempfile" +version = "3.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0136791f7c95b1f6dd99f9cc786b91bb81c3800b639b3478e561ddb7be95e5f1" +dependencies = [ + "fastrand", + "getrandom 0.4.1", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "thiserror" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tinystr" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.49.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72a2903cd7736441aac9df9d7688bd0ce48edccaadf181c3b90be801e81d3d86" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-macros" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af407857209536a95c8e56f8231ef2c2e2aff839b22e07a1ffcbc617e9db9fa5" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1729aa945f29d91ba541258c8df89027d5792d85a8841fb65e8bf0f4ede4ef61" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" +dependencies = [ + "indexmap", + "serde", + "serde_spanned", + "toml_datetime", + "toml_write", + "winnow", +] + +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-http" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4e6559d53cc268e5031cd8429d05415bc4cb4aefc4aa5d6cc35fbf5b924a1f8" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "iri-string", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "tracing", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "log", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f30143827ddab0d256fd843b7a66d164e9f271cfa0dde49142c5ca0ca291f1e" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex-automata", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "want" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.2+wasi-0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9517f9239f02c069db75e65f174b3da828fe5f5b945c4dd26bd25d89c03ebcf5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec1adf1535672f5b7824f817792b1afd731d7e843d2d04ec8f27e8cb51edd8ac" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.61" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe88540d1c934c4ec8e6db0afa536876c5441289d7f9f9123d4f065ac1250a6b" +dependencies = [ + "cfg-if", + "futures-util", + "js-sys", + "once_cell", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e638317c08b21663aed4d2b9a2091450548954695ff4efa75bff5fa546b3b1" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c64760850114d03d5f65457e96fc988f11f01d38fbaa51b254e4ab5809102af" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.111" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60eecd4fe26177cfa3339eb00b4a36445889ba3ad37080c2429879718e20ca41" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "web-sys" +version = "0.3.88" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d6bb20ed2d9572df8584f6dc81d68a41a625cadc6f15999d649a70ce7e3597a" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-registry" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02752bf7fbdcce7f2a27a742f798510f3e5ad88dbe84871e5168e2120c3d5720" +dependencies = [ + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.5", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.1", + "windows_aarch64_msvc 0.53.1", + "windows_i686_gnu 0.53.1", + "windows_i686_gnullvm 0.53.1", + "windows_i686_msvc 0.53.1", + "windows_x86_64_gnu 0.53.1", + "windows_x86_64_gnullvm 0.53.1", + "windows_x86_64_msvc 0.53.1", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "winnow" +version = "0.7.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +dependencies = [ + "memchr", +] + +[[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" + +[[package]] +name = "yoke" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50cc42e0333e05660c3587f3bf9d0478688e15d870fab3346451ce7f8c9fbea5" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71e5d6e06ab090c67b5e44993ec16b72dcbaabc526db883a360057678b48502" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b97154e67e32c85465826e8bcc1c59429aaaf107c1e4a9e53c8d8ccd5eff88d0" + +[[package]] +name = "zerotrie" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/mcp-gateway/Cargo.toml b/mcp-gateway/Cargo.toml new file mode 100644 index 0000000..0752477 --- /dev/null +++ b/mcp-gateway/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "mcp-gateway" +version = "0.1.0" +edition = "2021" + +[[bin]] +name = "mcp-gateway" +path = "src/main.rs" + +[dependencies] +tokio = { version = "1", features = ["macros", "rt-multi-thread", "signal", "time", "sync"] } +axum = { version = "0.8", features = ["macros"] } +tower-http = { version = "0.6", features = ["cors", "trace"] } +reqwest = { version = "0.12", features = ["json"] } +serde = { version = "1", features = ["derive"] } +serde_json = "1" +toml = "0.8" +tracing = "0.1" +tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] } +clap = { version = "4", features = ["derive", "env"] } +dashmap = "6" +thiserror = "2" +anyhow = "1" diff --git a/mcp-gateway/README.md b/mcp-gateway/README.md new file mode 100644 index 0000000..e586d0c --- /dev/null +++ b/mcp-gateway/README.md @@ -0,0 +1,140 @@ +# mcp-gateway + +`mcp-gateway` is a small MCP aggregation service written in Rust. It connects to multiple upstream MCP servers at startup, caches their advertised tools, resources, and prompts, and exposes a single `/mcp` endpoint that forwards supported JSON-RPC requests to the correct upstream. + +## What it does + +- Performs the MCP handshake against each configured upstream on startup. +- Caches `tools/list`, `resources/list`, and `prompts/list` results. +- Exposes a single gateway endpoint for clients. +- Namespaces tool and prompt names as `{upstream}__{name}` to avoid collisions. +- Routes resource reads by matching the requested resource URI to the upstream that advertised it. + +## Architecture + +```mermaid +flowchart LR + C["MCP Client"] -->|JSON-RPC over HTTP| G["mcp-gateway\nAxum router"] + G --> H["POST /mcp handler"] + G --> K["GET /health"] + + H --> A["Aggregator / Dispatcher"] + H --> I["Initialize response"] + + A --> R["Upstream registry"] + R --> U1["UpstreamClient: time_server"] + R --> U2["UpstreamClient: calculator"] + U1 --> S1["MCP upstream server"] + U2 --> S2["MCP upstream server"] + + S1 -. startup handshake .-> U1 + S2 -. startup handshake .-> U2 + U1 -. cache tools/resources/prompts .-> R + U2 -. cache tools/resources/prompts .-> R + + A -->|tools/list, resources/list, prompts/list| R + A -->|tools/call| U1 + A -->|tools/call| U2 + A -->|resources/read by URI| U1 + A -->|resources/read by URI| U2 + A -->|prompts/get| U1 + A -->|prompts/get| U2 +``` + +## Endpoints + +- `POST /mcp`: MCP JSON-RPC endpoint. +- `GET /health`: returns `{"status":"ok"}`. + +## Supported MCP methods + +The gateway currently handles these methods: + +- `initialize` +- `notifications/initialized` +- `ping` +- `tools/list` +- `tools/call` +- `resources/list` +- `resources/read` +- `prompts/list` +- `prompts/get` + +Requests for other methods return JSON-RPC error `-32601` (`method not found`). + +## Configuration + +By default the binary reads `config.toml` from the project root. You can override this with `--config` or `MCP_GATEWAY_CONFIG`. + +Example: + +```toml +[gateway] +host = "0.0.0.0" +port = 3000 +log_level = "info" + +[[upstreams]] +name = "time_server" +url = "http://127.0.0.1:9080/mcp" + +[[upstreams]] +name = "calculator" +url = "http://127.0.0.1:9081/mcp" +``` + +Each upstream needs: + +- `name`: namespace prefix used for tools and prompts. +- `url`: HTTP MCP endpoint for that upstream. + +## Running + +Start the gateway: + +```bash +cargo run +``` + +Use a different config file: + +```bash +cargo run -- --config ./config.toml +``` + +Or: + +```bash +MCP_GATEWAY_CONFIG=./config.toml cargo run +``` + +The server listens on the configured `host` and `port`. + +## Request routing + +### Initialization + +The gateway responds to `initialize` directly and reports aggregated capabilities for tools, resources, and prompts. + +### Tools + +- `tools/list` returns the combined tool list from all upstreams. +- Tool names are rewritten to `{upstream}__{tool}`. +- `tools/call` expects the namespaced tool name, strips the prefix, and forwards the request to the matching upstream. + +### Resources + +- `resources/list` returns the combined resource list from all upstreams. +- `resources/read` forwards the request to the upstream that advertised the requested resource URI. + +### Prompts + +- `prompts/list` returns the combined prompt list from all upstreams. +- Prompt names are rewritten to `{upstream}__{prompt}`. +- `prompts/get` expects the namespaced prompt name, strips the prefix, and forwards the request upstream. + +## Notes + +- Upstream initialization is eager: if any configured upstream fails during startup, the gateway exits with an error. +- Capability lists are cached at startup; this implementation does not refresh them dynamically. +- CORS is configured as permissive. diff --git a/mcp-gateway/config.toml b/mcp-gateway/config.toml new file mode 100644 index 0000000..268b5bb --- /dev/null +++ b/mcp-gateway/config.toml @@ -0,0 +1,12 @@ +[gateway] +host = "0.0.0.0" +port = 3000 +log_level = "info" + +[[upstreams]] +name = "time_server" +url = "http://127.0.0.1:9080/mcp" + +[[upstreams]] +name = "calculator" +url = "http://127.0.0.1:9081/mcp" diff --git a/mcp-gateway/src/config.rs b/mcp-gateway/src/config.rs new file mode 100644 index 0000000..f605233 --- /dev/null +++ b/mcp-gateway/src/config.rs @@ -0,0 +1,46 @@ +use serde::Deserialize; + +#[derive(Debug, Clone, Deserialize)] +pub struct GatewayConfig { + pub gateway: GatewaySettings, + #[serde(default)] + pub upstreams: Vec, +} + +#[derive(Debug, Clone, Deserialize)] +pub struct GatewaySettings { + #[serde(default = "default_host")] + pub host: String, + #[serde(default = "default_port")] + pub port: u16, + #[serde(default = "default_log_level")] + pub log_level: String, +} + +fn default_host() -> String { + "0.0.0.0".into() +} + +fn default_port() -> u16 { + 3000 +} + +fn default_log_level() -> String { + "info".into() +} + +#[derive(Debug, Clone, Deserialize)] +pub struct UpstreamConfig { + pub name: String, + pub url: String, +} + +impl GatewayConfig { + pub fn from_file(path: &str) -> anyhow::Result { + let contents = std::fs::read_to_string(path) + .map_err(|e| anyhow::anyhow!("failed to read config file '{}': {}", path, e))?; + let config: GatewayConfig = toml::from_str(&contents) + .map_err(|e| anyhow::anyhow!("failed to parse config file '{}': {}", path, e))?; + Ok(config) + } +} diff --git a/mcp-gateway/src/error.rs b/mcp-gateway/src/error.rs new file mode 100644 index 0000000..4d191b6 --- /dev/null +++ b/mcp-gateway/src/error.rs @@ -0,0 +1,22 @@ +use thiserror::Error; + +use crate::protocol::types::JsonRpcResponse; +use serde_json::Value; + +#[derive(Debug, Error)] +pub enum GatewayError { + #[error("upstream error: {0}")] + Upstream(#[from] anyhow::Error), + + #[error("bad request: {0}")] + BadRequest(String), +} + +impl GatewayError { + pub fn into_jsonrpc(self, id: Option) -> JsonRpcResponse { + match self { + GatewayError::BadRequest(message) => JsonRpcResponse::err(id, -32602, message), + GatewayError::Upstream(error) => JsonRpcResponse::err(id, -32603, error.to_string()), + } + } +} diff --git a/mcp-gateway/src/gateway/aggregator.rs b/mcp-gateway/src/gateway/aggregator.rs new file mode 100644 index 0000000..8efb288 --- /dev/null +++ b/mcp-gateway/src/gateway/aggregator.rs @@ -0,0 +1,150 @@ +use serde_json::{json, Value}; + +use crate::{ + error::GatewayError, + protocol::types::{JsonRpcRequest, JsonRpcResponse, ToolCallParams, ResourceReadParams, PromptGetParams}, + upstream::registry::UpstreamRegistry, +}; + +/// Dispatch an inbound JSON-RPC request to the appropriate handler. +pub async fn dispatch( + registry: &UpstreamRegistry, + req: &JsonRpcRequest, +) -> Result { + match req.method.as_str() { + "tools/list" => tools_list(registry, req.id.clone()).await, + "tools/call" => tools_call(registry, req.id.clone(), req.params.clone()).await, + "resources/list" => resources_list(registry, req.id.clone()).await, + "resources/read" => resources_read(registry, req.id.clone(), req.params.clone()).await, + "prompts/list" => prompts_list(registry, req.id.clone()).await, + "prompts/get" => prompts_get(registry, req.id.clone(), req.params.clone()).await, + "ping" => Ok(JsonRpcResponse::ok(req.id.clone(), json!({}))), + _ => Ok(JsonRpcResponse::err( + req.id.clone(), + -32601, + format!("method not found: {}", req.method), + )), + } +} + +async fn tools_list( + registry: &UpstreamRegistry, + id: Option, +) -> Result { + let tools = registry.all_tools().await; + Ok(JsonRpcResponse::ok(id, json!({ "tools": tools }))) +} + +async fn tools_call( + registry: &UpstreamRegistry, + id: Option, + params: Option, +) -> Result { + let params_val = params.ok_or_else(|| GatewayError::BadRequest("tools/call requires params".into()))?; + let call_params: ToolCallParams = serde_json::from_value(params_val.clone()) + .map_err(|e| GatewayError::BadRequest(format!("invalid tools/call params: {}", e)))?; + + let (client, original_name) = registry + .client_for_tool(&call_params.name) + .ok_or_else(|| { + GatewayError::BadRequest(format!("unknown tool prefix in '{}'", call_params.name)) + })?; + + // Rewrite params with original (un-prefixed) tool name + let upstream_params = json!({ + "name": original_name, + "arguments": call_params.arguments + }); + + let resp = client + .forward("tools/call", Some(upstream_params), id.clone()) + .await + .map_err(GatewayError::Upstream)?; + + forward_response(id, resp) +} + +async fn resources_list( + registry: &UpstreamRegistry, + id: Option, +) -> Result { + let resources = registry.all_resources().await; + Ok(JsonRpcResponse::ok(id, json!({ "resources": resources }))) +} + +async fn resources_read( + registry: &UpstreamRegistry, + id: Option, + params: Option, +) -> Result { + let params_val = params.ok_or_else(|| GatewayError::BadRequest("resources/read requires params".into()))?; + let read_params: ResourceReadParams = serde_json::from_value(params_val.clone()) + .map_err(|e| GatewayError::BadRequest(format!("invalid resources/read params: {}", e)))?; + + let client = registry + .client_for_resource(&read_params.uri) + .await + .ok_or_else(|| { + GatewayError::BadRequest(format!("unknown resource URI '{}'", read_params.uri)) + })?; + + let resp = client + .forward("resources/read", Some(params_val), id.clone()) + .await + .map_err(GatewayError::Upstream)?; + + forward_response(id, resp) +} + +async fn prompts_list( + registry: &UpstreamRegistry, + id: Option, +) -> Result { + let prompts = registry.all_prompts().await; + Ok(JsonRpcResponse::ok(id, json!({ "prompts": prompts }))) +} + +async fn prompts_get( + registry: &UpstreamRegistry, + id: Option, + params: Option, +) -> Result { + let params_val = params.ok_or_else(|| GatewayError::BadRequest("prompts/get requires params".into()))?; + let get_params: PromptGetParams = serde_json::from_value(params_val.clone()) + .map_err(|e| GatewayError::BadRequest(format!("invalid prompts/get params: {}", e)))?; + + let (client, original_name) = registry + .client_for_prompt(&get_params.name) + .ok_or_else(|| { + GatewayError::BadRequest(format!("unknown prompt prefix in '{}'", get_params.name)) + })?; + + // Rewrite params with original (un-prefixed) prompt name + let upstream_params = json!({ + "name": original_name, + "arguments": get_params.arguments + }); + + let resp = client + .forward("prompts/get", Some(upstream_params), id.clone()) + .await + .map_err(GatewayError::Upstream)?; + + forward_response(id, resp) +} + +fn forward_response(id: Option, upstream: Value) -> Result { + if let Some(result) = upstream.get("result") { + return Ok(JsonRpcResponse::ok(id, result.clone())); + } + if let Some(error) = upstream.get("error") { + let code = error.get("code").and_then(Value::as_i64).unwrap_or(-32603); + let message = error + .get("message") + .and_then(Value::as_str) + .unwrap_or("upstream error") + .to_string(); + return Ok(JsonRpcResponse::err(id, code, message)); + } + Ok(JsonRpcResponse::err(id, -32603, "upstream returned invalid response")) +} diff --git a/mcp-gateway/src/gateway/handlers.rs b/mcp-gateway/src/gateway/handlers.rs new file mode 100644 index 0000000..b7b65c7 --- /dev/null +++ b/mcp-gateway/src/gateway/handlers.rs @@ -0,0 +1,110 @@ +use axum::{ + extract::State, + http::StatusCode, + response::{IntoResponse, Response}, + Json, +}; +use serde_json::json; +use tracing::debug; + +use crate::{ + error::GatewayError, + gateway::{aggregator, state::GatewayState}, + protocol::types::{ + InitializeResult, JsonRpcRequest, JsonRpcResponse, PromptsCapability, ResourcesCapability, + ServerCapabilities, ServerInfo, ToolsCapability, + }, +}; + +/// `POST /mcp` +pub async fn handle_post( + State(state): State, + Json(req): Json, +) -> Response { + debug!(method = %req.method, id = ?req.id, "POST /mcp"); + + if req.method == "initialize" { + let result = InitializeResult { + protocol_version: "2025-06-18".into(), + capabilities: ServerCapabilities { + tools: Some(ToolsCapability { + list_changed: Some(false), + }), + resources: Some(ResourcesCapability { + list_changed: Some(false), + subscribe: Some(false), + }), + prompts: Some(PromptsCapability { + list_changed: Some(false), + }), + }, + server_info: ServerInfo { + name: "mcp-gateway".into(), + version: env!("CARGO_PKG_VERSION").into(), + }, + }; + + let rpc_resp = match serde_json::to_value(&result) { + Ok(value) => JsonRpcResponse::ok(req.id.clone(), value), + Err(error) => GatewayError::Upstream(error.into()).into_jsonrpc(req.id.clone()), + }; + return (StatusCode::OK, Json(rpc_resp)).into_response(); + } + + if req.method == "notifications/initialized" && req.id.is_none() { + debug!("notifications/initialized → 202"); + return StatusCode::ACCEPTED.into_response(); + } + + let rpc_resp = match aggregator::dispatch(&state.registry, &req).await { + Ok(response) => response, + Err(error) => error.into_jsonrpc(req.id.clone()), + }; + (StatusCode::OK, Json(rpc_resp)).into_response() +} + +/// `GET /health` +pub async fn handle_health() -> impl IntoResponse { + Json(json!({ "status": "ok" })) +} + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use axum::{body::to_bytes, http::StatusCode, Json}; + use serde_json::{json, Value}; + + use super::handle_post; + use crate::{ + gateway::state::GatewayState, + protocol::types::JsonRpcRequest, + upstream::registry::UpstreamRegistry, + }; + + #[tokio::test] + async fn bad_request_is_returned_as_jsonrpc_error() { + let state = GatewayState::new(Arc::new(UpstreamRegistry::new())); + let request = JsonRpcRequest { + jsonrpc: "2.0".into(), + id: Some(json!(7)), + method: "tools/call".into(), + params: Some(json!({ "name": "missing__tool", "arguments": {} })), + }; + + let response = handle_post(axum::extract::State(state), Json(request)).await; + + assert_eq!(response.status(), StatusCode::OK); + + let body = to_bytes(response.into_body(), usize::MAX).await.unwrap(); + let payload: Value = serde_json::from_slice(&body).unwrap(); + + assert_eq!(payload["jsonrpc"], "2.0"); + assert_eq!(payload["id"], 7); + assert_eq!(payload["error"]["code"], -32602); + assert!(payload["error"]["message"] + .as_str() + .unwrap() + .contains("unknown tool prefix")); + } +} diff --git a/mcp-gateway/src/gateway/mod.rs b/mcp-gateway/src/gateway/mod.rs new file mode 100644 index 0000000..5a36594 --- /dev/null +++ b/mcp-gateway/src/gateway/mod.rs @@ -0,0 +1,4 @@ +pub mod aggregator; +pub mod handlers; +pub mod router; +pub mod state; diff --git a/mcp-gateway/src/gateway/router.rs b/mcp-gateway/src/gateway/router.rs new file mode 100644 index 0000000..8e7c162 --- /dev/null +++ b/mcp-gateway/src/gateway/router.rs @@ -0,0 +1,19 @@ +use axum::{ + routing::{get, post}, + Router, +}; +use tower_http::{cors::CorsLayer, trace::TraceLayer}; + +use crate::gateway::{ + handlers::{handle_health, handle_post}, + state::GatewayState, +}; + +pub fn build_router(state: GatewayState) -> Router { + Router::new() + .route("/mcp", post(handle_post)) + .route("/health", get(handle_health)) + .layer(TraceLayer::new_for_http()) + .layer(CorsLayer::permissive()) + .with_state(state) +} diff --git a/mcp-gateway/src/gateway/state.rs b/mcp-gateway/src/gateway/state.rs new file mode 100644 index 0000000..93a0a22 --- /dev/null +++ b/mcp-gateway/src/gateway/state.rs @@ -0,0 +1,14 @@ +use std::sync::Arc; + +use crate::upstream::registry::UpstreamRegistry; + +#[derive(Clone)] +pub struct GatewayState { + pub registry: Arc, +} + +impl GatewayState { + pub fn new(registry: Arc) -> Self { + Self { registry } + } +} diff --git a/mcp-gateway/src/main.rs b/mcp-gateway/src/main.rs new file mode 100644 index 0000000..374411b --- /dev/null +++ b/mcp-gateway/src/main.rs @@ -0,0 +1,66 @@ +use std::net::SocketAddr; + +use clap::Parser; +use tracing::info; + +mod config; +mod error; +mod gateway; +mod protocol; +mod telemetry; +mod upstream; + +use config::GatewayConfig; +use gateway::{router::build_router, state::GatewayState}; +use upstream::registry::UpstreamRegistry; + +#[derive(Parser, Debug)] +#[command(name = "mcp-gateway", about = "MCP aggregator gateway")] +struct Cli { + /// Path to config file + #[arg(short, long, env = "MCP_GATEWAY_CONFIG", default_value = "config.toml")] + config: String, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + let cli = Cli::parse(); + let cfg = GatewayConfig::from_file(&cli.config)?; + + telemetry::init(&cfg.gateway.log_level); + + info!( + host = %cfg.gateway.host, + port = cfg.gateway.port, + upstreams = cfg.upstreams.len(), + "mcp-gateway starting" + ); + + // Connect to all upstreams and build capability cache + let registry = UpstreamRegistry::connect_all(&cfg.upstreams).await?; + + let state = GatewayState::new(registry); + let router = build_router(state); + + let addr: SocketAddr = format!("{}:{}", cfg.gateway.host, cfg.gateway.port) + .parse() + .map_err(|e| anyhow::anyhow!("invalid address: {}", e))?; + + info!(%addr, "listening"); + + let listener = tokio::net::TcpListener::bind(addr).await?; + + axum::serve(listener, router) + .with_graceful_shutdown(shutdown_signal()) + .await?; + + info!("mcp-gateway stopped"); + Ok(()) +} + +async fn shutdown_signal() { + tokio::signal::ctrl_c() + .await + .expect("failed to install Ctrl+C handler"); + info!("shutdown signal received"); +} diff --git a/mcp-gateway/src/protocol/mod.rs b/mcp-gateway/src/protocol/mod.rs new file mode 100644 index 0000000..cd40856 --- /dev/null +++ b/mcp-gateway/src/protocol/mod.rs @@ -0,0 +1 @@ +pub mod types; diff --git a/mcp-gateway/src/protocol/types.rs b/mcp-gateway/src/protocol/types.rs new file mode 100644 index 0000000..6d2511e --- /dev/null +++ b/mcp-gateway/src/protocol/types.rs @@ -0,0 +1,258 @@ +#![allow(dead_code)] + +use serde::{Deserialize, Serialize}; +use serde_json::Value; + +// --------------------------------------------------------------------------- +// JSON-RPC 2.0 wire types +// --------------------------------------------------------------------------- + +#[derive(Debug, Clone, Deserialize, Serialize)] +pub struct JsonRpcRequest { + pub jsonrpc: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub id: Option, + pub method: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub params: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct JsonRpcResponse { + pub jsonrpc: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub id: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub result: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub error: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct JsonRpcError { + pub code: i64, + pub message: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub data: Option, +} + +impl JsonRpcResponse { + pub fn ok(id: Option, result: Value) -> Self { + Self { + jsonrpc: "2.0".into(), + id, + result: Some(result), + error: None, + } + } + + pub fn err(id: Option, code: i64, message: impl Into) -> Self { + Self { + jsonrpc: "2.0".into(), + id, + result: None, + error: Some(JsonRpcError { + code, + message: message.into(), + data: None, + }), + } + } +} + +// --------------------------------------------------------------------------- +// MCP protocol types +// --------------------------------------------------------------------------- + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct InitializeParams { + pub protocol_version: String, + pub capabilities: Value, + pub client_info: ClientInfo, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ClientInfo { + pub name: String, + pub version: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct InitializeResult { + pub protocol_version: String, + pub capabilities: ServerCapabilities, + pub server_info: ServerInfo, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ServerInfo { + pub name: String, + pub version: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct ServerCapabilities { + #[serde(skip_serializing_if = "Option::is_none")] + pub tools: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub resources: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub prompts: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct ToolsCapability { + #[serde(skip_serializing_if = "Option::is_none")] + pub list_changed: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct ResourcesCapability { + #[serde(skip_serializing_if = "Option::is_none")] + pub list_changed: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub subscribe: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +#[serde(rename_all = "camelCase")] +pub struct PromptsCapability { + #[serde(skip_serializing_if = "Option::is_none")] + pub list_changed: Option, +} + +// --------------------------------------------------------------------------- +// Tool types +// --------------------------------------------------------------------------- + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Tool { + pub name: String, + pub description: Option, + pub input_schema: Value, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ToolsListResult { + pub tools: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ToolCallParams { + pub name: String, + #[serde(default)] + pub arguments: Value, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ToolCallResult { + pub content: Vec, + #[serde(skip_serializing_if = "Option::is_none")] + pub is_error: Option, +} + +// --------------------------------------------------------------------------- +// Resource types +// --------------------------------------------------------------------------- + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct Resource { + pub uri: String, + pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub mime_type: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ResourcesListResult { + pub resources: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ResourceReadParams { + pub uri: String, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ResourceReadResult { + pub contents: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct ResourceContent { + pub uri: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub mime_type: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub text: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub blob: Option, +} + +// --------------------------------------------------------------------------- +// Prompt types +// --------------------------------------------------------------------------- + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct Prompt { + pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub arguments: Option>, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PromptArgument { + pub name: String, + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub required: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PromptsListResult { + pub prompts: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PromptGetParams { + pub name: String, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub arguments: Option, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PromptGetResult { + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option, + pub messages: Vec, +} + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PromptMessage { + pub role: String, + pub content: ContentItem, +} + +// --------------------------------------------------------------------------- +// Shared content type +// --------------------------------------------------------------------------- + +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(tag = "type", rename_all = "camelCase")] +pub enum ContentItem { + Text { text: String }, + Image { data: String, mime_type: String }, + Resource { resource: ResourceContent }, +} diff --git a/mcp-gateway/src/telemetry.rs b/mcp-gateway/src/telemetry.rs new file mode 100644 index 0000000..fe888ef --- /dev/null +++ b/mcp-gateway/src/telemetry.rs @@ -0,0 +1,12 @@ +use tracing_subscriber::{fmt, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter}; + +pub fn init(log_level: &str) { + let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| { + EnvFilter::new(format!("mcp_gateway={log_level},tower_http=debug")) + }); + + tracing_subscriber::registry() + .with(filter) + .with(fmt::layer()) + .init(); +} diff --git a/mcp-gateway/src/upstream/client.rs b/mcp-gateway/src/upstream/client.rs new file mode 100644 index 0000000..797e608 --- /dev/null +++ b/mcp-gateway/src/upstream/client.rs @@ -0,0 +1,248 @@ +use std::sync::Arc; + +use anyhow::{anyhow, Context}; +use reqwest::{header, Client}; +use serde_json::{json, Value}; +use tokio::sync::RwLock; +use tracing::{debug, info, warn}; + +use crate::protocol::types::{ + Prompt, PromptsListResult, Resource, ResourcesListResult, Tool, ToolsListResult, +}; + +static PROTOCOL_VERSION: &str = "2025-06-18"; + +pub struct UpstreamClient { + pub name: String, + url: String, + http: Client, + // Capability cache + pub tools: Arc>>, + pub resources: Arc>>, + pub prompts: Arc>>, +} + +impl UpstreamClient { + pub fn new(name: String, url: String) -> Self { + let http = Client::builder() + .build() + .expect("failed to build reqwest client"); + Self { + name, + url, + http, + tools: Arc::new(RwLock::new(Vec::new())), + resources: Arc::new(RwLock::new(Vec::new())), + prompts: Arc::new(RwLock::new(Vec::new())), + } + } + + /// Full MCP handshake and capability fetch. Called once at startup. + pub async fn initialize_and_cache(&self) -> anyhow::Result<()> { + info!(upstream = %self.name, "initializing"); + + self.handshake().await.context("initialize handshake")?; + self.send_initialized_notification().await.context("notifications/initialized")?; + let tools = self.fetch_tools().await.context("tools/list")?; + let resources = self.fetch_resources().await.context("resources/list")?; + let prompts = self.fetch_prompts().await.context("prompts/list")?; + + info!( + upstream = %self.name, + tools = tools.len(), + resources = resources.len(), + prompts = prompts.len(), + "initialized" + ); + + *self.tools.write().await = tools; + *self.resources.write().await = resources; + *self.prompts.write().await = prompts; + + Ok(()) + } + + async fn handshake(&self) -> anyhow::Result<()> { + let request = json!({ + "jsonrpc": "2.0", + "id": 1, + "method": "initialize", + "params": { + "protocolVersion": PROTOCOL_VERSION, + "capabilities": {}, + "clientInfo": { + "name": "mcp-gateway", + "version": "0.1.0" + } + } + }); + + let resp = self + .http + .post(&self.url) + .header(header::CONTENT_TYPE, "application/json") + .header(header::ACCEPT, "application/json") + .header("MCP-Protocol-Version", PROTOCOL_VERSION) + .json(&request) + .send() + .await + .context("POST initialize")?; + let rpc_resp = self.parse_response(resp).await.context("parse initialize response")?; + if let Some(error) = rpc_resp.get("error") { + return Err(anyhow!("initialize error: {}", error)); + } + if rpc_resp.get("result").is_none() { + return Err(anyhow!("initialize response missing result")); + } + + Ok(()) + } + + async fn send_initialized_notification(&self) -> anyhow::Result<()> { + let notification = json!({ + "jsonrpc": "2.0", + "method": "notifications/initialized" + }); + + let resp = self.post_json(notification).await?; + + if resp.status() == reqwest::StatusCode::ACCEPTED || resp.status().is_success() { + debug!(upstream = %self.name, "notifications/initialized acknowledged"); + } else { + warn!( + upstream = %self.name, + status = %resp.status(), + "unexpected status for notifications/initialized" + ); + } + + Ok(()) + } + + async fn fetch_tools(&self) -> anyhow::Result> { + let req = self.build_request(2, "tools/list", None); + let resp = self.post_json(req).await?; + let rpc_resp = self.parse_response(resp).await?; + Self::parse_tools_list_response(&rpc_resp) + } + + async fn fetch_resources(&self) -> anyhow::Result> { + let req = self.build_request(3, "resources/list", None); + let resp = self.post_json(req).await?; + let rpc_resp = self.parse_response(resp).await?; + Self::parse_resources_list_response(&rpc_resp) + } + + async fn fetch_prompts(&self) -> anyhow::Result> { + let req = self.build_request(4, "prompts/list", None); + let resp = self.post_json(req).await?; + let rpc_resp = self.parse_response(resp).await?; + Self::parse_prompts_list_response(&rpc_resp) + } + + /// Forward a JSON-RPC request to the upstream and return the response Value. + pub async fn forward(&self, method: &str, params: Option, id: Option) -> anyhow::Result { + let req_id = id.unwrap_or(json!(null)); + let mut body = json!({ + "jsonrpc": "2.0", + "id": req_id, + "method": method + }); + if let Some(p) = params { + body["params"] = p; + } + + let resp = self.post_json(body).await?; + self.parse_response(resp).await + } + + fn build_request(&self, id: u64, method: &str, params: Option) -> Value { + let mut req = json!({ + "jsonrpc": "2.0", + "id": id, + "method": method + }); + if let Some(p) = params { + req["params"] = p; + } + req + } + + pub async fn post_json(&self, body: Value) -> anyhow::Result { + self + .http + .post(&self.url) + .header(header::CONTENT_TYPE, "application/json") + .header(header::ACCEPT, "application/json") + .header("MCP-Protocol-Version", PROTOCOL_VERSION) + .json(&body) + .send() + .await + .context("HTTP POST to upstream") + } + + async fn parse_response(&self, resp: reqwest::Response) -> anyhow::Result { + let val: Value = resp.json().await.context("parse JSON response")?; + Ok(val) + } + + fn parse_tools_list_response(rpc_resp: &Value) -> anyhow::Result> { + if let Some(result) = rpc_resp.get("result") { + let list: ToolsListResult = serde_json::from_value(result.clone()) + .context("deserialize tools/list result")?; + return Ok(list.tools); + } + if let Some(err) = rpc_resp.get("error") { + return Err(anyhow!("tools/list error: {}", err)); + } + Ok(vec![]) + } + + fn parse_resources_list_response(rpc_resp: &Value) -> anyhow::Result> { + if let Some(result) = rpc_resp.get("result") { + let list: ResourcesListResult = serde_json::from_value(result.clone()) + .context("deserialize resources/list result")?; + return Ok(list.resources); + } + if let Some(err) = rpc_resp.get("error") { + return Err(anyhow!("resources/list error: {}", err)); + } + Ok(vec![]) + } + + fn parse_prompts_list_response(rpc_resp: &Value) -> anyhow::Result> { + if let Some(result) = rpc_resp.get("result") { + let list: PromptsListResult = serde_json::from_value(result.clone()) + .context("deserialize prompts/list result")?; + return Ok(list.prompts); + } + if let Some(err) = rpc_resp.get("error") { + return Err(anyhow!("prompts/list error: {}", err)); + } + Ok(vec![]) + } +} + +#[cfg(test)] +mod tests { + use serde_json::json; + + use super::UpstreamClient; + + #[tokio::test] + async fn resources_list_error_is_not_silently_treated_as_empty() { + let error = UpstreamClient::parse_resources_list_response(&json!({ + "jsonrpc": "2.0", + "id": 3, + "error": { + "code": -32601, + "message": "resources/list not supported" + } + })) + .unwrap_err() + .to_string(); + + assert!(error.contains("resources/list")); + assert!(error.contains("not supported")); + } +} diff --git a/mcp-gateway/src/upstream/mod.rs b/mcp-gateway/src/upstream/mod.rs new file mode 100644 index 0000000..0f51386 --- /dev/null +++ b/mcp-gateway/src/upstream/mod.rs @@ -0,0 +1,2 @@ +pub mod client; +pub mod registry; diff --git a/mcp-gateway/src/upstream/registry.rs b/mcp-gateway/src/upstream/registry.rs new file mode 100644 index 0000000..1b16e86 --- /dev/null +++ b/mcp-gateway/src/upstream/registry.rs @@ -0,0 +1,190 @@ +use std::{collections::{HashMap, HashSet}, sync::Arc}; + +use anyhow::anyhow; +use dashmap::DashMap; +use tracing::error; + +use crate::{ + config::UpstreamConfig, + protocol::types::{Prompt, Resource, Tool}, + upstream::client::UpstreamClient, +}; + +pub struct UpstreamRegistry { + clients: DashMap>, +} + +impl UpstreamRegistry { + pub fn new() -> Self { + Self { + clients: DashMap::new(), + } + } + + /// Connect to all upstreams concurrently and cache their capabilities. + /// Any failure is fatal. + pub async fn connect_all(configs: &[UpstreamConfig]) -> anyhow::Result> { + let registry = Arc::new(Self::new()); + + let mut handles = Vec::new(); + for cfg in configs { + let client = Arc::new(UpstreamClient::new(cfg.name.clone(), cfg.url.clone())); + registry.clients.insert(cfg.name.clone(), client.clone()); + + let handle = tokio::spawn(async move { + client.initialize_and_cache().await + }); + handles.push((cfg.name.clone(), handle)); + } + + for (name, handle) in handles { + match handle.await { + Ok(Ok(())) => {} + Ok(Err(e)) => { + error!(upstream = %name, error = %e, "upstream initialization failed"); + return Err(anyhow!("upstream '{}' failed to initialize: {}", name, e)); + } + Err(e) => { + error!(upstream = %name, error = %e, "upstream task panicked"); + return Err(anyhow!("upstream '{}' task panicked: {}", name, e)); + } + } + } + + registry.validate_unique_resources().await?; + + Ok(registry) + } + + /// Returns all tools from all upstreams, prefixed as `{upstream}__{name}`. + pub async fn all_tools(&self) -> Vec { + let mut result = Vec::new(); + for entry in self.clients.iter() { + let prefix = entry.key().clone(); + let tools = entry.value().tools.read().await; + for tool in tools.iter() { + let mut t = tool.clone(); + t.name = format!("{}__{}", prefix, tool.name); + result.push(t); + } + } + result + } + + /// Returns all resources from all upstreams (URIs are assumed globally unique). + pub async fn all_resources(&self) -> Vec { + let mut result = Vec::new(); + for entry in self.clients.iter() { + let resources = entry.value().resources.read().await; + result.extend(resources.iter().cloned()); + } + result + } + + /// Returns all prompts from all upstreams, prefixed as `{upstream}__{name}`. + pub async fn all_prompts(&self) -> Vec { + let mut result = Vec::new(); + for entry in self.clients.iter() { + let prefix = entry.key().clone(); + let prompts = entry.value().prompts.read().await; + for prompt in prompts.iter() { + let mut p = prompt.clone(); + p.name = format!("{}__{}", prefix, prompt.name); + result.push(p); + } + } + result + } + + /// Find the client responsible for a namespaced tool name (`{prefix}__{tool}`). + pub fn client_for_tool(&self, namespaced: &str) -> Option<(Arc, String)> { + let (prefix, tool_name) = namespaced.split_once("__")?; + let client = self.clients.get(prefix)?.clone(); + Some((client, tool_name.to_string())) + } + + /// Find the client that owns a given resource URI. + pub async fn client_for_resource(&self, uri: &str) -> Option> { + for entry in self.clients.iter() { + let resources = entry.value().resources.read().await; + let uris: HashSet<&str> = resources.iter().map(|r| r.uri.as_str()).collect(); + if uris.contains(uri) { + return Some(entry.value().clone()); + } + } + None + } + + /// Find the client responsible for a namespaced prompt name (`{prefix}__{prompt}`). + pub fn client_for_prompt(&self, namespaced: &str) -> Option<(Arc, String)> { + let (prefix, prompt_name) = namespaced.split_once("__")?; + let client = self.clients.get(prefix)?.clone(); + Some((client, prompt_name.to_string())) + } + + async fn validate_unique_resources(&self) -> anyhow::Result<()> { + let mut owners = HashMap::new(); + + for entry in self.clients.iter() { + let upstream = entry.key().clone(); + let resources = entry.value().resources.read().await; + for resource in resources.iter() { + if let Some(existing) = owners.insert(resource.uri.clone(), upstream.clone()) { + return Err(anyhow!( + "resource URI '{}' is advertised by both '{}' and '{}'", + resource.uri, + existing, + upstream + )); + } + } + } + + Ok(()) + } +} + +impl Default for UpstreamRegistry { + fn default() -> Self { + Self::new() + } +} + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use super::UpstreamRegistry; + use crate::{ + protocol::types::Resource, + upstream::client::UpstreamClient, + }; + + #[tokio::test] + async fn duplicate_resource_uris_are_rejected() { + let registry = UpstreamRegistry::new(); + let left = Arc::new(UpstreamClient::new("left".into(), "http://left".into())); + let right = Arc::new(UpstreamClient::new("right".into(), "http://right".into())); + + *left.resources.write().await = vec![Resource { + uri: "file:///shared.txt".into(), + name: "shared".into(), + description: None, + mime_type: None, + }]; + *right.resources.write().await = vec![Resource { + uri: "file:///shared.txt".into(), + name: "shared".into(), + description: None, + mime_type: None, + }]; + + registry.clients.insert("left".into(), left); + registry.clients.insert("right".into(), right); + + let error = registry.validate_unique_resources().await.unwrap_err().to_string(); + assert!(error.contains("file:///shared.txt")); + assert!(error.contains("left")); + assert!(error.contains("right")); + } +}