Skip to main content

sqlserver_mcp_catalog/tools/
get_tool.rs

1// SQL Server 2025 - master/msdb/sandbox combined catalog MCP server — generated by mcpify. Do not hand-edit.
2
3use rusqlite::Connection;
4
5use crate::core::errors::McpifyError;
6use crate::data::store::get_endpoint;
7
8/// Returns the literal schema, path, method, and documentation for a
9/// specific operationId (PRD §1.5).
10pub fn get_operation(conn: &Connection, operation_id: &str) -> anyhow::Result<serde_json::Value> {
11    let endpoint = get_endpoint(conn, operation_id)?
12        .ok_or_else(|| McpifyError::NotFound(format!("unknown operationId '{operation_id}'")))?;
13    Ok(serde_json::to_value(endpoint)?)
14}
15
16#[cfg(test)]
17mod tests {
18    use super::*;
19
20    /// Minimal `endpoints`-only schema -- `get_operation` never touches
21    /// `semantic_endpoints`, so unlike search_tool's tests this doesn't
22    /// need the sqlite-vec extension registered at all.
23    fn seeded_store() -> Connection {
24        let conn = Connection::open_in_memory().unwrap();
25        conn.execute(
26            "CREATE TABLE endpoints (
27                operation_id TEXT PRIMARY KEY,
28                path TEXT NOT NULL,
29                method TEXT NOT NULL,
30                summary TEXT,
31                description TEXT,
32                input_schema TEXT NOT NULL,
33                output_schema TEXT NOT NULL,
34                auth_scheme_ref TEXT
35            )",
36            [],
37        )
38        .unwrap();
39        conn.execute(
40            "INSERT INTO endpoints (operation_id, path, method, summary, description, input_schema, output_schema, auth_scheme_ref)
41             VALUES ('listWidgets', '/widgets', 'GET', 'List widgets', NULL, '{}', '[]', NULL)",
42            [],
43        )
44        .unwrap();
45        conn
46    }
47
48    #[test]
49    fn get_operation_returns_the_seeded_endpoint_as_json() {
50        let conn = seeded_store();
51        let result = get_operation(&conn, "listWidgets").unwrap();
52        assert_eq!(result["operation_id"], "listWidgets");
53        assert_eq!(result["path"], "/widgets");
54        assert_eq!(result["summary"], "List widgets");
55    }
56
57    #[test]
58    fn get_operation_errors_on_an_unknown_operation_id() {
59        let conn = seeded_store();
60        let err = get_operation(&conn, "doesNotExist").unwrap_err();
61        assert!(err.to_string().contains("unknown operationId 'doesNotExist'"));
62    }
63}