
Cosmos Semantic
io.github.WiliamRosaPublished by GitHub account WiliamRosav0.3.0Updated Nov 5, 2026
Governed metrics, business rules and a glossary for AI agents, with evidence on every answer.
Overview
Cosmos Semantic serves a governed semantic layer over MCP so assistants query defined metrics and business rules instead of guessing SQL, with evidence on…
- What you can do
- Search and explain governed concepts, metrics and business rules from the semantic model
- List the members (metrics, dimensions, rules) available in the model
- Run metric queries with dimensions, rule filters and a pinned reference date, returning deterministic SQL
- Show the generated SQL for a query
- Every answer carries the expanded formula, rules, row filters, reference date and hashes, and runs as the token's user
- When to use it
- Use it when an assistant needs trustworthy business numbers from a warehouse or database and you already maintain (or want to define) a semantic model of metrics, rules and a glossary, rather than letting the model write ad-hoc SQL.
- Requirements
- Local Python package run with uvx (Python 3.11+); a semantic model and a connections file for the target database (DuckDB, Postgres, SQL Server, MySQL/MariaDB, Oracle, Databricks, Snowflake); the COSMOS_API_KEY environment variable for the stdio transport; network access to the data source. The REST/MCP server mode uses OIDC settings or COSMOS_DEV_API_KEYS.
Installation
In SourceWeft
- Open Cosmos Semantic in the dashboard and add it to a workspace.
- Enable the server for the chats that should use its tools.
Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.
Other MCP clients
Follow the launch instructions in the repository.
README
Cosmos Semantic
[PyPI] [Python] [CI] [License] [Good first issues]
An open-source semantic layer with an ontology at its core, so AI agents and apps get the same number on every database, with the proof in every answer.
Live demo of the console · Quickstart · Docs · Article (Portuguese)
AI agents that write SQL over raw tables return numbers that look right and that nobody can explain: "revenue" has three definitions, "active customer" means 60 days to one team and 90 to another. Cosmos Semantic defines metrics, business rules and concepts once, serves them to agents over MCP instead of letting them guess SQL, and attaches evidence to every answer.
The YAML format uses the dbt Semantic Layer vocabulary and ships a JSON Schema; Cube and dbt are import sources and export targets, not dependencies. The core is Apache 2.0 within an open-core model (ADR 0005).
Status: phases 0 to 3 are implemented: the engine, the ontology (glossary and business rules), the REST API, the MCP server, OIDC identity, verifiable numbers (evidence, replay, reconciliation, impact, bootstrap), business context (rule versions, usage and cost, knowledge graph, Power BI import, AI-assisted discovery, the retail pack, SKOS export) and the read-only console. See the roadmap.
Quickstart
That is a governed metric with its evidence (formula, rules, policies, as_of and hashes) in about
a minute, on a local DuckDB file. The quickstart continues with business
rules, row filters, personal data and connecting an AI agent over MCP. Extras: duckdb,
postgres, sqlserver, mysql (MySQL and MariaDB), oracle, databricks, snowflake, server (REST and MCP), ai (cosmos suggest), testdata.
Console
cosmos serve also serves a read-only console at /console, in English or Portuguese, for people who decide rather than build:
- metric health and ownership;
- business processes as graphs colored by health;
- the catalog in business words;
- every audited answer, with a button to reproduce it;
- usage and cost per agent.
cosmos check records rule tests and reconciliations against legacy reports, so the console shows health over time.
Development
Requires Python 3.11+ and uv. From a clone of this repository:
REST API and MCP
cosmos serve starts the REST API at /v1 and the MCP server at /mcp in the same process; interactive docs are at /docs.
Remote MCP clients use /mcp as an OAuth protected resource: requests without a valid token get HTTP 401 with a WWW-Authenticate header pointing to /.well-known/oauth-protected-resource, which names the identity provider (set COSMOS_PUBLIC_URL behind a proxy).
For local MCP clients (Claude Desktop, Claude Code), use the stdio transport: cosmos mcp -m ... -c ... with COSMOS_API_KEY set. The tools are search_concepts, explain, list_members, query and show_sql. Every call runs as the user who owns the token; personal data never reaches agents.
Data sources
Local Postgres: docker compose -p cosmos-semantic -f deploy/docker-compose.yml up -d, then cosmos demo-data --target postgres and cosmos reference --source postgres. To also run the tests on Postgres, set COSMOS_PG_URI=postgresql://cosmos:cosmos@localhost:15432/cosmos.
Local SQL Server: docker compose -p cosmos-semantic -f deploy/docker-compose.yml --profile sqlserver up -d and COSMOS_MSSQL_URI='mssql+pymssql://sa:Cosmos!Passw0rd@localhost:14330/master'. Every data source accepts a schema_map in connections.yml (for example public: dbo) to use the same model with different schemas.
Local MySQL, MariaDB and Oracle Database Free: docker compose -p cosmos-semantic -f deploy/docker-compose.yml --profile mysql --profile mariadb --profile oracle up -d, then COSMOS_MYSQL_URI=mysql+pymysql://root:[email protected]:13306/, COSMOS_MARIADB_URI=mysql+pymysql://root:[email protected]:13307/, COSMOS_ORACLE_DSN=127.0.0.1:11521/FREEPDB1 and COSMOS_ORACLE_PASSWORD=cosmos. Once the Oracle container is healthy, run deploy/oracle-setup.sql as SYSTEM (the command is in the file). In Oracle a schema is a user, so an Oracle source maps the model's public to its owner (schema_map: { public: cosmos }).
Databricks: set DATABRICKS_HTTP_PATH (SQL warehouse) and DATABRICKS_TOKEN with DATABRICKS_SERVER_HOSTNAME, or DATABRICKS_CONFIG_PROFILE with a Databricks CLI profile (databricks auth login --profile <name>). The tests load the example data into the catalog in DATABRICKS_CATALOG (default cosmos_demo, which must exist). On Git Bash for Windows, also set MSYS_NO_PATHCONV=1, or the shell rewrites /sql/1.0/... into a Windows path and the warehouse answers 404.
Snowflake: set SNOWFLAKE_ACCOUNT (<org>-<account>), SNOWFLAKE_USER and SNOWFLAKE_PRIVATE_KEY_FILE (key-pair login), or SNOWFLAKE_CONNECTION_NAME with a connection from ~/.snowflake/connections.toml; plus SNOWFLAKE_ROLE and SNOWFLAKE_WAREHOUSE. The tests load the example data into SNOWFLAKE_DATABASE (default COSMOS_DEMO). deploy/snowflake-setup.sql creates the warehouse, database, role and service user they need.
Editors validate and autocomplete model files through the JSON Schema in schema/, referenced on the first line of each file (# yaml-language-server: $schema=...). After changing spec.py, regenerate it with uv run cosmos schema -o schema/cosmos-semantic.v1.schema.json.
Principles
- The engine is ours. The semantic model, metric planner and SQL generation are the core of the product.
- Compatible, not dependent. Cube, dbt and Ossie are import and export formats.
- Query the source directly. No intermediate infrastructure in the MVP; caching comes later.
- Same number everywhere. The same request returns the same result on every supported database.
- One differentiator per phase. Scope only grows after it is validated.
- Open core. Everything that defines or computes a number is Apache 2.0; the paid part covers enterprise identity, auditing, managed operations and support.
Documentation
Repository layout
License and contributing
The core is licensed under Apache 2.0 (ADR 0005). Contributions are welcome under the Developer Certificate of Origin; see CONTRIBUTING.md. Report vulnerabilities privately as described in SECURITY.md.
Source: README.md at commit a058eb9
Tools
0Version history
1- v0.3.0LatestNov 5, 2026
Score
50% of the applicable checks met
How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.
- Reached in the last 30 days25 pts
Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.
- Auth declared10 pts
Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.
- Tools listed15 pts
Answer tools/list without a credential, or ship a package that starts in a sandbox without one.
- DescriptionRequired15 pts
- Logo10 pts
- Documentation15 pts
- License10 pts
