Skip to main content

Examples & API Showcases

Every SemanticFed developer repository ships runnable example applications and automated smoke tests so you can verify integration flows locally — both offline in --demo mode (no credentials required) and against a live workspace.

Example catalog​

RepositoryExampleWhat it demonstratesHow to run
semanticfed-sdk-nodeexamples/01-federated-model-and-query.tsRegistering connectors & data sources, authoring and publishing a semantic model (entities, dimensions, metrics), publishing and running a saved federated query, and reading plan/result rowsbun examples/01-federated-model-and-query.ts --demo
semanticfed-sdk-nodeexamples/02-governed-sql-and-policies.tsIntrospecting sqlCatalog(), listing active access policies, running a governed SELECT via sql(), inspecting masked column metadata, and exporting RFC-4180 CSVbun examples/02-governed-sql-and-policies.ts --demo
semanticfed-sdk-pythonexamples/basic_usage.pyMinimal async client initialization with workspace tokens, listing connectors and shared tags, and clean sdk.close() teardownuv run python examples/basic_usage.py
semanticfed-sdk-pythonexamples/federated_analytics_showcase.pyAsync Python data-pipeline / BI bridge: listing connectors and models, inspecting sql_catalog() and access_policies, running governed sql(), and exporting masked rows to CSVuv run python examples/federated_analytics_showcase.py --demo
semanticfed-mcpexamples/governed-agent-client.tsReal @modelcontextprotocol/sdk stdio client spawning semanticfed-mcp in --read-only and full mode, inspecting semanticfed:// resources & prompts, and verifying policy-write gating and destructive confirmation refusalbun examples/governed-agent-client.ts

Showcase 1: Federated semantic model & saved query (Node.js)​

semanticfed-sdk-node/examples/01-federated-model-and-query.ts walks through the full semantic modeling and governed query lifecycle:

git clone https://github.com/algoshred/semanticfed-sdk-node.git
cd semanticfed-sdk-node
bun install

# Offline demo mode (in-process GraphQL transport stub)
bun examples/01-federated-model-and-query.ts --demo

# Live workspace inspection
export SEMANTICFED_ACCESS_TOKEN="<platform-token>"
export SEMANTICFED_WORKSPACE_TOKEN="<workspace-token>"
bun examples/01-federated-model-and-query.ts

Key SDK operations exercised:

  • sdk.semanticfed.connectors.create() / list() and dataSources.create()
  • sdk.semanticfed.models.create() / publish(), entities.create(), dimensions.create(), metrics.create()
  • sdk.semanticfed.queries.create() / publish() / run()
  • sdk.semanticfed.queryRuns.get() and queryRuns.result()

Showcase 2: Governed SQL endpoint & BI CSV bridge (Node.js & Python)​

Both SDKs expose typed helpers over the read-only SQL endpoint (semSqlCatalog and semExecuteSql) so downstream BI tools and notebooks receive governed, policy-masked datasets without authoring raw GraphQL.

Node.js (examples/02-governed-sql-and-policies.ts)​

cd semanticfed-sdk-node
bun examples/02-governed-sql-and-policies.ts --demo

Python (examples/federated_analytics_showcase.py)​

git clone https://github.com/algoshred/semanticfed-sdk-python.git
cd semanticfed-sdk-python
uv sync --locked --all-extras

# Offline demo mode (respx HTTP mock)
uv run python examples/federated_analytics_showcase.py --demo

# Live workspace
export SEMANTICFED_ACCESS_TOKEN="<platform-token>"
export SEMANTICFED_WORKSPACE_TOKEN="<workspace-token>"
export SEMANTICFED_MODEL_ID="<model-id>"
uv run python examples/federated_analytics_showcase.py

Both examples output structured JSON including the discovered catalog tables, active access-policy count, masked column names, row count, truncation flag, and an RFC-4180 CSV preview.

Showcase 3: Governed MCP analyst agent (TypeScript)​

semanticfed-mcp/examples/governed-agent-client.ts connects a real MCP client (StdioClientTransport) to the semanticfed-mcp server entrypoint and verifies the server's governance guarantees end-to-end:

git clone https://github.com/algoshred/semanticfed-mcp.git
cd semanticfed-mcp
bun install
bun examples/governed-agent-client.ts

What the showcase verifies:

  1. --read-only mode exposes read tools, semanticfed:// resources, prompts, semanticfed_sql_catalog, semanticfed_sql_execute, and semanticfed_queries_run while hiding mutating tools (semanticfed_models_create, semanticfed_entities_delete, policy writes).
  2. Default full mode exposes semanticfed_access_policies_list while keeping semanticfed_access_policies_create and semanticfed_access_policies_set_active off the tool list unless --enable-policy-writes is explicitly set.
  3. Calling a destructive tool such as semanticfed_entities_delete without confirm: true is refused before any GraphQL request is dispatched.

Showcase 4: Direct GraphQL & PostgreSQL wire smoke calls​

GraphQL health and model listing (curl)​

curl -sS -X POST https://graphqlworkspaces.burdenoff.com/workspaces/graphql \
-H "Content-Type: application/json" \
-H "Origin: https://app.semanticfed.com" \
-H "Authorization: Bearer $SEMANTICFED_ACCESS_TOKEN" \
-H "X-Workspace-Authorization: Bearer $SEMANTICFED_WORKSPACE_TOKEN" \
-H "x-workspace-id: $WORKSPACE_ID" \
-d '{"query":"query { semHealth semListModels(pagination: { limit: 10 }) { items { id name status } } }"}'

PostgreSQL wire protocol (psql)​

PGPASSWORD="$SEMANTICFED_ACCESS_TOKEN" \
PGOPTIONS="-c semanticfed.model=$SEMANTICFED_MODEL_ID" \
psql "host=sql.semanticfed.com port=5432 dbname=$WORKSPACE_ID user=analyst sslmode=verify-full sslrootcert=system" \
-c "\dt" \
-c "SELECT region, SUM(amount) AS revenue FROM orders GROUP BY region ORDER BY revenue DESC LIMIT 10"

Continuous verification​

Every runnable example in semanticfed-sdk-node, semanticfed-sdk-python, and semanticfed-mcp is backed by automated tests executed in repository sanity checks (bun test / pytest), alongside GraphQL document validation against the production workspace supergraph (schema/wspace.graphql).

Next steps​