
Cosmos Semantic
io.github.WiliamRosa由 GitHub 帳號 WiliamRosa 發布v0.3.0更新於 Nov 5, 2026
Governed metrics, business rules and a glossary for AI agents, with evidence on every answer.
概覽
Cosmos Semantic 透過 MCP 提供受治理的語意層,讓助理查詢已定義的指標與業務規則,而不是自行猜寫 SQL,並為每個答案附上佐證。
- 可以做什麼
- 搜尋並解釋語意模型中的概念、指標與業務規則
- 列出模型中可用的成員(指標、維度、規則)
- 依維度、規則篩選與指定參考日期執行指標查詢,回傳確定性的 SQL
- 顯示查詢產生的 SQL
- 每個答案都附上展開的公式、規則、資料列篩選、參考日期與雜湊,並以權杖所屬使用者身分執行
- 適用情境
- 當助理需要從資料倉儲或資料庫取得可信的業務數字,且你已維護(或願意定義)包含指標、規則與詞彙表的語意模型,而不希望模型臨時撰寫 SQL 時使用。
- 執行需求
- 本機 Python 套件,以 uvx 執行(需 Python 3.11+);需要語意模型與目標資料庫的連線設定檔(DuckDB、Postgres、SQL Server、MySQL/MariaDB、Oracle、Databricks、Snowflake);stdio 傳輸需設定 COSMOS_API_KEY 環境變數;需能連線至資料來源。REST/MCP 服務模式使用 OIDC 設定或 COSMOS_DEV_API_KEYS。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Cosmos Semantic,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
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.
來源:README.md,提交 a058eb9
工具
0版本歷史
1- v0.3.0最新Nov 5, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分
