Skip to content

Commit fe46ad4

Browse files
authored
Merge pull request #7 from Minitour/feature/sparql-query
Add sparql_query tool for SPARQL querying over OWL files
2 parents faafd2e + 4877c8c commit fe46ad4

9 files changed

Lines changed: 476 additions & 5 deletions

File tree

Cargo.lock

Lines changed: 186 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rust-mcp-sdk = { version = "0.8", default-features = false, features = [
2323
] }
2424
horned-owl = "1.4"
2525
whelk = { git = "https://github.com/INCATools/whelk-rs" }
26+
oxigraph = { version = "0.5", default-features = false }
2627
curie = "0.1"
2728
tokio = { version = "1", features = ["full"] }
2829
serde = { version = "1", features = ["derive"] }

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Built as a drop-in replacement for [ai4curation/owl-mcp](https://github.com/ai4c
1212

1313
## Features
1414

15-
- **11 MCP tools** — add, remove, search, and inspect axioms; manage prefixes, labels, and ontology IRIs; scan for modeling pitfalls; evaluate ontology quality
15+
- **12 MCP tools** — add, remove, search, and inspect axioms; manage prefixes, labels, and ontology IRIs; scan for modeling pitfalls; evaluate ontology quality; run SPARQL queries
1616
- **CLI mode** — every tool is also available as a direct CLI subcommand (`owl-mcp find-axioms ...`)
1717
- **2 transport modes**`stdio` (default, for Cursor/Claude Desktop) and `http` (Streamable HTTP + SSE)
1818
- **Live file watching** — automatically reloads ontology files modified externally
@@ -71,6 +71,8 @@ owl-mcp find-axioms --file ontology.owl --pattern "Dog" --limit 50
7171
owl-mcp get-all-axioms --file ontology.owl --include-labels
7272
owl-mcp test-pitfalls --file ontology.owl
7373
owl-mcp test-quality --file ontology.owl
74+
owl-mcp sparql --file ontology.owl --query "SELECT ?c WHERE { ?c a owl:Class }"
75+
owl-mcp sparql --file schema.owl --file data.owl --query "ASK { ?i a :Plan }"
7476
```
7577

7678
Run `owl-mcp --help` for a full list of commands, or `owl-mcp <command> --help` for details on a specific command.
@@ -144,6 +146,14 @@ All tools operate on OWL files by absolute path. The manager lazily loads files
144146

145147
`test_quality` uses the [whelk](https://github.com/INCATools/whelk-rs) OWL EL reasoner to compute inferred class hierarchy and returns a JSON report containing 19 raw and scaled metrics (ANOnto, AROnto, CBOOnto, CROnto, DITOnto, INROnto, LCOMOnto, NACOnto, NOCOnto, NOMOnto, RFCOnto, RROnto, TMOnto, WMCOnto, and variants), 22 subcharacteristics, 7 quality characteristics (Structural, Functional Adequacy, Maintainability, Operability, Reliability, Transferability, Compatibility), and an overall OQuaRE score on a 1–5 scale.
146148

149+
### Querying
150+
151+
| Tool | Description |
152+
|---|---|
153+
| `sparql_query` | Run a SPARQL query over one or more OWL files |
154+
155+
`sparql_query` takes `owl_file_paths` (one or more absolute paths) and a `query` string. Each file is serialized to RDF and loaded together into an in-memory [oxigraph](https://github.com/oxigraph/oxigraph) store, so passing several paths merges a schema with its ABox or imports before the query runs. `SELECT` and `ASK` return the standard [SPARQL 1.1 JSON results](https://www.w3.org/TR/sparql11-results-json/) format; `CONSTRUCT` and `DESCRIBE` return a list of N-Triples. Queries run over asserted triples (no reasoning is applied).
156+
147157
## Development
148158

149159
```bash

src/cli.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,16 @@ pub enum CliCommand {
138138
#[arg(long)]
139139
pitfalls: Option<String>,
140140
},
141+
142+
/// Run a SPARQL query over one or more OWL files (merged into one RDF graph)
143+
Sparql {
144+
/// Absolute path to an OWL file. Repeat --file to merge several (e.g. schema + ABox).
145+
#[arg(long = "file", required = true)]
146+
files: Vec<String>,
147+
/// SPARQL query string (SELECT, ASK, CONSTRUCT, or DESCRIBE)
148+
#[arg(long)]
149+
query: String,
150+
},
141151
}
142152

143153
fn print_result(result: CallToolResult) {
@@ -285,6 +295,16 @@ pub async fn dispatch(cmd: CliCommand, manager: Manager) {
285295
)
286296
.await
287297
}
298+
CliCommand::Sparql { files, query } => {
299+
tools::SparqlQuery::run_tool(
300+
tools::SparqlQuery {
301+
owl_file_paths: files,
302+
query,
303+
},
304+
&manager,
305+
)
306+
.await
307+
}
288308
};
289309

290310
match result {

src/handler.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl ServerHandler for OwlMcpHandler {
6161
OwlTools::SetOntologyIri(p) => SetOntologyIri::run_tool(p, mgr).await,
6262
OwlTools::TestQuality(p) => TestQuality::run_tool(p, mgr).await,
6363
OwlTools::TestPitfalls(p) => TestPitfalls::run_tool(p, mgr).await,
64+
OwlTools::SparqlQuery(p) => SparqlQuery::run_tool(p, mgr).await,
6465
}
6566
}
6667

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ mod handler;
33
mod ontology;
44
mod pitfalls;
55
mod quality;
6+
mod sparql;
67
mod tools;
78

89
use std::sync::Arc;

0 commit comments

Comments
 (0)