
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 分
