A Model Context Protocol (MCP) server that provides access to all Segment Public API endpoints as tools for AI assistants like Claude.
- Node.js (v18 or higher)
- npm
- A valid Segment API token
npm installExport your Segment API token as an environment variable:
export SEGMENT_API_TOKEN="your_segment_api_token_here"Add this to your shell profile (~/.zshrc, ~/.bashrc, etc.) to make it persistent:
echo 'export SEGMENT_API_TOKEN="your_segment_api_token_here"' >> ~/.zshrc
source ~/.zshrcnpm run buildThis compiles the TypeScript source code to JavaScript in the build/ directory.
The MCP Inspector provides a web interface to test your server:
SEGMENT_API_TOKEN="YOUR_PAPI_TOKEN" npx @modelcontextprotocol/inspector node build/index.jsThis will:
- Start the MCP server
- Launch a web interface (usually at
http://localhost:6274) - Allow you to test individual tools and see all available Segment API endpoints
If your build of src/index.ts starts an Express HTTP server (streamable HTTP transport or a custom HTTP endpoint), run the compiled server directly:
- Build the project
npm run build- Start the server (temporary env var for this run)
SEGMENT_API_TOKEN="YOUR_PAPI_TOKEN" npm start
# or
SEGMENT_API_TOKEN="YOUR_PAPI_TOKEN" node build/index.js- Open the server in your browser
- The server will log the listening address/port when it starts. Default port used in examples is
8000, so try: - If no port appears in the logs, check src/index.ts for the configured port or the "streamableHttp" host/port printed at startup.
The config file is located at:
~/Library/Application Support/Claude/claude_desktop_config.json
Add your server to the mcpServers section:
{
"mcpServers": {
"segment-public-api": {
"command": "node",
"args": ["/absolute/path/to/your/project/build/index.js"],
"env": {
"SEGMENT_API_TOKEN": "your_segment_api_token_here"
}
}
}
}Replace /absolute/path/to/your/project/ with the actual path to this project directory.
Quit and restart Claude Desktop to load the new configuration.
Once installed, you can ask Claude to:
- List your Segment workspaces
- Get information about sources and destinations
- Create audiences and computed traits
- Manage user permissions
- Access any of the 200+ Segment Public API endpoints
Example prompts:
- "List my Segment workspaces"
- "Show me all sources in my workspace"
- "Create a new audience in space [space-id]"
src/
index.ts # Main MCP server implementation
build/
index.js # Compiled JavaScript (generated)
package.json # Dependencies and build scripts
tsconfig.json # TypeScript configuration
- Edit the TypeScript source in
src/index.ts - Rebuild the project:
npm run build - Test with the inspector:
SEGMENT_API_TOKEN="YOUR_PAPI_TOKEN" npx @modelcontextprotocol/inspector node build/index.js - Restart Claude Desktop to use the updated server
This usually means the SEGMENT_API_TOKEN is not properly set:
- Verify the token is set:
echo $SEGMENT_API_TOKEN - Use the explicit
envblock in Claude's config (recommended)
If you get "PORT IS IN USE" errors:
# Kill existing inspector processes
pkill -f "inspector"
# Wait a moment, then try again
SEGMENT_API_TOKEN="YOUR_PAPI_TOKEN" npx @modelcontextprotocol/inspector node build/index.jsMake sure all dependencies are installed:
npm install
npm run buildThis server provides access to all Segment Public API endpoints. Each API endpoint becomes an available tool in Claude with:
- Automatic request validation
- Proper authentication headers
- Error handling and response formatting
- Full parameter support as defined in the Segment OpenAPI specification
For complete API documentation, visit: Segment API Documentation