You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iggy.apache.org by pi...@apache.org on 2025/07/21 20:37:38 UTC

(iggy) branch mcp updated (0a65de7a -> f79c940b)

This is an automated email from the ASF dual-hosted git repository.

piotr pushed a change to branch mcp
in repository https://gitbox.apache.org/repos/asf/iggy.git


    from 0a65de7a add stream and topic mcp tests
     new e9793916 add more mcp tests
     add ada8f6c4 fix(js): fix npm packaging (broke by adding examples/ changed dist root) (#2026)
     new f79c940b Merge branch 'master' into mcp

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 core/ai/mcp/src/service/mod.rs                     |  15 +-
 core/ai/mcp/src/service/requests.rs                |   2 +-
 core/integration/tests/mcp/mod.rs                  | 165 ++++++++++++++++++++-
 foreign/node/package.json                          |  13 +-
 .../{ => src}/examples/stream-file-to-topic.ts     |   2 +-
 .../{ => src}/examples/stream-topic-to-file.ts     |   4 +-
 foreign/node/{ => src}/examples/utils.ts           |   4 +-
 foreign/node/src/wire/client/client.utils.ts       |   2 +
 foreign/node/src/wire/stream/stream.utils.ts       |   3 +
 .../node/src/wire/topic/create-topic.command.ts    |   8 +-
 foreign/node/src/wire/topic/index.ts               |   1 +
 foreign/node/src/wire/topic/topic.utils.ts         |  11 +-
 .../node/src/wire/topic/update-topic.command.ts    |   8 +-
 foreign/node/src/wire/user/user.utils.ts           |   3 +
 foreign/node/tsconfig.json                         |   2 +-
 15 files changed, 205 insertions(+), 38 deletions(-)
 rename foreign/node/{ => src}/examples/stream-file-to-topic.ts (98%)
 rename foreign/node/{ => src}/examples/stream-topic-to-file.ts (97%)
 rename foreign/node/{ => src}/examples/utils.ts (94%)


(iggy) 01/02: add more mcp tests

Posted by pi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

piotr pushed a commit to branch mcp
in repository https://gitbox.apache.org/repos/asf/iggy.git

commit e979391676f64e2e421cda6c513fc0d86d507752
Author: spetz <pi...@gmail.com>
AuthorDate: Mon Jul 21 22:37:22 2025 +0200

    add more mcp tests
---
 core/ai/mcp/src/service/mod.rs      |  15 ++--
 core/ai/mcp/src/service/requests.rs |   2 +-
 core/integration/tests/mcp/mod.rs   | 165 ++++++++++++++++++++++++++++++++++--
 3 files changed, 169 insertions(+), 13 deletions(-)

diff --git a/core/ai/mcp/src/service/mod.rs b/core/ai/mcp/src/service/mod.rs
index f286f721..87c8252e 100644
--- a/core/ai/mcp/src/service/mod.rs
+++ b/core/ai/mcp/src/service/mod.rs
@@ -55,6 +55,12 @@ impl IggyService {
         }
     }
 
+    #[tool(description = "Ping")]
+    pub async fn ping(&self) -> Result<CallToolResult, ErrorData> {
+        self.permissions.ensure_read()?;
+        request(self.client.ping().await)
+    }
+
     #[tool(description = "Get stream")]
     pub async fn get_stream(
         &self,
@@ -418,7 +424,7 @@ impl IggyService {
     #[tool(description = "Get me")]
     pub async fn get_me(&self) -> Result<CallToolResult, ErrorData> {
         self.permissions.ensure_read()?;
-        request(self.client.get_stats().await)
+        request(self.client.get_me().await)
     }
 
     #[tool(description = "Get client")]
@@ -436,12 +442,6 @@ impl IggyService {
         request(self.client.get_clients().await)
     }
 
-    #[tool(description = "Ping")]
-    pub async fn ping(&self) -> Result<CallToolResult, ErrorData> {
-        self.permissions.ensure_read()?;
-        request(self.client.ping().await)
-    }
-
     #[tool(description = "Snapshot")]
     pub async fn snapshot(
         &self,
@@ -451,6 +451,7 @@ impl IggyService {
         let compression = compression.and_then(|c| c.parse().ok()).unwrap_or_default();
         let mut types = types
             .into_iter()
+            .flatten()
             .flat_map(|t| t.parse().ok())
             .collect::<Vec<_>>();
         if types.is_empty() {
diff --git a/core/ai/mcp/src/service/requests.rs b/core/ai/mcp/src/service/requests.rs
index 0f20d2ca..1a8aea5c 100644
--- a/core/ai/mcp/src/service/requests.rs
+++ b/core/ai/mcp/src/service/requests.rs
@@ -248,7 +248,7 @@ pub struct Snapshot {
     pub compression: Option<String>,
 
     #[schemars(description = "types")]
-    pub types: Vec<String>,
+    pub types: Option<Vec<String>>,
 }
 
 #[derive(Debug, Deserialize, JsonSchema)]
diff --git a/core/integration/tests/mcp/mod.rs b/core/integration/tests/mcp/mod.rs
index 84d395bb..389edeae 100644
--- a/core/integration/tests/mcp/mod.rs
+++ b/core/integration/tests/mcp/mod.rs
@@ -17,10 +17,11 @@
  */
 
 use iggy::prelude::{Client, DEFAULT_ROOT_PASSWORD, DEFAULT_ROOT_USERNAME, IggyClient};
-use iggy_binary_protocol::{MessageClient, StreamClient, TopicClient};
+use iggy_binary_protocol::{ConsumerGroupClient, MessageClient, StreamClient, TopicClient};
 use iggy_common::{
-    Identifier, IggyExpiry, IggyMessage, MaxTopicSize, Partitioning, Stream, StreamDetails, Topic,
-    TopicDetails,
+    ClientInfo, ClientInfoDetails, ConsumerGroup, ConsumerGroupDetails, Identifier, IggyExpiry,
+    IggyMessage, MaxTopicSize, Partitioning, PolledMessages, Snapshot, Stats, Stream,
+    StreamDetails, Topic, TopicDetails,
 };
 use integration::{
     test_mcp_server::{McpClient, TestMcpServer},
@@ -37,12 +38,15 @@ use rmcp::{
 const STREAM_NAME: &str = "test_stream";
 const TOPIC_NAME: &str = "test_topic";
 const MESSAGE_PAYLOAD: &str = "test_message";
+const CONSUMER_GROUP_NAME: &str = "test_consumer_group";
 
 lazy_static! {
     static ref STREAM_ID: Identifier =
         Identifier::from_str_value(STREAM_NAME).expect("Failed to create stream ID");
     static ref TOPIC_ID: Identifier =
         Identifier::from_str_value(TOPIC_NAME).expect("Failed to create topic ID");
+    static ref CONSUMER_GROUP_ID: Identifier =
+        Identifier::from_str_value(CONSUMER_GROUP_NAME).expect("Failed to create group ID");
 }
 
 #[tokio::test]
@@ -191,6 +195,144 @@ async fn mcp_server_should_purge_topic() {
     .await;
 }
 
+#[tokio::test]
+async fn mcp_server_should_create_partitions() {
+    assert_empty_response(
+        "create_partitions",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partitions_count": 3 })),
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_delete_partitions() {
+    assert_empty_response(
+        "delete_partitions",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partitions_count": 1 })),
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_delete_segments() {
+    assert_empty_response(
+        "delete_segments",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "segments_count": 1 })),
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_poll_messages() {
+    assert_response::<PolledMessages>(
+        "poll_messages",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "offset": 0 })),
+        |messages| {
+            assert_eq!(messages.messages.len(), 1);
+            let message = &messages.messages[0];
+            assert_eq!(message.header.offset, 0);
+            let payload = message.payload_as_string().expect("Failed to parse message payload");
+            assert_eq!(payload, MESSAGE_PAYLOAD);
+        },
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_send_messages() {
+    assert_empty_response(
+        "send_messages",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "partition_id": 1, "messages": [
+            {
+                "payload": "test"
+            }
+        ] })),
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_return_stats() {
+    assert_response::<Stats>("get_stats", None, |stats| {
+        assert!(!stats.hostname.is_empty());
+        assert_eq!(stats.messages_count, 1);
+    })
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_return_me() {
+    assert_response::<ClientInfoDetails>("get_me", None, |client| {
+        assert!(client.client_id > 0);
+    })
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_return_clients() {
+    assert_response::<Vec<ClientInfo>>("get_clients", None, |clients| {
+        assert!(!clients.is_empty());
+    })
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_handle_snapshot() {
+    assert_response::<Snapshot>("snapshot", None, |snapshot| {
+        assert!(!snapshot.0.is_empty());
+    })
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_return_consumer_groups() {
+    assert_response::<Vec<ConsumerGroup>>(
+        "get_consumer_groups",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME})),
+        |groups| {
+            assert!(!groups.is_empty());
+        },
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_return_consumer_group_details() {
+    assert_response::<ConsumerGroupDetails>("get_consumer_group", Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "group_id": CONSUMER_GROUP_NAME })), |group| {
+        assert_eq!(group.name, CONSUMER_GROUP_NAME);
+        assert_eq!(group.partitions_count, 1);
+        assert_eq!(group.members_count, 0);
+        assert!(group.members.is_empty());
+
+    })
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_create_consumer_group() {
+    let name = "test";
+    assert_response::<ConsumerGroupDetails>(
+        "create_consumer_group",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "name": name })),
+        |group| {
+            assert_eq!(group.name, name);
+            assert_eq!(group.partitions_count, 1);
+            assert_eq!(group.members_count, 0);
+            assert!(group.members.is_empty());
+        },
+    )
+    .await;
+}
+
+#[tokio::test]
+async fn mcp_server_should_delete_consumer_group() {
+    assert_empty_response(
+        "delete_consumer_group",
+        Some(json!({ "stream_id": STREAM_NAME, "topic_id": TOPIC_NAME, "group_id": CONSUMER_GROUP_NAME })),
+    )
+    .await;
+}
+
 async fn assert_empty_response(method: &str, data: Option<serde_json::Value>) {
     assert_response::<()>(method, data, |()| {}).await
 }
@@ -202,6 +344,15 @@ async fn assert_response<T: DeserializeOwned>(
 ) {
     let infra = setup().await;
     let client = infra.mcp_client;
+    let result = invoke_request(&client, method, data).await;
+    assert_response(result)
+}
+
+async fn invoke_request<T: DeserializeOwned>(
+    client: &TestMcpClient,
+    method: &str,
+    data: Option<serde_json::Value>,
+) -> T {
     let error_message = format!("Failed to invoke MCP method: {method}",);
     let mut result = client.invoke(method, data).await.expect(&error_message);
 
@@ -214,8 +365,7 @@ async fn assert_response<T: DeserializeOwned>(
         panic!("Expected text response for MCP method: {method}");
     };
 
-    let json = serde_json::from_str::<T>(&text.text).expect("Failed to parse JSON");
-    assert_response(json)
+    serde_json::from_str::<T>(&text.text).expect("Failed to parse JSON")
 }
 
 async fn setup() -> McpInfra {
@@ -291,6 +441,11 @@ async fn seed_data(iggy_server_address: &str) {
         )
         .await
         .expect("Failed to send messages");
+
+    iggy_client
+        .create_consumer_group(&STREAM_ID, &TOPIC_ID, CONSUMER_GROUP_NAME, None)
+        .await
+        .expect("Failed to create consumer group");
 }
 
 #[derive(Debug)]


(iggy) 02/02: Merge branch 'master' into mcp

Posted by pi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

piotr pushed a commit to branch mcp
in repository https://gitbox.apache.org/repos/asf/iggy.git

commit f79c940b520d09f5a8c5c0f436958a4abaf34e09
Merge: e9793916 ada8f6c4
Author: spetz <pi...@gmail.com>
AuthorDate: Mon Jul 21 22:37:29 2025 +0200

    Merge branch 'master' into mcp

 foreign/node/package.json                               | 13 ++++++-------
 foreign/node/{ => src}/examples/stream-file-to-topic.ts |  2 +-
 foreign/node/{ => src}/examples/stream-topic-to-file.ts |  4 ++--
 foreign/node/{ => src}/examples/utils.ts                |  4 ++--
 foreign/node/src/wire/client/client.utils.ts            |  2 ++
 foreign/node/src/wire/stream/stream.utils.ts            |  3 +++
 foreign/node/src/wire/topic/create-topic.command.ts     |  8 ++++----
 foreign/node/src/wire/topic/index.ts                    |  1 +
 foreign/node/src/wire/topic/topic.utils.ts              | 11 ++++++-----
 foreign/node/src/wire/topic/update-topic.command.ts     |  8 +++++---
 foreign/node/src/wire/user/user.utils.ts                |  3 +++
 foreign/node/tsconfig.json                              |  2 +-
 12 files changed, 36 insertions(+), 25 deletions(-)