KosmoKrator

analytics

Segment CLI for AI Agents

Use the Segment CLI from KosmoKrator to call Segment tools headlessly, return JSON, inspect schemas, and automate workflows from coding agents, scripts, and CI.

8 functions 4 read 4 write API token auth

Segment CLI Setup

Segment can be configured headlessly with `kosmokrator integrations:configure segment`.

# Install KosmoKrator first if it is not available on PATH.
curl -fsSL https://raw.githubusercontent.com/OpenCompanyApp/kosmokrator/main/install.sh | bash

# Configure and verify this integration.
kosmokrator integrations:configure segment --set write_key="$SEGMENT_WRITE_KEY" --enable --read allow --write ask --json
kosmokrator integrations:doctor segment --json
kosmokrator integrations:status --json

Credentials

Authentication type: API token api_token. Configure credentials once, then use the same stored profile from scripts, coding CLIs, Lua code mode, and the MCP gateway.

KeyEnv varTypeRequiredLabel
write_key SEGMENT_WRITE_KEY Secret secret yes Write Key
api_token SEGMENT_API_TOKEN Secret secret no API Token
url SEGMENT_URL URL url no API Base URL

Call Segment Headlessly

Use the generic call form when another coding CLI or script needs a stable universal interface.

kosmo integrations:call segment.segment_identify '{
  "userId": "example_userId",
  "traits": "example_traits"
}' --json

Use the provider shortcut form for shorter human-facing commands.

kosmo integrations:segment segment_identify '{
  "userId": "example_userId",
  "traits": "example_traits"
}' --json

Agent Discovery Commands

These commands return structured output for coding agents that need to inspect capabilities before choosing a function.

kosmo integrations:docs segment --json
kosmo integrations:docs segment.segment_identify --json
kosmo integrations:schema segment.segment_identify --json
kosmo integrations:search "Segment" --json
kosmo integrations:list --json

All CLI Functions

Every function below can be called headlessly. The generic form is stable across all integrations; the provider shortcut is shorter but specific to Segment.

segment.segment_identify

Write write

Identify a user in Segment with their traits. Links metadata about a user (name, email, plan, etc.) to a known userId so all their events can be attributed correctly.

Parameters
userId, traits

Generic CLI call

kosmo integrations:call segment.segment_identify '{"userId":"example_userId","traits":"example_traits"}' --json

Provider shortcut

kosmo integrations:segment segment_identify '{"userId":"example_userId","traits":"example_traits"}' --json

segment.segment_track

Write write

Track a custom event for a user in Segment. Records actions your users perform along with optional properties describing the action.

Parameters
event, userId, properties

Generic CLI call

kosmo integrations:call segment.segment_track '{"event":"example_event","userId":"example_userId","properties":"example_properties"}' --json

Provider shortcut

kosmo integrations:segment segment_track '{"event":"example_event","userId":"example_userId","properties":"example_properties"}' --json

segment.segment_page

Write write

Record a page view in Segment. Tracks when a user views a page, along with optional properties about the page.

Parameters
name, userId, properties

Generic CLI call

kosmo integrations:call segment.segment_page '{"name":"example_name","userId":"example_userId","properties":"example_properties"}' --json

Provider shortcut

kosmo integrations:segment segment_page '{"name":"example_name","userId":"example_userId","properties":"example_properties"}' --json

segment.segment_group

Write write

Associate a user with a group (organization, company, account) in Segment. Lets you record group membership along with optional group traits.

Parameters
groupId, userId, traits

Generic CLI call

kosmo integrations:call segment.segment_group '{"groupId":"example_groupId","userId":"example_userId","traits":"example_traits"}' --json

Provider shortcut

kosmo integrations:segment segment_group '{"groupId":"example_groupId","userId":"example_userId","traits":"example_traits"}' --json

segment.segment_get_workspace

Read read

Get details of a Segment workspace by its slug. Requires an API token to be configured.

Parameters
slug

Generic CLI call

kosmo integrations:call segment.segment_get_workspace '{"slug":"example_slug"}' --json

Provider shortcut

kosmo integrations:segment segment_get_workspace '{"slug":"example_slug"}' --json

segment.segment_list_sources

Read read

List all sources in a Segment workspace. Requires an API token to be configured.

Parameters
slug

Generic CLI call

kosmo integrations:call segment.segment_list_sources '{"slug":"example_slug"}' --json

Provider shortcut

kosmo integrations:segment segment_list_sources '{"slug":"example_slug"}' --json

segment.segment_get_source

Read read

Get details of a specific Segment source by ID. Requires an API token to be configured.

Parameters
slug, id

Generic CLI call

kosmo integrations:call segment.segment_get_source '{"slug":"example_slug","id":"example_id"}' --json

Provider shortcut

kosmo integrations:segment segment_get_source '{"slug":"example_slug","id":"example_id"}' --json

segment.segment_get_current_user

Read read

Get the currently authenticated Segment user. Useful for verifying API token credentials are correct.

Parameters
none

Generic CLI call

kosmo integrations:call segment.segment_get_current_user '{}' --json

Provider shortcut

kosmo integrations:segment segment_get_current_user '{}' --json

Function Schemas

Use these parameter tables when building CLI payloads without calling integrations:schema first.

segment.segment_identify

Identify a user in Segment with their traits. Links metadata about a user (name, email, plan, etc.) to a known userId so all their events can be attributed correctly.

Operation
Write write
Schema command
kosmo integrations:schema segment.segment_identify --json
ParameterTypeRequiredDescription
userId string yes The unique identifier for the user in your database.
traits object no Key-value pairs of user traits (e.g., name, email, plan, role, company).

segment.segment_track

Track a custom event for a user in Segment. Records actions your users perform along with optional properties describing the action.

Operation
Write write
Schema command
kosmo integrations:schema segment.segment_track --json
ParameterTypeRequiredDescription
event string yes The name of the event being tracked (e.g., "Order Completed", "Button Clicked").
userId string yes The unique identifier for the user in your database.
properties object no Key-value pairs of event properties (e.g., revenue, category, productId).

segment.segment_page

Record a page view in Segment. Tracks when a user views a page, along with optional properties about the page.

Operation
Write write
Schema command
kosmo integrations:schema segment.segment_page --json
ParameterTypeRequiredDescription
name string yes The name of the page viewed (e.g., "Homepage", "Product Listing").
userId string yes The unique identifier for the user in your database.
properties object no Key-value pairs of page properties (e.g., url, referrer, title, path).

segment.segment_group

Associate a user with a group (organization, company, account) in Segment. Lets you record group membership along with optional group traits.

Operation
Write write
Schema command
kosmo integrations:schema segment.segment_group --json
ParameterTypeRequiredDescription
groupId string yes The unique identifier for the group (e.g., company ID, organization ID).
userId string yes The unique identifier for the user in your database.
traits object no Key-value pairs of group traits (e.g., name, plan, industry, employee_count).

segment.segment_get_workspace

Get details of a Segment workspace by its slug. Requires an API token to be configured.

Operation
Read read
Schema command
kosmo integrations:schema segment.segment_get_workspace --json
ParameterTypeRequiredDescription
slug string yes The workspace slug (e.g., "my-workspace").

segment.segment_list_sources

List all sources in a Segment workspace. Requires an API token to be configured.

Operation
Read read
Schema command
kosmo integrations:schema segment.segment_list_sources --json
ParameterTypeRequiredDescription
slug string yes The workspace slug (e.g., "my-workspace").

segment.segment_get_source

Get details of a specific Segment source by ID. Requires an API token to be configured.

Operation
Read read
Schema command
kosmo integrations:schema segment.segment_get_source --json
ParameterTypeRequiredDescription
slug string yes The workspace slug (e.g., "my-workspace").
id string yes The source ID (e.g., "abc123").

segment.segment_get_current_user

Get the currently authenticated Segment user. Useful for verifying API token credentials are correct.

Operation
Read read
Schema command
kosmo integrations:schema segment.segment_get_current_user --json
ParameterTypeRequiredDescription
No parameters.

Permissions

Headless calls still follow the integration read/write permission policy. Configure read/write defaults with integrations:configure. Add --force only for trusted automation that should bypass that policy.