Skip to main content
Glama
OntoLayer MCP Server

OntoLayer MCP Server

by AshubShafqat

OntoLayer

Business meaning your agents can query.

Ontologies as code · Knowledge graphs · Governed metrics · MCP

CI License: Apache-2.0 Python

OntoLayer is an open-source reference implementation of a business semantic layer. Define concepts, relationships, mappings, metrics, and policies in YAML; ingest data into a validated knowledge graph; and let agents retrieve definitions and execute approved calculations over MCP.

Version 0.2 includes a complete web workspace: live overview, ontology/record explorer, query studio with downloadable evidence, and access/lineage inspection. All screens use the same authenticated, policy-filtered service as MCP.

OntoLayer workspace

The core runs locally without Docker, a database server, an API key, or a model download. The included LangGraph agent uses a real MCP client. Optional Ollama and OpenAI-compatible planners add natural-language flexibility while calculations remain deterministic.

Five-minute quickstart

Requires Git and uv. Initial dependency/interpreter downloads need internet access; the demo itself runs offline.

git clone https://github.com/AshubShafqat/ontolayer.git
cd ontolayer
uv sync --locked --python 3.12
uv run ontolayer serve --ontology examples/retail/ontology.yaml --credentials examples/retail/credentials.yaml --demo

Open http://127.0.0.1:8000/. The synthetic demo starts as a north-region user. Use the identity selector to compare administrator, analyst, regional and guest views. /docs remains a developer API reference, not the application. The web app has no external font/script/CDN dependency.

To use the CLI and MCP reference agent instead:

uv run ontolayer validate --ontology examples/retail/ontology.yaml
uv run ontolayer build --ontology examples/retail/ontology.yaml
uv run ontolayer ask "revenue from 2026-10-01 to 2026-11-01" --ontology examples/retail/ontology.yaml --actor examples/retail/north.yaml

Expected answer: 250 USD, scoped to authorized north-region records, certified under ontology version 1.0.0, with lineage to lines.csv. The JSON contains snapshot and definition hashes. Run the same question with admin.yaml for 600 USD or south.yaml for 350 USD. The canceled order and November sales are excluded by the definition and date interval.

On Windows machines where the virtual-environment launcher is unavailable but installed Python works, ./scripts/dev.ps1 -m ontolayer ... uses that interpreter with the same dependencies. It does not modify security settings. Run it from this directory after uv sync.

Related MCP server: governed-analytics-agent

What works

Capability

Included

Ontology as code

Typed YAML, generated JSON Schema, references, owners, versions, certification

Modeling

Objects, links, interface contracts and advisory design linter

Ingestion

CSV and read-only SQLite adapters, stable identity and source snapshot hashes

Graph

RDFLib backend, atomic validation, OWL/Turtle export and SHACL constraints

Semantics

Search, entities, relationships, paths, definitions and bounded metric execution

Governance

Default deny, role/attribute grants, PII/property filtering before model access

Agent access

11 read-only MCP tools and authenticated REST

Reference agent

LangGraph over MCP; rules, Ollama or OpenAI-compatible planner

Review workflow

CSV draft scaffolding, isolated proposals, explicit human certification

Examples

Retail and agriculture data, identities, policies and evaluation questions

Delivery

Tests, strict typing, CI, dependency SBOM/audit, wheel build, optional Docker

This v0.2 is a working application with a production configuration profile, not an enterprise-readiness certification. See deployment instructions and operating limits. Remote graph backends, OIDC, HTTP MCP, document extraction, and production orchestration are not implemented. See architecture and limits.

Try the semantic layer

uv run ontolayer lint --ontology examples/retail/ontology.yaml
uv run ontolayer export --ontology examples/retail/ontology.yaml --output ontology.ttl
uv run ontolayer query --ontology examples/retail/ontology.yaml --actor examples/retail/admin.yaml --metric revenue --group-by region
uv run ontolayer evaluate --ontology examples/retail/ontology.yaml --questions examples/retail/questions.yaml
uv run ontolayer ask "harvest by crop" --ontology examples/agriculture/ontology.yaml --actor examples/agriculture/north.yaml

The no-key planner accepts a metric name/synonym, optional by dimension, dimension=value, and from YYYY-MM-DD to YYYY-MM-DD. End dates are exclusive. Unsupported qualifiers such as “last month” trigger clarification rather than guessed dates.

Connect an agent through MCP

uv run ontolayer mcp --ontology examples/retail/ontology.yaml --actor examples/retail/north.yaml

Use search_terms → get_metric → check_answerable → query_metric. Discovery, entity listing, graph traversal, lineage, and safe policy explanations are also available. The trusted launcher chooses the actor; tools cannot change it. See the MCP guide and client config.

For optional local model planning, start Ollama, download a suitable model, then run:

uv run ontolayer ask "Show October 2026 revenue grouped by region" --ontology examples/retail/ontology.yaml --actor examples/retail/north.yaml --provider ollama --model qwen3:8b

For a compatible hosted or local API, use --provider openai-compatible, --base-url http://localhost:8001/v1 and --model YOUR_MODEL. Hosted providers may require ONTOLAYER_LLM_API_KEY in the environment. Only permitted definitions and the question go to the planner; results are rendered from governed tool output. Provider adapters have protocol-mock tests; the core suite does not require a live model.

REST API

uv run ontolayer serve --ontology examples/retail/ontology.yaml --credentials examples/retail/credentials.yaml --demo

Open interactive API docs, authorize with demo-north-token, and call POST /v1/tools/query_metric:

{"arguments": {"metric_id": "revenue", "start_date": "2026-10-01", "end_date": "2026-11-01"}}

The header is Authorization: Bearer demo-north-token. Demo tokens are public fixtures for synthetic data. For real data, create private actors and random credentials with issue-token; serve behind TLS and follow the policy guide and security notes. /health is public; /metrics requires an authenticated operator role.

Define your own domain

Copy an example directory and change its ontology, sources, mappings, policies and questions. Keep source files below the ontology's directory. The retail graph is:

Customer ← placedBy — Order ← partOf — OrderLine — forProduct → Product

Metrics specify units, grain, filters and dates. Revenue uses actual line prices, not current product prices. Source adapters map business properties to columns; backend adapters implement graph storage.

uv run ontolayer draft-csv --source examples/retail/customers.csv --output examples/retail/draft.yaml --namespace retail --concept Customer --owner retail-team
uv run ontolayer propose --candidate examples/retail/draft.yaml

Review the proposal, then use certify --proposal PATH --output NEW_FILE --reviewer NAME to create a new certified file. Existing active files are never overwritten. Review source paths relative to the final ontology location; the CLI does not copy source data. Commit reviewed changes through Git. Certification records review state; it does not prove source-data accuracy.

Development

uv run ruff check src tests scripts
uv run ruff format --check src tests scripts
uv run mypy src
uv run pytest --cov-fail-under=85
uv build
npm ci
npx playwright install chromium
npm run test:e2e

CI tests Python 3.12 and 3.13, browser journeys and automated accessibility, runs real MCP evaluation, builds distributions, and creates a dependency audit/SBOM. Docker is optional: docker compose up --build exposes the synthetic REST demo on localhost port 8000. Docker and live model inference need their respective runtimes.

For private data, omit --demo, issue random tokens and enable --production with explicit allowed hosts. Production mode disables public developer docs and refuses demo credentials. The server enforces strict request contracts, 64 KiB body limits, security headers and per-process rate limits. Use the production deployment guide for HTTPS, backups and operations.

src/ontolayer/   models, validation, adapters, graph, policies, MCP, API, agent, CLI
spec/           generated JSON Schema
examples/       retail and agriculture fixtures, actors, policies, questions
tests/          semantic, security, source, transport and agent checks
docs/           architecture, specification, policies, MCP and decisions
scripts/        fixture generation and Windows development runner

References and license

Inspired by NVIDIA Auto Ontology, ModernRelay Omnigraph, TrustGraph, and Palantir modeling guidance. These are architecture references, not bundled backend integrations. See NOTICE.

Apache-2.0. Contributing · Governance · Code of conduct · Security

Available Tools

11 tools
check_answerableC

Check whether the caller can use this certified metric.

Inputs: metric_id (required). Returns: object

explain_policy_decisionC

Explain visibility without revealing whether a hidden entity exists.

Inputs: entity_id (required). Returns: object

find_pathB

Find an undirected path inside the authorized subgraph (at most six hops).

Inputs: source (required), target (required), max_depth. Returns: object

get_conceptB

Get a concept's definition and permitted properties.

Inputs: concept (required). Returns: object

get_lineageC

Read provenance only for a visible entity.

Inputs: entity_id (required). Returns: object

get_metricB

Read a governed metric definition; this does not execute it.

Inputs: metric_id (required). Returns: object

get_relationshipsC

Find links whose endpoints are both visible to the caller.

Inputs: entity_id (required), limit, offset. Returns: object

list_entitiesC

List authorized entity records; pagination never counts hidden records.

Inputs: concept (required), limit, offset. Returns: object

list_ontology_versionsB

Get the ontology version loaded by this immutable server instance.

Inputs: no named parameters. Returns: object

query_metricC

Execute a certified metric over authorized records, returning values and lineage.

Inputs: metric_id (required), filters, end_date, group_by, +1 more. Returns: object

search_termsC

Search permitted business concepts and metrics, including synonyms.

Inputs: limit, query, offset. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.3/5.0

    Scored across 11 tools

    Disambiguation5/5

    Each tool targets a distinct operation: discovery (search_terms), definition retrieval (get_concept, get_metric), execution (query_metric), authorization checks (check_answerable), graph traversal (get_relationships, find_path), lineage, policy explanation, and version listing. Overlap is minimal, and the descriptions make boundaries clear, especially between metric definition, execution, and answerability.

    Naming Consistency5/5

    All tools use snake_case and a verb_noun or verb_object pattern: search_terms, get_concept, list_entities, get_relationships, find_path, get_metric, query_metric, check_answerable, get_lineage, explain_policy_decision, list_ontology_versions. The verbs vary appropriately by action while the overall convention remains predictable.

    Tool Count5/5

    Eleven tools is well scoped for a governed ontology and metrics server. Each tool covers a distinct capability without obvious redundancy or missing core operations.

    Completeness4/5

    The surface covers concept/metric discovery, definitions, entity listing, relationships, path finding, metric execution, lineage, policy explanation, and ontology versions. Minor gaps exist, such as no explicit get_entity for single-record detail and no dedicated list_concepts or list_metrics beyond search_terms.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables agents to answer analytics questions with provable correctness by resolving metrics through the semantic layer, tracing lineage, traversing knowledge graphs, checking freshness, and searching glossary definitions, while enforcing access controls and logging every call.
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to query databases correctly by serving governed context over MCP, including canonical metric definitions, relationships, business meaning, and guardrails, so answers come back with resolved definitions, fired filters, freshness, and a trust score instead of guesses.
      3
      -
    • A
      license
      A
      quality
      C
      maintenance
      Enables AI agents and their users to ask business questions in plain language and receive governed metric values, breakdowns, share-of-total figures, and the exact parameterized SQL behind them, drawn from a single semantic model rather than ad-hoc SQL. It also lets clients inspect available metrics and their definitions, and preview optimized queries without executing them.
      4
      MIT