OAuth-Protected Workspace MCP Server
Audience: Users — Developers exposing a hpilot workspace to ChatGPT, Gemini Spark, or another remote MCP client.
hpilot can optionally expose one OAuth 2.1-protected Streamable HTTP MCP endpoint that combines the installed mcp-yieldshell execution tools with workspace-scoped file tools. The endpoint is disabled unless --mcp is supplied.
Closing a client session leaves shell and file tools available to other clients and later connections. Shared execution resources are shut down when the MCP server stops.
Security warning
The endpoint grants command execution and file modification. Bind hpilot to loopback behind a trusted HTTPS reverse proxy or secure tunnel, configure a high-entropy client secret, and give the client credentials only to services you trust.
The configured OAuth client is auto-approved. hpilot does not show a browser consent page or identify an individual workspace owner. Anyone who has both the client ID and secret can complete OAuth and obtain workspace access.
The file provider confines file operations to the process working directory, but shell commands are not constrained by that file boundary. A command can read or modify anything available to the process, including mounted home-directory content or additional mounts.
Configure the OAuth client
Choose a stable client ID and generate a high-entropy client secret:
openssl rand -hex 32Store both values only in the protected home config:
# ~/.hpilot/config.yaml
mcp:
client_id: hpilot-workspace
client_secret: paste-the-generated-secret-herehpilot reads OAuth credentials only from ~/.hpilot/config.yaml. Configure both values in that file.
If either value is empty or missing, hpilot serve --mcp reports the missing setting before it opens a listener.
Start the server
For a local client:
hpilot serve --mcpFor ChatGPT or Gemini Spark, publish the listener through HTTPS and tell hpilot its exact external MCP URL:
hpilot serve --mcp \
--mcp-host 127.0.0.1 \
--mcp-port 8766 \
--mcp-public-url https://workspace.example.com/mcpThere is no hpilot HTML authorization page. Supplying the configured client credentials to the MCP client is the approval decision.
Options
| Option | Default | Description |
|---|---|---|
--mcp | disabled | Enable the OAuth-protected MCP listener. |
--mcp-host HOST | 127.0.0.1 with a Unix daemon; effective daemon host with TCP | Address on which the independent MCP HTTP listener binds. |
--mcp-port PORT | 8766 | TCP port for the MCP listener. |
--mcp-public-url URL | derived local http://HOST:PORT/mcp URL | Canonical URL used for OAuth issuer, audience, discovery, redirects, and proxy host allowlisting; required unless the MCP host is localhost or 127.0.0.1, and otherwise must be an externally reachable HTTPS URL ending in /mcp. |
--mcp-allowed-origin ORIGIN | built-in local and public URL origins | Add an allowed browser Origin; repeat the option for multiple origins. |
MCP options without --mcp are rejected. In Unix daemon mode an omitted --mcp-host is always 127.0.0.1; in TCP daemon mode it inherits the effective daemon host. MCP remains a separate HTTP listener and never enables a daemon TCP listener. The default bind posture is loopback. The MCP SDK permits a local HTTP OAuth issuer only for localhost and 127.0.0.1; any other inherited or explicit host, including another loopback address, requires --mcp-public-url with an externally reachable HTTPS URL. A public URL must not contain credentials, whitespace, a query, or a fragment.
Startup output
With MCP enabled, startup reports the internal listener, canonical OAuth resource URL, and authentication mode without printing either client credential:
Daemon listening on unix:///workspace/project/.hpilot/run/daemon.sock
MCP listening on http://127.0.0.1:8766/mcp
MCP OAuth resource URL: https://workspace.example.com/mcp
MCP OAuth 2.1 authentication is required.Check local liveness without authentication:
curl -fsS http://127.0.0.1:8766/healthz
# {"status":"ok"}If the workspace root is the home directory or a filesystem root, startup prints an additional warning because the file boundary then protects little. Start from a project directory instead. If either the WebSocket or MCP listener cannot bind, startup fails rather than leaving a WebSocket-only daemon running; an unexpected runtime failure in either listener triggers coordinated teardown of both. Without --mcp, no MCP listener is created and the WebSocket daemon behaves as before.
OAuth endpoints and lifecycle
hpilot implements authorization-code OAuth with S256 PKCE, confidential-client authentication, and RFC 8707 resource indicators. It exposes these public endpoints on the same origin as /mcp:
| Endpoint | Purpose |
|---|---|
/.well-known/oauth-protected-resource/mcp | RFC 9728 protected-resource metadata for the canonical /mcp resource. |
/.well-known/oauth-protected-resource | Compatibility alias for clients that probe origin-level protected-resource metadata first. |
/.well-known/oauth-authorization-server | Authorization-server metadata advertising client_secret_post and S256 PKCE. |
/authorize | Validates the configured client ID, resource, scope, PKCE challenge, and secure callback, then immediately redirects with an authorization code. |
/token | Exchanges a code or refresh token after verifying the configured client secret. |
Dynamic client registration is disabled and /register is not exposed. There is no consent endpoint or HTML form.
The /mcp endpoint returns 401 Unauthorized with a WWW-Authenticate challenge containing the protected-resource metadata URL when an OAuth access token is missing or invalid. The access token is bound to the exact canonical resource URL and requires the workspace scope.
Access tokens expire after one hour. Clients requesting offline_access receive a refresh token that expires after 30 days and rotates on every use. Hashed refresh-token records persist in an owner-only file under ~/.hpilot/oauth/, so linked clients survive a hpilot restart. Client credentials remain only in ~/.hpilot/config.yaml and are not copied into OAuth state.
Changing the client ID or secret invalidates existing access and refresh tokens. Update the client configuration in ChatGPT or Gemini Spark and reconnect after rotation.
Network deployment
hpilot does not create firewall rules, public URLs, tunnels, or TLS certificates. A remote client must reach every OAuth and MCP endpoint through the same trusted HTTPS reverse proxy or secure tunnel.
Forward /.well-known/*, /authorize, /token, /mcp, and /healthz to the hpilot listener. Preserve the external Host header or rewrite it to the bound host; hpilot allows both the configured public host and local bind hosts. Forward Authorization unchanged. Do not cache authorization, token, or MCP responses.
Binding to a non-loopback address makes the listener reachable on the selected network interface. It does not authenticate the network or provision TLS. Prefer loopback binding when the proxy runs on the same host.
What to enter in ChatGPT and Gemini Spark
Use the exact same pair from ~/.hpilot/config.yaml in either client:
| Client field | Value |
|---|---|
| MCP server URL | https://workspace.example.com/mcp, matching --mcp-public-url exactly |
| Client ID | The exact mcp.client_id value, such as hpilot-workspace |
| Client secret | The exact mcp.client_secret value generated above |
| Authorization URL, if requested | https://workspace.example.com/authorize |
| Token URL, if requested | https://workspace.example.com/token |
| Scopes, if requested | workspace offline_access |
| Token authentication method, if requested | Client secret in POST body (client_secret_post) |
| PKCE, if requested | Enabled, S256 |
For ChatGPT, choose predefined or manual OAuth credentials rather than dynamic client registration. Enter the MCP URL and the configured client ID and secret. ChatGPT can discover the authorization and token URLs from hpilot's metadata.
For Gemini Spark, open Advanced features when adding the custom app and enter the configured client ID and secret. The URL-only flow is for servers that support dynamic client registration; hpilot intentionally does not.
If either product retains metadata or credentials from an older connection, delete that connection and create it again.
Endpoint and tools
Register the single Streamable HTTP URL ending in /mcp; the deprecated HTTP-plus-SSE compatibility endpoint is not enabled. Initialization identifies the server as hpilot-workspace and reports the running hpilot version.
Server-wide initialization instructions identify regular ChatGPT Chat conversations as the intended audience and instruct Codex not to invoke the integration's tools. Tool descriptions remain unchanged. This is guidance for the model, not an access restriction or a change to the app description stored in ChatGPT. Clients that expose initialization instructions can use this guidance; hosted plugin connections may omit it even after refreshing or recreating the plugin. Use request metadata diagnostics to investigate whether requests from different products can be distinguished.
The endpoint discovers and exposes the installed yieldshell provider's complete tool registry at startup without a hpilot-owned tool allowlist. Each upstream name receives the yieldshell_ namespace, while its description and input schema remain provider-defined. Clients should treat the MCP tools/list response as authoritative.
yieldshell_execute requires a non-empty side_effects list. Declare every category that may apply; use ["NONE"] only when the command has no meaningful side effect, and never combine NONE with another value. The provider's default policy rejects several high-risk categories, including inline-code execution, protected-file changes, OS or user-setting changes, and killing an agent process, before the command starts.
The namespaced file tools are:
file_readreads bounded UTF-8 content and can select line or byte ranges.file_writeatomically creates or replaces a text file.file_editreplaces an exact text fragment only when the expected occurrence count matches.
Use yieldshell for file discovery and content search, file_read for an already-known path, and file_write or file_edit for structured modification. tools/list exposes exactly these three file_ tools plus the yieldshell_ registry; any other file_ name returns an unknown-tool error — reconnect to refresh a cached tool list.
For read-only discovery and search, call yieldshell_execute with arguments such as:
[
{"command":"rg --files","side_effects":["NONE"]},
{"command":"rg -n -F 'symbol' .","side_effects":["NONE"]},
{"command":"find . -name '*.py'","side_effects":["NONE"]},
{"command":"git grep -n 'symbol'","side_effects":["NONE"]},
{"command":"ls -la src/","side_effects":["NONE"]}
]Prefer rg where it is available because it provides efficient traversal and ignore handling, but it is not required; find, git grep, grep, and ls remain valid alternatives.
hpilot preserves annotations supplied by yieldshell. File tool annotations identify read-only, modifying, destructive, and idempotent operations. File tool names use the file_ namespace so they cannot collide with yieldshell names. hpilot admits at most four blocking file operations to dedicated worker threads at once; queued requests wait asynchronously, a cancelled request that has not been admitted does not start, and a modifying operation that already started is allowed to finish its atomic durability work. hpilot never retries an MCP tool call after an ambiguous transport result.
Workspace isolation
The current working directory of hpilot serve is the root for MCP file tools.
Every file path is normalized, resolved through intermediate and final symlinks, and checked against the workspace root before the operation runs. Relative traversal, outside absolute paths, and symlink escapes are rejected.
Writes use a temporary file in the target directory followed by an atomic replacement where the filesystem supports it. File errors returned to clients do not expose host filesystem paths or Python tracebacks.
Yieldshell commands default to the workspace root, and a requested command working directory must remain within that root, but the shell itself can still use absolute paths or mounted resources outside it. The file boundary therefore applies only to file tools; use a separate project directory and avoid running from your home directory.
Health, authentication, and errors
GET /healthz is unauthenticated and returns only basic liveness. It does not list tools, workspace paths, configuration, or credentials. The default maximum MCP request body is 4 MiB and is not a CLI option.
401 Unauthorizedfrom/mcpmeans the OAuth access token is missing, expired, malformed, or issued for another public URL; follow theWWW-Authenticatemetadata link and reconnect.401 Unauthorizedfrom/tokenusually means the client ID or client secret is invalid.403 Forbiddenmeans a supplied browserOriginis not on the configured allowlist.421 Misdirected Requestmeans the HTTPHostheader matches neither the bound listener nor--mcp-public-url.400 Bad Requestfrom an OAuth endpoint usually means a redirect URI, scope, PKCE value, resource, code, or refresh token is invalid.400 Bad Requestor415 Unsupported Media Typefrom/mcpcommonly means invalid MCP JSON orContent-Type.413 Request Entity Too Largemeans the configured maximum request body size was exceeded.
Authentication failures are rate-limited in persistent structured logs written to .hpilot/logs/services/mcp.jsonl. Tool output, OAuth tokens, and client secrets are not recorded by request logging.
MCP request metadata diagnostics
Every HTTP request reaching the MCP observer at /mcp writes an mcp_http_request event to .hpilot/logs/services/mcp.jsonl when its response starts, including long-lived streaming responses. Each event includes a server-generated request_id, http_method, status_code, selected headers, header_names, and session_id_hash. POST events also include rpc_method, rpc_meta_keys, and params_meta_keys when the body is a JSON object. Requests rejected by the outer host/origin checks are not observed; requests that fail or disconnect before a response starts have a null status_code.
Initialization additionally writes an mcp_client_initialize event containing the same request_id, protocol_version, client_info (name, version, and optional title), and top-level capability names. Join the two events by request_id; use session_id_hash from the HTTP event to correlate subsequent requests. The hash is the first 16 hexadecimal characters of SHA-256 of the transport session ID. The raw session ID is never recorded. Initialization events describe a received attempt, so check the associated HTTP status before treating it as a successful connection.
Header values are limited to user-agent, accept, content-type, mcp-protocol-version, origin, x-openai-client-name, x-openai-client-version, x-openai-product, x-openai-product-sku, x-openai-surface, x-mcp-client-name, and x-mcp-client-version. These are diagnostic candidates, not a claim that any client sends them. Origin values exclude user information, paths, queries, and fragments. Other headers contribute names only, allowing new routing hints to be discovered without dumping their values. Metadata strings are limited to 256 characters with control characters replaced; key/header-name lists are limited to 64 entries, and header_names_truncated indicates additional HTTP headers.
These request events omit authorization and cookie values, query strings, IP addresses, JSON-RPC IDs, tool arguments, and arbitrary _meta, capability, or client-info values. Existing tool-call events still follow the separate argument logging rules below. Do not put secrets in client identity strings or the explicitly selected diagnostic headers.
To compare ChatGPT Chat and Codex without changing access rules:
Deploy the updated server through its normal deployment process. No extra logging flag is required.
Follow only metadata events from the server's working directory:
bashtail -n 0 -f .hpilot/logs/services/mcp.jsonl | jq --unbuffered -c 'select(.event == "mcp_http_request" or .event == "mcp_client_initialize")'Record the time, then make one harmless read from a ChatGPT Chat conversation with the plugin selected. Repeat separately from Codex. Do not rely on a fresh conversation to create a new MCP session: hosted connections can reuse sessions, so compare HTTP events too.
Compare
client_info,headers,header_names, and metadata key names across both labeled samples. A hosted gateway may give both products the same identity. Header and MCP client-info strings are client-supplied hints, not authenticated proof of the originating product.Add a blocking rule only after observing a consistent distinguishing signal and checking that it does not also identify ChatGPT Chat. These diagnostics do not block any client. If both products use identical gateway metadata, these fields cannot support a selective Codex block.
MCP tool-call logging
hpilot records each MCP call in .hpilot/logs/services/mcp.jsonl as a start event followed by either a completion or failure event. The start and outcome records share one full correlation_id, so you can match a request with its duration and any failure details.
Follow the structured records while the server is running:
tail -f .hpilot/logs/services/mcp.jsonlEach record contains timestamp and event. Start records contain exactly one tool-name field, tool, plus correlation_id and a sanitized arguments object. Completion records contain tool, correlation_id, and duration_ms. Failure records contain those fields plus an error object with a short category and message. The legacy tool_name, params, and success fields are not emitted.
The start record keeps the original argument names and insertion order, and the same sanitized arguments feed both JSONL and the human-readable stderr message. With normal (non-quiet) stderr logging, a call looks like this:
INFO | tool call: file_read
path: notes.txt
start_line: 1
end_line: 100Arguments stay independent: line and byte ranges are not merged into range, and timeout or output limits are not merged into limits. Flat scalar lists render as comma-separated values, and multiline values show the field name on its own line with the body indented below it. Successful calls do not produce a routine completion line on stderr; use the JSONL completion record for duration and correlation.
Logging sanitizes recorded arguments without changing the MCP request or its result:
- Whole-file
content, shellstdin, and interactiveinputvalues become placeholders such as<omitted, 512 bytes>on both stderr and JSONL. envandenvironmentmappings become placeholders such as<omitted, 3 variables>; their values are not recorded.- Credential-named fields, including headers, authorization, access or refresh tokens, API keys, passwords, secrets, and cookies, become
<redacted>, including when they occur in bounded nested mappings. - Unsupported or excessively deep values become an opaque
<omitted>placeholder instead of being serialized without a bound. file_editold_textandnew_textremain visible in full by design, so do not put credentials in edit text.- Other scalar fields, including
commandandpath, remain visible; logging does not inspect secret-like text embedded in those strings.
The logger catches failures in sanitization, rendering, and log writing so an observability problem cannot change, stall, or replace the MCP tool call. --quiet suppresses the human-readable stderr block but does not disable the structured JSONL records.
Troubleshooting checklist
- Confirm both
mcp.client_idandmcp.client_secretare non-empty in~/.hpilot/config.yaml. - Confirm the client contains the exact same ID and secret; do not use the old
mcp.tokenvalue as a bearer token. - Confirm
--mcp-public-urlexactly matches the externally reachable HTTPS URL entered in the client, including/mcp. - Confirm the proxy forwards every OAuth discovery and flow endpoint, not only
/mcp. - Fetch
/.well-known/oauth-protected-resource/mcpand/.well-known/oauth-authorization-serverthrough the public hostname and verify that every returned URL uses that same public origin. - Confirm the client requests
workspace offline_access, uses S256 PKCE, and authenticates the token request withclient_secret_post. - For Gemini Spark, use Advanced features and enter the credentials instead of relying on URL-only dynamic registration.
- Relink the client after rotating credentials or changing the public URL.
- Check allowed
HostandOriginvalues, proxy caching, and listener port conflicts. - If file access is rejected, check the effective process working directory and remember that extra mounts are not automatically file-provider roots.
- If the client reports an unknown tool, reconnect to refresh
tools/list; the file surface is exactlyfile_read,file_write, andfile_editplus theyieldshell_registry and discovery/search now useyieldshell_executeas described above.