fix: Small improvement to progress demo (#898)
Signed-off-by: Dawid Nowak <nowakd@gmail.com>
This commit is contained in:
parent
2536a05992
commit
52e731bec6
3 changed files with 26 additions and 55 deletions
|
|
@ -1,50 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
# Verify commit message follows conventional commit format
|
|
||||||
# https://www.conventionalcommits.org/
|
|
||||||
#
|
|
||||||
# Uses npx commitlint if Node.js is available (same as CI),
|
|
||||||
# otherwise falls back to basic shell regex validation.
|
|
||||||
|
|
||||||
commit_msg_file="$1"
|
|
||||||
commit_msg=$(cat "$commit_msg_file")
|
|
||||||
|
|
||||||
# Skip merge commits
|
|
||||||
if echo "$commit_msg" | grep -qE "^Merge "; then
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Try to use commitlint via npx if Node.js is available
|
|
||||||
if command -v npx >/dev/null 2>&1; then
|
|
||||||
# Run commitlint with config-conventional rules (same as CI)
|
|
||||||
echo "$commit_msg" | npx --yes @commitlint/cli@latest --extends @commitlint/config-conventional
|
|
||||||
exit $?
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Fallback: basic shell regex validation if Node.js is not available
|
|
||||||
echo "Note: Node.js not found, using basic commit message validation."
|
|
||||||
echo " Install Node.js for full commitlint validation (same as CI)."
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
# Conventional commit types from @commitlint/config-conventional
|
|
||||||
types="build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test"
|
|
||||||
|
|
||||||
# Pattern: type(optional-scope): description
|
|
||||||
# The description must start with lowercase and not end with period
|
|
||||||
pattern="^($types)(\(.+\))?(!)?: .+"
|
|
||||||
|
|
||||||
if ! echo "$commit_msg" | head -1 | grep -qE "$pattern"; then
|
|
||||||
echo "ERROR: Commit message does not follow conventional commit format."
|
|
||||||
echo ""
|
|
||||||
echo "Expected format: <type>(<scope>): <description>"
|
|
||||||
echo ""
|
|
||||||
echo "Valid types: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test"
|
|
||||||
echo ""
|
|
||||||
echo "Examples:"
|
|
||||||
echo " feat: add new feature"
|
|
||||||
echo " fix(parser): resolve parsing issue"
|
|
||||||
echo " docs: update README"
|
|
||||||
echo ""
|
|
||||||
echo "Your commit message:"
|
|
||||||
echo " $(head -1 "$commit_msg_file")"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
@ -11,7 +11,7 @@ use rmcp::{
|
||||||
};
|
};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use tokio_stream::StreamExt;
|
use tokio_stream::StreamExt;
|
||||||
use tracing::debug;
|
use tracing::{debug, info};
|
||||||
|
|
||||||
// a Stream data source that generates data in chunks
|
// a Stream data source that generates data in chunks
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -30,7 +30,7 @@ impl StreamDataSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn from_text(text: &str) -> Self {
|
pub fn from_text(text: &str) -> Self {
|
||||||
Self::new(text.as_bytes().to_vec(), 1)
|
Self::new(text.as_bytes().to_vec(), 5)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -61,7 +61,7 @@ impl ProgressDemo {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
data_source: StreamDataSource::from_text("Hello, world!"),
|
data_source: StreamDataSource::from_text("1111122222333334444455555"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[tool(description = "Process data stream with progress updates")]
|
#[tool(description = "Process data stream with progress updates")]
|
||||||
|
|
@ -70,6 +70,21 @@ impl ProgressDemo {
|
||||||
ctx: RequestContext<RoleServer>,
|
ctx: RequestContext<RoleServer>,
|
||||||
) -> Result<CallToolResult, McpError> {
|
) -> Result<CallToolResult, McpError> {
|
||||||
let mut counter = 0;
|
let mut counter = 0;
|
||||||
|
info!(
|
||||||
|
"Processing stream with progress token {:?}",
|
||||||
|
ctx.meta.get_key_value("progressToken")
|
||||||
|
);
|
||||||
|
let Some((_, progress_token)) = ctx.meta.get_key_value("progressToken") else {
|
||||||
|
return Err(McpError::internal_error(format!("No progress token"), None));
|
||||||
|
};
|
||||||
|
|
||||||
|
let Ok(progress_token) = serde_json::from_value::<NumberOrString>(progress_token.clone())
|
||||||
|
else {
|
||||||
|
return Err(McpError::internal_error(
|
||||||
|
format!("Invalid format of the progress token"),
|
||||||
|
None,
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
||||||
let mut data_source = self.data_source.clone();
|
let mut data_source = self.data_source.clone();
|
||||||
loop {
|
loop {
|
||||||
|
|
@ -83,9 +98,9 @@ impl ProgressDemo {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
// create progress notification param
|
// create progress notification param
|
||||||
let progress_param = ProgressNotificationParam {
|
let progress_param = ProgressNotificationParam {
|
||||||
progress_token: ProgressToken(NumberOrString::Number(counter)),
|
progress_token: ProgressToken(progress_token.clone()),
|
||||||
progress: counter as f64,
|
progress: counter as f64,
|
||||||
total: None,
|
total: Some(5.0),
|
||||||
message: Some(chunk_str.to_string()),
|
message: Some(chunk_str.to_string()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -104,6 +119,7 @@ impl ProgressDemo {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(CallToolResult::success(vec![Content::text(format!(
|
Ok(CallToolResult::success(vec![Content::text(format!(
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ use rmcp::{
|
||||||
|
|
||||||
mod common;
|
mod common;
|
||||||
use common::progress_demo::ProgressDemo;
|
use common::progress_demo::ProgressDemo;
|
||||||
|
use tracing_subscriber::EnvFilter;
|
||||||
|
|
||||||
const HTTP_BIND_ADDRESS: &str = "127.0.0.1:8001";
|
const HTTP_BIND_ADDRESS: &str = "127.0.0.1:8001";
|
||||||
|
|
||||||
|
|
@ -20,6 +21,10 @@ async fn main() -> anyhow::Result<()> {
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.unwrap_or_else(|| env::var("TRANSPORT_MODE").unwrap_or_else(|_| "stdio".to_string()));
|
.unwrap_or_else(|| env::var("TRANSPORT_MODE").unwrap_or_else(|_| "stdio".to_string()));
|
||||||
|
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(EnvFilter::from_default_env())
|
||||||
|
.init();
|
||||||
|
|
||||||
match transport_mode.as_str() {
|
match transport_mode.as_str() {
|
||||||
"stdio" => run_stdio().await,
|
"stdio" => run_stdio().await,
|
||||||
"http" | "streamhttp" => run_streamable_http().await,
|
"http" | "streamhttp" => run_streamable_http().await,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue