|
1 | 1 | --- |
2 | 2 | name: sereinflow |
3 | | -description: Connect to the SereinFlow MCP service and load its current operating guide and live capabilities. |
| 3 | +description: Connect to the SereinFlow MCP service, load its current operating guide and live capabilities, and diagnose transport, authentication, and session failures with evidence. |
4 | 4 | --- |
5 | 5 |
|
6 | 6 | # SereinFlow MCP |
@@ -41,25 +41,157 @@ and `mcp_servers.<id>.env_vars` is for stdio servers; neither is a replacement |
41 | 41 | for the HTTP bearer-token setting. Use the Codex credential/environment |
42 | 42 | injection supported by the host, then restart Codex or start a new task. |
43 | 43 |
|
44 | | -## Connection diagnostics |
| 44 | +## Connection lifecycle and diagnostics |
45 | 45 |
|
46 | | -Only an authenticated MCP session can provide a meaningful live catalog. |
47 | | -An empty `resources/list` or `resources/templates/list` result from a client |
48 | | -session that did not complete `initialize` is not evidence that the server has |
49 | | -no resources. Do not infer the server's listening state from those lists. |
| 46 | +Treat connection health as four separate layers. Do not collapse a transport |
| 47 | +error from the Codex MCP client into a conclusion about the SereinFlow service: |
50 | 48 |
|
51 | | -Use these bounded distinctions when diagnosing the configured HTTP endpoint: |
| 49 | +1. **Transport**: can the configured host and route be reached? |
| 50 | +2. **Authentication**: does the endpoint accept the bearer token? |
| 51 | +3. **MCP session**: did `initialize` succeed, and are the returned session and |
| 52 | + protocol headers used on follow-up requests? |
| 53 | +4. **Capabilities**: can the authenticated session read the guide and list the |
| 54 | + current tools, resources, resource templates, and prompts? |
| 55 | + |
| 56 | +The normal connection sequence is: |
| 57 | + |
| 58 | +1. Use the configured `sereinflow` MCP server. Do not send an API key in tool |
| 59 | + arguments or try to create a second authentication mechanism. |
| 60 | +2. Complete one fresh `initialize` handshake and record only non-secret |
| 61 | + evidence: status, error body category, and whether `MCP-Session-Id` was |
| 62 | + returned. Do not print the bearer token, full authorization header, or any |
| 63 | + secret-bearing response fields. |
| 64 | +3. For every request after `initialize`, preserve the returned |
| 65 | + `MCP-Session-Id` and send `MCP-Protocol-Version: 2025-03-26` (header names |
| 66 | + are case-insensitive). If a session is stale or the server reports a |
| 67 | + missing protocol/session header, create a fresh session and retry the |
| 68 | + read-only request once. |
| 69 | +4. Read `initialize.instructions`, then `sereinflow://ai/guide`, and only the |
| 70 | + relevant capability resource. A successful `initialize` alone proves only |
| 71 | + that a session was created; it is not a full health check. |
| 72 | +5. Verify the session with the current capability catalogs: `tools/list`, |
| 73 | + `resources/list`, `resources/templates/list`, and `prompts/list`. Record |
| 74 | + successful result counts when available. An empty catalog is meaningful only |
| 75 | + after a successful authenticated `initialize` and a successful catalog |
| 76 | + response. |
| 77 | + |
| 78 | +When the MCP client reports an ambiguous failure, or when a user asks whether |
| 79 | +the service is connected, perform a bounded direct HTTP comparison against the |
| 80 | +same configured endpoint if shell/network diagnostics are available. Label |
| 81 | +every observation as either `Codex MCP client` or `direct probe`; a successful |
| 82 | +PowerShell probe proves the service and key work for that PowerShell process, |
| 83 | +not that an already-running Codex process has loaded the same environment. |
| 84 | +Keep the API key in the process environment and report only presence/absence |
| 85 | +and status classes. |
| 86 | + |
| 87 | +For a direct probe, use the configured URL and this sequence: |
| 88 | + |
| 89 | +1. `GET /mcp`: `405 Method Not Allowed` is expected and proves that the |
| 90 | + listener and route are reachable; it is not an MCP failure. MCP requests |
| 91 | + use `POST`. |
| 92 | +2. Unauthenticated `POST initialize`: `401` with |
| 93 | + `WWW-Authenticate: Bearer` proves that the route is reachable and bearer |
| 94 | + authentication is enforced. Never use this result alone to claim the key is |
| 95 | + invalid. |
| 96 | +3. Authenticated `POST initialize`: `200` plus a session ID proves that the |
| 97 | + endpoint accepted the key and created an MCP session. Capture the session ID |
| 98 | + internally, but do not expose it as a credential or log it in full. |
| 99 | +4. Authenticated follow-up catalog requests with both the session ID and |
| 100 | + `MCP-Protocol-Version: 2025-03-26`: successful `200` responses prove that |
| 101 | + the session can use the MCP API. Read the guide resource as a final |
| 102 | + application-level check. |
| 103 | + |
| 104 | +The diagnostic initialize payload must be a valid MCP JSON-RPC request, for |
| 105 | +example: |
| 106 | + |
| 107 | +```json |
| 108 | +{ |
| 109 | + "jsonrpc": "2.0", |
| 110 | + "id": "diagnostic-initialize", |
| 111 | + "method": "initialize", |
| 112 | + "params": { |
| 113 | + "protocolVersion": "2025-03-26", |
| 114 | + "capabilities": {}, |
| 115 | + "clientInfo": { |
| 116 | + "name": "codex-sereinflow-diagnostic", |
| 117 | + "version": "1.0" |
| 118 | + } |
| 119 | + } |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +For direct HTTP diagnostics, send `Content-Type: application/json` and an |
| 124 | +appropriate `Accept` header. Send `Authorization: Bearer <value>` only from |
| 125 | +the process environment; never put the value in this file, command output, |
| 126 | +task text, or a tool argument. Use the response session header on all |
| 127 | +subsequent requests. Handle either JSON or event-stream response framing when |
| 128 | +the transport allows both. |
| 129 | + |
| 130 | +Apply these bounded retry rules: |
| 131 | + |
| 132 | +- Retry connection resets, timeouts, and `502`/`503`/`504` only a small, |
| 133 | + finite number of times with short backoff while the service may be starting. |
| 134 | +- Retry `initialize`, catalog reads, and resource reads safely. Do not blindly |
| 135 | + retry a mutating `tools/call`; retry it only when the server contract says |
| 136 | + the operation is idempotent and supplies an idempotency key. |
| 137 | +- After a failed initialization, do not reuse a partial or stale session. After |
| 138 | + a client restart or server restart, establish a new session before listing |
| 139 | + capabilities. |
| 140 | +- Do not make repeated probes indefinitely. Report the attempts and the last |
| 141 | + observed status when the bounded check still fails. |
| 142 | + |
| 143 | +Use these evidence-based conclusions: |
52 | 144 |
|
53 | | -- `GET /mcp` returning `405 Method Not Allowed` means the listener and route |
54 | | - are reachable; MCP requests use `POST`. |
55 | 145 | - `POST initialize` returning `401` with `WWW-Authenticate: Bearer` means the |
56 | | - listener and route are reachable but the key is missing, invalid, expired, |
| 146 | + listener and route are reachable, but the key is missing, invalid, expired, |
57 | 147 | or revoked. |
58 | 148 | - Connection refused or a timeout means the configured host/port is not |
59 | | - reachable from the Codex process, or the API is not running there. |
| 149 | + reachable from the process performing the probe, or the API is not running |
| 150 | + there. |
60 | 151 | - `502` or `503` from a client transport is a gateway, connector, or startup |
61 | | - failure. It is not proof that a local port has no listener; retry after the |
62 | | - API is ready and report the transport status separately. |
| 152 | + failure. It is not proof that a local port has no listener; report the |
| 153 | + transport status separately. |
| 154 | +- If the direct probe reaches `GET /mcp` with `405`, gets `401` without a key, |
| 155 | + gets `200` with the configured key, and completes the follow-up catalog |
| 156 | + requests, the SereinFlow service and key are healthy. If the Codex MCP client |
| 157 | + still reports `502`, the likely fault is the Codex client/connector state or |
| 158 | + stale credential injection. Restart Codex or start a new task, then rerun the |
| 159 | + MCP handshake. |
| 160 | +- If the direct authenticated initialize returns `401`, distinguish an absent |
| 161 | + key from an invalid, expired, or revoked key without exposing the value. Do |
| 162 | + not replace it with a key in the repository, task text, or tool arguments. |
| 163 | +- If direct requests return `502`/`503`/`504`, the failure is in the service |
| 164 | + startup, gateway, or connector path. Do not state that authentication failed |
| 165 | + unless an authenticated request actually returned `401`. |
| 166 | +- If `initialize` succeeds but follow-up requests fail, suspect a missing or |
| 167 | + stale `MCP-Session-Id`, a missing `MCP-Protocol-Version`, an expired session, |
| 168 | + or a protocol mismatch before suspecting the API key. Establish one fresh |
| 169 | + session and retest a read-only catalog call. |
| 170 | +- If direct probing is unavailable, report the MCP client's exact observed |
| 171 | + status/error and mark service health as unverified. Do not claim the local |
| 172 | + service is down or the key is invalid based only on an unverified client |
| 173 | + error. |
| 174 | + |
| 175 | +When reporting a connection test or failure, use this compact diagnostic |
| 176 | +record so the user can distinguish the failing layer: |
| 177 | + |
| 178 | +```text |
| 179 | +Connection status: healthy | client-path-failed | auth-failed | unreachable | unknown |
| 180 | +Endpoint: <configured endpoint, without credentials> |
| 181 | +Transport: <status and evidence> |
| 182 | +Authentication: <not tested | missing/invalid | accepted> |
| 183 | +Session/protocol: <not established | session established | follow-up headers verified> |
| 184 | +Capabilities: tools=<count or ?>, resources=<count or ?>, |
| 185 | + templates=<count or ?>, prompts=<count or ?> |
| 186 | +Likely cause: <one evidence-based sentence> |
| 187 | +Next action: <one concrete action> |
| 188 | +``` |
| 189 | + |
| 190 | +Never report "connected" after only seeing a client-side `200` or an |
| 191 | +`initialize` response. Report the layer that was verified and the layer that |
| 192 | +still failed. Preserve status codes and relevant safe response headers in the |
| 193 | +diagnostic notes, but redact authorization values, API keys, session IDs, and |
| 194 | +other secrets. |
63 | 195 |
|
64 | 196 | After creating, rotating, or changing `SEREINFLOW_MCP_API_KEY`, restart the |
65 | 197 | Codex process or start a new task so the MCP client reloads its credentials. |
|
0 commit comments