Skip to content

Commit cd345e3

Browse files
committed
feat(mcp): add identity and setup tools
Expose identity (compact user context at session start) and setup (detect/apply onboarding) as MCP tools in serve.rs. Updates server instructions string to advertise both tools.
1 parent f1cee60 commit cd345e3

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

src/serve.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ pub struct ReindexFileParams {
192192
pub file: String,
193193
}
194194

195+
#[derive(Debug, Deserialize, JsonSchema)]
196+
pub struct SetupParams {
197+
/// Mode: "detect" to inspect vault, "apply" to configure identity and index.
198+
pub mode: String,
199+
/// User name (required for apply mode).
200+
pub name: Option<String>,
201+
/// User role (required for apply mode).
202+
pub role: Option<String>,
203+
/// Vault purpose (optional for apply mode).
204+
pub purpose: Option<String>,
205+
}
206+
195207
// ---------------------------------------------------------------------------
196208
// Server
197209
// ---------------------------------------------------------------------------
@@ -886,6 +898,56 @@ impl EngraphServer {
886898
});
887899
to_json_result(&output)
888900
}
901+
902+
#[tool(
903+
name = "identity",
904+
description = "Returns compact user identity and current context. Call at session start for instant context. L0 = static identity (~50 tokens), L1 = dynamic state (~120 tokens)."
905+
)]
906+
async fn identity(&self) -> Result<CallToolResult, McpError> {
907+
let store = self.store.lock().await;
908+
let config = crate::config::Config::load().unwrap_or_default();
909+
let block = crate::identity::format_identity_block(&config, &store)
910+
.map_err(|e| mcp_err(&e))?;
911+
Ok(CallToolResult::success(vec![Content::text(block)]))
912+
}
913+
914+
#[tool(
915+
name = "setup",
916+
description = "Run first-time setup or update identity. Use 'detect' mode to inspect the vault without changes, 'apply' mode to configure identity and index. Returns JSON."
917+
)]
918+
async fn setup(&self, params: Parameters<SetupParams>) -> Result<CallToolResult, McpError> {
919+
match params.0.mode.as_str() {
920+
"detect" => {
921+
let result = crate::onboarding::run_detect_json(&self.vault_path)
922+
.map_err(|e| mcp_err(&e))?;
923+
to_json_result(&result)
924+
}
925+
"apply" => {
926+
let mut config = crate::config::Config::load().unwrap_or_default();
927+
let data_dir = crate::config::Config::data_dir().map_err(|e| mcp_err(&e))?;
928+
let flags = crate::onboarding::ApplyFlags {
929+
name: params.0.name,
930+
role: params.0.role,
931+
purpose: params.0.purpose,
932+
identity_only: false,
933+
reindex_only: false,
934+
};
935+
let result = crate::onboarding::run_apply_json(
936+
&self.vault_path,
937+
&mut config,
938+
&data_dir,
939+
flags,
940+
)
941+
.map_err(|e| mcp_err(&e))?;
942+
to_json_result(&result)
943+
}
944+
other => Err(McpError::new(
945+
rmcp::model::ErrorCode::INVALID_PARAMS,
946+
format!("Unknown mode: {other}. Use 'detect' or 'apply'."),
947+
None::<serde_json::Value>,
948+
)),
949+
}
950+
}
889951
}
890952

891953
#[tool_handler]
@@ -898,6 +960,7 @@ impl rmcp::handler::server::ServerHandler for EngraphServer {
898960
edit_frontmatter for tags/properties, update_metadata for bulk tag/alias replacement. \
899961
Lifecycle: move_note to relocate, archive to soft-delete, unarchive to restore, delete for permanent removal. \
900962
Index: reindex_file to refresh a single file's index after external edits. \
963+
Identity: identity for user context at session start, setup to run first-time onboarding (detect/apply). \
901964
Migration: migrate_preview to classify notes into PARA folders, migrate_apply to execute the migration, migrate_undo to revert.",
902965
)
903966
}

0 commit comments

Comments
 (0)