Skip to content

Commit dbd4159

Browse files
committed
feat(serve): register read_section and health MCP tools
1 parent 5d3a3ad commit dbd4159

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/serve.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,17 @@ pub struct UnarchiveParams {
120120
pub file: String,
121121
}
122122

123+
#[derive(Debug, Deserialize, JsonSchema)]
124+
pub struct ReadSectionParams {
125+
/// Target note: file path, basename, or #docid.
126+
pub file: String,
127+
/// Section heading to read (case-insensitive).
128+
pub heading: String,
129+
}
130+
131+
#[derive(Debug, Deserialize, JsonSchema)]
132+
pub struct HealthParams {}
133+
123134
// ---------------------------------------------------------------------------
124135
// Server
125136
// ---------------------------------------------------------------------------
@@ -413,6 +424,40 @@ impl EngraphServer {
413424
.map_err(|e| mcp_err(&e))?;
414425
to_json_result(&result)
415426
}
427+
428+
#[tool(
429+
name = "read_section",
430+
description = "Read a specific heading section from a note. Returns content from that heading to the next same-level heading."
431+
)]
432+
async fn read_section(
433+
&self,
434+
params: Parameters<ReadSectionParams>,
435+
) -> Result<CallToolResult, McpError> {
436+
let store = self.store.lock().await;
437+
let result =
438+
context::read_section(&store, &self.vault_path, &params.0.file, &params.0.heading)
439+
.map_err(|e| mcp_err(&e))?;
440+
to_json_result(&result)
441+
}
442+
443+
#[tool(
444+
name = "health",
445+
description = "Vault health report: orphans, broken links, stale notes, tag hygiene, index freshness."
446+
)]
447+
async fn health(
448+
&self,
449+
_params: Parameters<HealthParams>,
450+
) -> Result<CallToolResult, McpError> {
451+
let store = self.store.lock().await;
452+
let profile_ref = self.profile.as_ref().as_ref();
453+
let config = crate::health::HealthConfig {
454+
daily_folder: profile_ref.and_then(|p| p.structure.folders.daily.clone()),
455+
inbox_folder: profile_ref.and_then(|p| p.structure.folders.inbox.clone()),
456+
};
457+
let report =
458+
crate::health::generate_health_report(&store, &config).map_err(|e| mcp_err(&e))?;
459+
to_json_result(&report)
460+
}
416461
}
417462

418463
#[tool_handler]

0 commit comments

Comments
 (0)