Ontos
Last updated on July 14, 2026

API Reference

REST endpoints, MCP tools, authentication, and SPARQL proxy usage.

Authentication

All endpoints require a valid Keycloak JWT in the Authorization: Bearer header. The gateway validates the token and forwards it to all internal services.

Get a Token

bash
# Analyst token (maya)
ANALYST_TOKEN=$(curl -s -X POST \
  http://localhost:8080/realms/ontos/protocol/openid-connect/token \
  -d 'grant_type=password&client_id=ontos-web&username=maya&password=maya' | jq -r .access_token)

# Steward token (chen)
STEWARD_TOKEN=$(curl -s -X POST \
  http://localhost:8080/realms/ontos/protocol/openid-connect/token \
  -d 'grant_type=password&client_id=ontos-web&username=chen&password=chen' | jq -r .access_token)

# Decode to inspect claims
echo $ANALYST_TOKEN | cut -d'.' -f2 | base64 -d | jq .realm_access

Response Format

All endpoints return JSON. Errors follow:

json
{
  "error": "UNAUTHORIZED",
  "message": "Missing or invalid JWT",
  "status": 401
}

Gateway Endpoints

Base: http://localhost:8082

POST/api/graph/sparqlπŸ”’ auth

Execute a read-only SPARQL SELECT/ASK/CONSTRUCT/DESCRIBE query. UPDATE/INSERT/DELETE rejected at ARQ parser level.

GET/api/graph/entityπŸ”’ auth

Get entity CBD (concise bounded description) + labels as JSON-LD. Query param: ?iri=<encoded IRI>

GET/api/graph/searchπŸ”’ auth

Search entities by label. Query params: ?q=<text>&limit=20. OpenSearch-backed with SPARQL fallback.

GET/api/graph/typeaheadπŸ”’ auth

Prefix + fuzzy typeahead. Query param: ?q=<prefix>. Returns entity IRIs and labels.

POST/api/ai/nl-queryπŸ”’ auth

Natural language query. Body: {"question": "..."}. Returns {sparql, results, entities, cannot_answer}.

POST/api/ai/retrieveπŸ”’ auth

GraphRAG retrieval. Body: {"question": "..."}. Returns {entities, relations, citations, truncated}.

POST/api/ai/mapping-suggestionsπŸ”’ auth

AI mapping suggestions for columns→ontology properties. Body: {"sourceId": "...", "table": "..."}.

POST/api/ontology/importπŸ”’ auth

Import ProtΓ©gΓ© Turtle/RDF-XML file. Steward role required.

GET/api/ontology/versionsπŸ”’ auth

List ontology versions (Git commits). Steward role required.

GET/api/ontology/diffπŸ”’ auth

Axiom-level diff between versions. Query params: ?from=v1&to=v2.

POST/api/ontology/publishπŸ”’ auth

Publish a version to urn:ontos:ontology. Steward role required.

POST/api/ingest/sourcesπŸ”’ auth

Register a data source connector. Body: {type, name, credentials}. Steward role required.

GET/api/ingest/sources/{id}/discoverπŸ”’ auth

Discover schemas/tables from a registered source.

GET/api/ingest/sources/{id}/previewπŸ”’ auth

Preview rows. Query param: ?table=<name>&n=10.

POST/api/ingest/sources/{id}/syncπŸ”’ auth

Trigger incremental sync. Returns sync run ID.

GET/api/ingest/stagingπŸ”’ auth

List pending staging proposals. Steward role required.

POST/api/ingest/staging/approveπŸ”’ auth

Approve staging triples β†’ data graph. Body: {ids: ["..."]]. Steward role required.

MCP Server (ai-svc) Endpoints

Base: http://localhost:8000

GET/mcp/tools

List all MCP tools. Returns array of tool definitions.

POST/mcp/tools/search_entitiesπŸ”’ auth

Search entities by natural language query. Body: {"query": "supplier"}.

POST/mcp/tools/get_entityπŸ”’ auth

Get entity CBD. Body: {"iri": "https://ontos.example/id/..."}.

POST/mcp/tools/run_sparqlπŸ”’ auth

Execute read-only SPARQL (5s timeout, 1000-row cap). Body: {"query": "SELECT ..."}.

POST/mcp/tools/describe_ontologyπŸ”’ auth

Get ontology description (classes, properties, shapes). No body.

SPARQL Proxy Examples

bash
# Count suppliers in the data graph
curl -X POST http://localhost:8082/api/graph/sparql \
  -H "Authorization: Bearer $ANALYST_TOKEN" \
  -H "Content-Type: application/sparql-query" \
  -d 'SELECT (COUNT(*) AS ?n) WHERE { GRAPH <urn:ontos:data> { ?s a <https://ontos.example/schema#Supplier> } }'

# Get a specific entity
curl "http://localhost:8082/api/graph/entity?iri=https%3A%2F%2Fontos.example%2Fid%2Fsupplier-001" \
  -H "Authorization: Bearer $ANALYST_TOKEN" \
  -H "Accept: application/ld+json"

MCP Tool Usage

Connect any MCP-compatible client to http://localhost:8000/mcpwith the user's JWT as a bearer token. The server is streamable HTTP (MCP v2024-11-05+).

bash
# List tools
curl http://localhost:8000/mcp/tools | jq '.[].name'
# ["search_entities", "get_entity", "run_sparql", "describe_ontology"]

# Search entities
curl -X POST http://localhost:8000/mcp/tools/search_entities \
  -H "Authorization: Bearer $ANALYST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "supplier in china"}'

# Run a read-only SPARQL query
curl -X POST http://localhost:8000/mcp/tools/run_sparql \
  -H "Authorization: Bearer $STEWARD_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"query": "SELECT ?s ?name WHERE { GRAPH <urn:ontos:data> { ?s a <https://ontos.example/schema#Supplier> ; <https://ontos.example/schema#name> ?name } } LIMIT 5"}'

NL→SPARQL API

bash
curl -X POST http://localhost:8082/api/ai/nl-query \
  -H "Authorization: Bearer $ANALYST_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"question": "Which suppliers supply components for Industrial Pump Assembly?"}'

# Response
{
  "sparql": "SELECT ?supplier ?name WHERE { ... }",
  "results": [
    {"supplier": "https://ontos.example/id/supplier-001", "name": "Apex Materials Ltd"},
    ...
  ],
  "entities": ["https://ontos.example/id/supplier-001", ...],
  "cannot_answer": false,
  "self_repaired": false
}

Rate Limits

The gateway enforces 20 requests/second per user (bucket4j). Exceeding returns HTTP 429 with a Retry-After: 1 header. There is no total daily cap in the current Phase 1 implementation.

Was this page helpful?