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
# 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_accessResponse Format
All endpoints return JSON. Errors follow:
{
"error": "UNAUTHORIZED",
"message": "Missing or invalid JWT",
"status": 401
}Gateway Endpoints
Base: http://localhost:8082
/api/graph/sparqlπ authExecute a read-only SPARQL SELECT/ASK/CONSTRUCT/DESCRIBE query. UPDATE/INSERT/DELETE rejected at ARQ parser level.
/api/graph/entityπ authGet entity CBD (concise bounded description) + labels as JSON-LD. Query param: ?iri=<encoded IRI>
/api/graph/searchπ authSearch entities by label. Query params: ?q=<text>&limit=20. OpenSearch-backed with SPARQL fallback.
/api/graph/typeaheadπ authPrefix + fuzzy typeahead. Query param: ?q=<prefix>. Returns entity IRIs and labels.
/api/ai/nl-queryπ authNatural language query. Body: {"question": "..."}. Returns {sparql, results, entities, cannot_answer}.
/api/ai/retrieveπ authGraphRAG retrieval. Body: {"question": "..."}. Returns {entities, relations, citations, truncated}.
/api/ai/mapping-suggestionsπ authAI mapping suggestions for columnsβontology properties. Body: {"sourceId": "...", "table": "..."}.
/api/ontology/importπ authImport ProtΓ©gΓ© Turtle/RDF-XML file. Steward role required.
/api/ontology/versionsπ authList ontology versions (Git commits). Steward role required.
/api/ontology/diffπ authAxiom-level diff between versions. Query params: ?from=v1&to=v2.
/api/ontology/publishπ authPublish a version to urn:ontos:ontology. Steward role required.
/api/ingest/sourcesπ authRegister a data source connector. Body: {type, name, credentials}. Steward role required.
/api/ingest/sources/{id}/discoverπ authDiscover schemas/tables from a registered source.
/api/ingest/sources/{id}/previewπ authPreview rows. Query param: ?table=<name>&n=10.
/api/ingest/sources/{id}/syncπ authTrigger incremental sync. Returns sync run ID.
/api/ingest/stagingπ authList pending staging proposals. Steward role required.
/api/ingest/staging/approveπ authApprove staging triples β data graph. Body: {ids: ["..."]]. Steward role required.
MCP Server (ai-svc) Endpoints
Base: http://localhost:8000
/mcp/toolsList all MCP tools. Returns array of tool definitions.
/mcp/tools/search_entitiesπ authSearch entities by natural language query. Body: {"query": "supplier"}.
/mcp/tools/get_entityπ authGet entity CBD. Body: {"iri": "https://ontos.example/id/..."}.
/mcp/tools/run_sparqlπ authExecute read-only SPARQL (5s timeout, 1000-row cap). Body: {"query": "SELECT ..."}.
/mcp/tools/describe_ontologyπ authGet ontology description (classes, properties, shapes). No body.
SPARQL Proxy Examples
# 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+).
# 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
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.