fix: harden self-hosted stdio startup validation#83
Merged
Conversation
Probe multiple Appwrite services at startup, normalize endpoints, and surface clear stderr errors so MCP clients no longer fail with opaque -32000 reconnects when the first tables_db probe fails or credentials are misconfigured. Co-authored-by: Cursor <cursoragent@cursor.com>
Greptile SummaryThis PR makes self-hosted stdio startup failures easier to diagnose. The main changes are:
Confidence Score: 4/5The endpoint normalization path needs a fix before merging.
src/mcp_server_appwrite/server.py Important Files Changed
Prompt To Fix All With AIFix the following 1 code review issue. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 1
src/mcp_server_appwrite/server.py:179
**Endpoint Paths Diverge By Transport**
When `APPWRITE_ENDPOINT` is set to a bare self-hosted host such as `http://localhost:9501`, this stdio config path now normalizes it to `/v1`, but the HTTP/OAuth paths still read the raw environment value. Stdio startup can pass while OAuth issuer and request clients use the wrong base path, so the same documented endpoint value can fail outside stdio.
Reviews (1): Last reviewed commit: "fix: harden self-hosted stdio startup va..." | Re-trigger Greptile |
| project_id = os.getenv("APPWRITE_PROJECT_ID") | ||
| api_key = os.getenv("APPWRITE_API_KEY") | ||
| endpoint = os.getenv("APPWRITE_ENDPOINT", DEFAULT_ENDPOINT) | ||
| endpoint = _normalize_endpoint(os.getenv("APPWRITE_ENDPOINT", DEFAULT_ENDPOINT)) |
There was a problem hiding this comment.
Endpoint Paths Diverge By Transport
When APPWRITE_ENDPOINT is set to a bare self-hosted host such as http://localhost:9501, this stdio config path now normalizes it to /v1, but the HTTP/OAuth paths still read the raw environment value. Stdio startup can pass while OAuth issuer and request clients use the wrong base path, so the same documented endpoint value can fail outside stdio.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/mcp_server_appwrite/server.py
Line: 179
Comment:
**Endpoint Paths Diverge By Transport**
When `APPWRITE_ENDPOINT` is set to a bare self-hosted host such as `http://localhost:9501`, this stdio config path now normalizes it to `/v1`, but the HTTP/OAuth paths still read the raw environment value. Stdio startup can pass while OAuth issuer and request clients use the wrong base path, so the same documented endpoint value can fail outside stdio.
How can I resolve this? If you propose a fix, please make it concise.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Self-hosted stdio MCP was exiting before the MCP handshake when startup validation failed on the first probe (
tables_db). Clients such as Cursor only saw an opaque reconnect error (-32000) with no actionable message.This change:
VALIDATION_SERVICE_ORDERuntil one succeeds, so keys withouttables_db/databases scopes can still start viausers,teams, etc.APPWRITE_ENDPOINT(strip trailing slash, append/v1when the host has no path).[appwrite-mcp] ERROR: …line on stderr for config/validation failures instead of relying on a traceback clients never show.-32000indocs/self-hosted.md.raise SystemExit(main())so stdio exits with a proper status code.Test plan
uv run python -m unittest discover -s tests/unit -v