|
| 1 | +--- |
| 2 | +description: Connect your AI Agent with Semaphore using an MCP Server |
| 3 | +sidebar_position: 1 |
| 4 | +--- |
| 5 | + |
| 6 | +# MCP Server |
| 7 | + |
| 8 | +This page explains how Semaphore's MCP Server works, how to configure your clients/agents, and what capabilities are available. |
| 9 | + |
| 10 | +:::info Request access to this feature |
| 11 | + |
| 12 | +If you want to try the MCP Server, contact `support@semaphore.io` so we can enable this feature in your organization at no cost. |
| 13 | + |
| 14 | +::: |
| 15 | + |
| 16 | +## Overview |
| 17 | + |
| 18 | +[MCP servers](https://modelcontextprotocol.info/) (Model Context Protocol servers) connect AI models to external data and tools through a standardized interface. They provide structured, real-time context-like data from APIs so models can retrieve accurate information and perform actions securely and consistently. |
| 19 | + |
| 20 | +You can connect your favorite AI agent with Semaphore using the official MCP Server. This allows the AI agent or IDE to access the activity in your organization using a conversational interface. |
| 21 | + |
| 22 | +With MCP, you can now ask your AI agent why your build failed and to provide a fix. |
| 23 | + |
| 24 | +## MCP Server Capabilities {#tools} |
| 25 | + |
| 26 | +Semaphore's MCP Server provides **read-only access** to your Semaphore organization via the following tools: |
| 27 | + |
| 28 | +- `echo`: Returns the provided `message` verbatim (handy for smoke tests) |
| 29 | +- `organizations_list`: Lists organizations that the user can access |
| 30 | +- `projects_list`: List projects that belong to a specific organization |
| 31 | +- `projects_search`: Search projects inside an organization by project name, repository URL, or description |
| 32 | +- `workflows_search`: Search recent workflows for a project (most recent first) |
| 33 | +- `pipelines_list`: List pipelines associated with a workflow (most recent first) |
| 34 | +- `pipeline_jobs`: List jobs belonging to a specific pipeline |
| 35 | +- `jobs_describe`: Describes a job, surfacing agent details, and lifecycle timestamps |
| 36 | +- `jobs_logs`: Fetches job logs. For cloud jobs, it streams loghub events. For self-hosted jobs, returns a URL where logs can be fetched |
| 37 | + |
| 38 | +See [example prompts](#examples) to see a bit of what's possible. |
| 39 | + |
| 40 | +## Configure your AI Agent or IDE |
| 41 | + |
| 42 | +Access to the MCP Server is controlled via an API Token. You can obtain your API token in two ways: |
| 43 | + |
| 44 | +- [Personal API Token](../user-management#profile-token): if you don't know your personal API token, you can reset it and obtain a new one |
| 45 | +- [Service Account](../service-accounts): create a service account with *Member* role and use its API token |
| 46 | + |
| 47 | +Both types of tokens are used to communicate with the Semaphore MCP Server endpoint: `https://mcp.semaphoreci.com/mcp` |
| 48 | + |
| 49 | +If you have problems connecting to the MCP Server, see [troubleshooting](#troubleshooting). |
| 50 | + |
| 51 | + |
| 52 | +### Claude Code {#claude-code} |
| 53 | + |
| 54 | +<Steps> |
| 55 | + |
| 56 | +1. Export an environment variable with your API token |
| 57 | + |
| 58 | + ```shell |
| 59 | + export SEMAPHORE_API_TOKEN=my-token |
| 60 | + ``` |
| 61 | + |
| 62 | +2. Add the MCP Server to Claude Code |
| 63 | + |
| 64 | + ```shell |
| 65 | + claude mcp add semaphore https://mcp.semaphoreci.com/mcp \ |
| 66 | + --scope user --transport http \ |
| 67 | + --header "Authorization: Bearer $SEMAPHORE_API_TOKEN" |
| 68 | + ``` |
| 69 | + |
| 70 | +3. If you have a session open, restart Claude Code |
| 71 | + |
| 72 | +</Steps> |
| 73 | + |
| 74 | +### OpenAI's Codex {#codex} |
| 75 | + |
| 76 | +<Steps> |
| 77 | + |
| 78 | +1. Open `$HOME/.codex/config.toml` and add the following lines to the config file |
| 79 | + |
| 80 | + |
| 81 | + ```toml title="Semaphore MCP Configuration for Codex" |
| 82 | + [mcp_servers.semaphore] |
| 83 | + url = "https://mcp.semaphoreci.com/mcp" |
| 84 | + bearer_token_env_var = "SEMAPHORE_API_TOKEN" |
| 85 | + startup_timeout_sec = 30 |
| 86 | + tool_timeout_sec = 300 |
| 87 | + ``` |
| 88 | + |
| 89 | + :::note Environment variable name |
| 90 | + |
| 91 | + The `bearer_token_env_var` value references the name of the environment variable that contains the actual API token value. It *is not* set to the actual API token value. |
| 92 | + |
| 93 | + ::: |
| 94 | + |
| 95 | +2. Export an environment variable with your API token. The *name of the environment variable* must be equal to the `bearer_token_env_var` in the previous step. Consider adding this line to your `.bashrc` (or similar) |
| 96 | + |
| 97 | + ```shell |
| 98 | + export SEMAPHORE_API_TOKEN=my-token |
| 99 | + ``` |
| 100 | + |
| 101 | +3. Start Codex normally |
| 102 | + |
| 103 | +</Steps> |
| 104 | + |
| 105 | +### VSCode Codex Extension {#vscode-codex} |
| 106 | + |
| 107 | +<Steps> |
| 108 | + |
| 109 | +1. Install the [VSCode Codex Extension](https://developers.openai.com/codex/ide/) |
| 110 | + |
| 111 | +2. Set up Codex as shown [above in OpenAI's Codex](#codex). Alternatively, in VS Code press the Gear icon β **MCP settings** β **Open config.toml** and add the lines shown in the [Codex Setup](#codex) |
| 112 | +
|
| 113 | + ```toml title="Semaphore MCP Configuration for Codex" |
| 114 | + [mcp_servers.semaphore] |
| 115 | + url = "https://mcp.semaphoreci.com/mcp" |
| 116 | + bearer_token_env_var = "SEMAPHORE_API_TOKEN" |
| 117 | + startup_timeout_sec = 30 |
| 118 | + tool_timeout_sec = 300 |
| 119 | + ``` |
| 120 | +
|
| 121 | +3. Close VS Code |
| 122 | +
|
| 123 | +4. Export an environment variable with your API token. The *name of the environment variable* must be equal to the `bearer_token_env_var` in the `config.toml`. Consider adding this line to your `.bashrc` (or similar) |
| 124 | +
|
| 125 | + ```shell |
| 126 | + export SEMAPHORE_API_TOKEN=my-token |
| 127 | + ``` |
| 128 | +
|
| 129 | +5. Start VS Code from the command line, in the same shell session where you set the environment variable. This ensures VS Code can have access to the API token |
| 130 | +
|
| 131 | + ```shell |
| 132 | + code path/to/project |
| 133 | + ``` |
| 134 | +
|
| 135 | + :::note |
| 136 | +
|
| 137 | + Due to current limitations of the Codex extension for VS Code, if you start VS Code in any other way except from the terminal session where the SEMAPHORE_API_TOKEN variable has the correct value, the Semaphore MCP server **will not work**. |
| 138 | +
|
| 139 | + ::: |
| 140 | +
|
| 141 | +
|
| 142 | +</Steps> |
| 143 | +
|
| 144 | +## Example Prompts {#examples} |
| 145 | +
|
| 146 | +The MCP Server provides access to your Semaphore organization (assuming the MCP Server is enabled for your organization). |
| 147 | +
|
| 148 | +
|
| 149 | +Here are a few example prompts you can use to interact with your projects, pipelines, and jobs. Use them as starting points to interact with Semaphore. Some prompts might require an API Token with [Admin Role](../rbac#org-admin). |
| 150 | +
|
| 151 | +| Task | Prompt | |
| 152 | +|------|--------| |
| 153 | +| List organizations the Agent has access to | "List organizations you have access to" | |
| 154 | +| Save the organization and project IDs in `AGENTS.md` (speeds up tasks and saves tokens) | "Find the current project in Semaphore and obtain the organization id and project id. Save the values in AGENTS.md for future reference" | |
| 155 | +| Understand what the pipeline does | "Describe what my pipeline does for this project on Semaphore" | |
| 156 | +| Troubleshoot failed tests | "Help me figure out why have my test failed on Semaphore" | |
| 157 | +| Troubleshoot failed builds | "Why did my build fail?" | |
| 158 | +| Retrieve the logs for a job | "Show me the logs for the build job in the latest workflow in Semaphore" | |
| 159 | +
|
| 160 | +## Troubleshooting {#troubleshooting} |
| 161 | +
|
| 162 | +### Codex fails to connect |
| 163 | +
|
| 164 | +**Symptom**: When you start Codex, you see the following message: |
| 165 | +
|
| 166 | +```text |
| 167 | +β MCP client for `semaphore` failed to start: handshaking with MCP server failed: Send message error Transport |
| 168 | +[rmcp::transport::worker::WorkerTransport<rmcp::transport::streamable_http_client::StreamableHttpClientWorker<reqwest::async_impl::client::Client>>] error: |
| 169 | +Client error: HTTP status client error (401 Unauthorized) for url (https://mcp.semaphoreci.com/mcp), when send initialize request |
| 170 | +``` |
| 171 | +
|
| 172 | +**Solution**: This usually means the environment variable with the Semaphore API Token is not correctly loaded. Check your `config.toml` to learn what the environment variable name and ensure you are setting it correctly in your shell before starting Codex. |
| 173 | +
|
| 174 | +
|
| 175 | +### VS Code fails to connect |
| 176 | +
|
| 177 | +**Symptom**: Your Codex extension in VS Code fails to connect with the MCP server. |
| 178 | +
|
| 179 | +**Solution**: This usually means that VS Code does not have access to the environment variable with the Semaphore API Token. Ensure you have set the environment variable as per `config.toml` in your shell, and that you are actually starting VS Code from that very same shell session. Starting VS Code by any other means causes Codex to fail the connection. |
| 180 | +
|
| 181 | +## See also |
| 182 | +
|
| 183 | +- [User management](../user-management) |
| 184 | +- [Service accounts](../service-accounts) |
| 185 | +
|
| 186 | +
|
| 187 | +
|
| 188 | +
|
| 189 | +
|
0 commit comments