mcp: part 2

This commit is contained in:
nym21
2025-06-21 20:34:14 +02:00
parent c3ae3cb768
commit c0f4ece17b
21 changed files with 280 additions and 187 deletions

View File

@@ -0,0 +1,31 @@
use schemars::JsonSchema;
use serde::Deserialize;
use crate::Index;
#[derive(Debug, Default, Deserialize, JsonSchema)]
pub struct PaginationParam {
#[serde(alias = "p")]
#[schemars(description = "Pagination index")]
#[serde(default)]
pub page: usize,
}
impl PaginationParam {
const PER_PAGE: usize = 1_000;
pub fn start(&self, len: usize) -> usize {
(self.page * Self::PER_PAGE).clamp(0, len)
}
pub fn end(&self, len: usize) -> usize {
((self.page + 1) * Self::PER_PAGE).clamp(0, len)
}
}
#[derive(Debug, Deserialize, JsonSchema)]
pub struct PaginatedIndexParam {
pub index: Index,
#[serde(flatten)]
pub pagination: PaginationParam,
}