Skip to content

feat(mcp): add read-only storage downloads - #5329

Merged
dbarrosop merged 16 commits into
mainfrom
mcp-storage
Nov 26, 2026
Merged

dbarrosop merged 16 commits into
mainfrom
mcp-storage

Conversation

@dbarrosop

@dbarrosop dbarrosop commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

Goal

Authenticated Backend MCP clients currently have GraphQL tools but no direct access to file bytes. Add optional read-only downloads from the same project's Storage service while keeping GraphQL unchanged and leaving file uploads, replacements, and deletion outside the MCP tool set.

Type: Enhancement

Changes

  • Opt-in tool and permissions — MCP_STORAGE_URL registers only storage-download. The service sends a GET request for the stored file ID to the configured HTTP(S) endpoint, forwards the caller's JWT, and leaves bucket and file authorization to Storage. Without the URL, the server exposes only GraphQL tools.
  • Download contract — The tool forwards image transformations, format negotiation, byte ranges, and ETag/date conditions. Structured results preserve upstream status and headers. Complete nonempty images carry bytes only in an MCP image block; other downloads return base64 data. The configurable response budget checks Content-Length and caps the read before returning data; oversized downloads preserve headers without a truncated payload.
  • Nhost Run examples — One-click installers and TOML use the proposed nhost/mcp:0.4.0 image, http://hasura-storage-service:5000/v1, and a 10 MB download limit for 256 MiB services. Operators can remove MCP_STORAGE_URL to disable downloads and grant only the Storage Download permission on intended files.

Key files

  • services/mcp/server/ (+308/-13) — Startup flags, conditional registration, and server tests.
  • services/mcp/tools/ (+1496/-0) — Download handler, schema, bounded transport, and tests.
  • services/mcp/{server.json,README.md,CLAUDE.md} (+86/-13) — Registry configuration, deployment examples, and maintainer guidance.
  • docs/src/content/docs/products/ai/mcp/ and landing/src/pages/blog/mcp-service.mdx (+99/-31) — Published tool guidance, permissions, and installer links.
  • go.mod (+1/-1) — Reflect direct use of the JSON Schema package for the tool's published constraints.

@github-actions

github-actions Bot commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Deployment Info - docs

Expose upload, download, replacement and deletion against the connected backend's explicitly configured storage URL. Forward the caller's JWT and preserve batch metadata, image transformations, conditional/range requests and complete storage response details.

Document configuration and base64 transfers, advertise the optional storage URL, and test registration, endpoint contracts, authorization and failure handling.

Checks: repository-wide golines and golangci-lint pass; MCP generation and race tests pass. Full-repository generation is blocked by unrelated GraphQL schema and local backend prerequisites.
Work unit: PR_mcp-storage/RUN-17051356745287014898/WU-001
Review issue: 001 — .nhost-code/review/PR_mcp-storage_COMMENT_001.md — ADDRESSED, ACCEPT
Resolution:
- configuration.mdx gains a Storage section and keyword for --storage-url / MCP_STORAGE_URL. It covers the optional same-backend URL with its API prefix (normally /v1), says the URL is configured explicitly and not inferred, notes that no storage tools are registered when it is unset, and says that non-HTTP(S) URLs or URLs with credentials, a query or a fragment make startup fail.
- index.mdx describes three GraphQL tools plus four optional storage tools. The Tools table gains a Destructive column, the Backend-vs-CLI comparison and the optional settings list now include storage, and the access-control text covers JWT forwarding to storage.
- deployment.mdx adds MCP_STORAGE_URL to the one-click environment list, the run-mcp.toml example (with instructions to remove it) and the local-run guidance, and links Storage permissions before deployment.
- permissions.mdx adds a Storage permissions section. It explains shared JWT forwarding and storage.files checks, maps each tool to its Storage action, requires explicit grants for user_mcp, says to grant Replace and Delete deliberately, and links the canonical Storage permissions page.
Why:
- server.json sends registry users to the public docs at docs.nhost.io/products/ai/mcp. Before this change, those pages listed only the three GraphQL tools and no storage flag, so customers could not find storage access or learn the storage permissions that decide what an assistant can read, overwrite or delete.
Decisions:
- Storage stays opt-in: the run-mcp.toml example includes the MCP_STORAGE_URL block, matching the service README, and the text says to remove it to keep a GraphQL-only deployment.
- Required storage.files columns and uploader-identity presets are linked from the canonical Storage permissions page rather than copied, so the MCP pages do not drift from it.
Checks:
- `pnpm --filter docs build` — exit 0: pass
- `git diff --check` — exit 0: pass
Work unit: PR_mcp-storage/RUN-17051356745287014898/WU-002
Review issue: 002 — .nhost-code/review/PR_mcp-storage_COMMENT_002.md — ADDRESSED, ACCEPT
Resolution:
- Storage responses are capped at 4 MiB using early Content-Length rejection and limit-plus-one reads; size errors retain upstream status and headers and explain range-based downloads without transformations.
- Upload/update handlers preflight decoded file sizes and batch totals before decoding; storage-enabled servers also cap MCP POST bodies at 8 MiB before transport parsing.
- Documentation and table-driven tests cover advertised/unknown/understated lengths, read bounds and body closure, exact limits, padding, batch rejection, and successful ranged downloads.
Why:
- Handler-only upload validation cannot bound mcp-go's earlier request buffering; the HTTP guard also bounds oversized metadata and argument materialization.
- A small fixed transfer budget leaves serialization headroom in the documented 256 MiB deployment while ranges preserve access to larger stored files.
Decisions:
- Use fixed 4 MiB transfer and 8 MiB request budgets rather than adding configuration; cap every storage response, including error and mutation responses, to avoid alternate unbounded paths.
- Apply the HTTP request budget only when storage is enabled, preserving GraphQL-only behavior; document that it covers all MCP POST calls on storage-enabled servers.
- Account for base64 padding so exact-limit transfers succeed; conservatively count line breaks in encoded-size estimates. Larger individual uploads/replacements use the storage API directly.
Review-plan variance:
- Added a pre-transport HTTP request-body guard because the suggested decoded-size checks alone occur after unbounded request reads.
- Left payload de-duplication to the separately assigned WU-003. No MIME allowlists, native-image-specific gates, or review-artifact edits were introduced.
Checks:
- `golines --dry-run --base-formatter=gofumpt .` — exit 0: pass
- `golangci-lint run ./...` — exit 0: pass
- `go test -race ./services/mcp/...` — exit 0: pass
- `git diff --check` — exit 0: pass
Work unit: PR_mcp-storage/RUN-17051356745287014898/WU-003
Review issue: 003 — .nhost-code/review/PR_mcp-storage_COMMENT_003.md — ADDRESSED, ACCEPT
Resolution:
- Complete nonempty HTTP 200 image downloads carry bytes in one image block; structured content and its JSON text mirror contain only status and headers.
- Partial, non-image, empty and failed downloads retain base64 data and existing response details.
- Regression tests verify a single serialized image payload, including a 300 KiB case, and matching text/structured summaries; tool and service documentation describe the contract.
Why:
- Removing base64 from image summaries eliminates opaque model-context noise and reduces each serialized image result from three payload copies to one.
Decisions:
- Preserved existing image eligibility and general transfer limits; no MIME allowlist or image-specific size gate was introduced.
- Separated image contract cases and assertion helpers to satisfy repository complexity limits without weakening coverage.
Review-plan variance:
- Retained NewToolResultStructuredOnly instead of manually constructing CallToolResult: omitting Data before serialization gives the same faithful compact text/structured response without a separate serializer.
Checks:
- `golines --dry-run --base-formatter=gofumpt .` — exit 0: pass
- `golangci-lint run ./...` — exit 0: pass
- `go test -race ./services/mcp/...` — exit 0: pass
- `git diff --check` — exit 0: pass
Work unit: PR_mcp-storage/RUN-17051356745287014898/WU-005
Review issue: 005 — .nhost-code/review/PR_mcp-storage_COMMENT_005.md — ADDRESSED, ACCEPT
Resolution:
- Storage now uses a private httpClient interface; the unused exported HTTPClient, mockgen directive and generated HTTP client mock are removed.
- The MCP guide describes the existing inline read-accounting stubs and httptest transport coverage instead of the unused generated mock.
Why:
- The anchored code already has white-box bounded-read tests using an inline client stub, but no external interface consumer or generated-mock user. Keeping that private seam preserves precise read-limit tests without an unused public contract.
Decisions:
- Retained the Do interface rather than replacing it with *http.Client: existing internal tests inject deliberately inconsistent response lengths. Registration still owns the unchanged timeout and no-redirect policy; no caller-injection API was added.
Checks:
- `golines --dry-run --base-formatter=gofumpt .` — exit 0: pass
- `golangci-lint run ./...` — exit 0: pass
- `go test -race ./services/mcp/...` — exit 0: pass
- `git diff --check` — exit 0: pass
Work unit: PR_mcp-storage/RUN-17051356745287014898/WU-006
Review issue: 006 — .nhost-code/review/PR_mcp-storage_COMMENT_006.md — ADDRESSED, ACCEPT
Resolution:
- TestStorageCancellation waits for a live storage-download request before canceling, then requires upstream context cancellation and an unsuccessful MCP call within bounded waits.
- Failure cleanup releases the blocking HTTP handler; the buffered call outcome avoids blocking its goroutine after a timeout.
Why:
- Request-arrival synchronization removes connection refusal and pre-canceled client contexts as alternative explanations for passing the assertion.
- An independent cleanup release is necessary because losing cancellation would otherwise hang httptest server shutdown.
Decisions:
- Retained the black-box in-process MCP client and real HTTP transport, testing the shared storage request path without production changes.
- Used an external Go overlay to drop upstream cancellation for mutation validation, leaving repository production files unchanged.
Checks:
- `golines --dry-run --base-formatter=gofumpt .` — exit 0: pass
- `golangci-lint run ./...` — exit 0: pass
- `go test -race ./services/mcp/...` — exit 0: pass
- `git diff --check` — exit 0: pass
Review comment: 001 — .nhost-code/review/PR_5329_COMMENT_001.md
The storage-enabled 256 MiB examples inherited transfer defaults that can exhaust memory in one call.
Resolution:
Addressed: the deployment guide and service README give the 256 MiB setup explicit 10 MB transfer and 14 MB request limits for single-transfer sizing; the configuration guide explains peak-memory estimates and concurrency headroom. Runtime defaults are unchanged.

Review comment: 003 — .nhost-code/review/PR_5329_COMMENT_003.md
The authentication page documented forwarding the JWT to GraphQL but not to Storage.
Resolution:
Addressed: the authentication flow and JWT validation steps now identify Storage as a token destination when enabled and link to its role permissions.

Review comment: 004 — .nhost-code/review/PR_5329_COMMENT_004.md
The deployment examples advertised storage while pinning an image that does not support it.
Resolution:
Addressed: the existing pinned examples are explicitly GraphQL-only; the optional storage setup requires a release image whose CLI supports the storage URL and both transfer-budget flags.

Checks:
- `python3 .nhost-code/tmp/check-mcp-deployment-examples.py` — exit 0; parsed the TOML and one-click configuration and verified both opt-in storage examples and docs anchors.
- `git diff --check` — exit 0; no whitespace errors.
Final validation: pending
Review comment: 005 — .nhost-code/review/PR_5329_COMMENT_005.md
The update tool described an optional replacement name without explaining that the required upload filename becomes the stored name by default; custom metadata behavior was also unclear.
Resolution:
Addressed: the storage-update tool description, input schema, and service README explain that file.name becomes the stored name unless metadata.name overrides it, and that omitted or empty custom metadata leaves it unchanged. The PUT request and storage behavior are unchanged.

Checks:
- `golines -w --base-formatter=gofumpt .` — exit 0.
- `golangci-lint run --fix ./...` — exit 0; no issues.
- `go test -count=1 ./services/mcp/tools -run '^TestStorageToolSchemas$'` — exit 0.
- `git diff --check` — exit 0; no whitespace errors.
Final validation: pending
Review comment: 005 — .nhost-code/review/PR_5329_COMMENT_005.md
The replacement field descriptions must explain the filename and custom metadata semantics. Rebasing picked up mcp-go's new reflector, which rejects the branch's legacy schema tags and leaves all four storage tools without input properties.
Resolution:
Use plain description tags. Derive the upload and download schemas from the typed requests and apply their array, numeric, and format constraints explicitly before registration. Promote the already-vendored reflector to a direct dependency without changing its version. Test the published schema keywords and the replacement field description via ListTools.

Checks:
- `go mod vendor -o <scratch>/vendor` and `diff -qr --exclude=.envrc vendor <scratch>/vendor` — exit 0; no tracked vendor differences.
- `golines -w --base-formatter=gofumpt .` — exit 0.
- `golangci-lint run --fix ./...` — exit 0; no issues.
- `go test -count=1 -race ./services/mcp/...` — exit 0; all MCP packages passed.
- `git diff --check` — exit 0; no whitespace errors.
Final validation: pending

Corrects-Commit: 5416055
Remove the upload, replacement, and deletion tools and the request-body setting added for uploads. Keep the download schema, response size limit, and JWT forwarding unchanged, and document the reduced permissions and deployment settings.

Checks: repository-wide Go formatting and lint, MCP race tests, and pnpm --filter docs test.
Pin MCP installation examples to the proposed 0.4.0 image and use the internal Storage URL on Nhost Run. Set a 10 MB response budget for the 256 MiB examples, and keep the TOML examples aligned with the installer links.

Checks: decoded all three installer payloads and verified their TOML equivalents; docs test suite, blog MDX compilation and Vale passed.
@dbarrosop dbarrosop changed the title feat(mcp): expose storage uploads, downloads, updates and deletion feat(mcp): add read-only storage downloads Nov 25, 2026
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Vercel Deployment Info - landing

Attach a bundled HTML resource to storage-download. Render the existing image block without adding a public URL, browser credentials, or duplicate image bytes. Clients without MCP Apps keep the existing tool result.

Checks: MCP race tests, repository-wide Go lint, Nix MCP check, docs suite, and a mock-host viewer test passed. Live Claude rendering remains unverified.
Review comment: 003 — .nhost-code/review/PR_5329_COMMENT_003.md
The docs described image previews but not the panel shown for other results.
Resolution:
ADDRESSED — The public MCP overview and service README now say that any `storage-download` call can open a panel, with a short status message when there is no previewable image. Both explain that rendering depends on browser decoding. Tool behavior is unchanged.

Review comment: 004 — .nhost-code/review/PR_5329_COMMENT_004.md
The resource test did not guard against changing network restrictions or breaking protocol markers.
Resolution:
ADDRESSED — `TestStoragePreviewResource` checks the CSP, network-reference markers, and MCP Apps handshake and lifecycle strings in the HTML returned by `resources/read`. Temporary overlays confirmed that loosening image sources or renaming the tool-result notification fails the test. The checks stay in Go; no browser or Node dependency was added.

Checks:
- `vale --minAlertLevel=error services/mcp/README.md docs/src/content/docs/products/ai/mcp/index.mdx` — exit 0, no errors.
- `golines -w --base-formatter=gofumpt .` and `golangci-lint run --fix ./...` — exit 0.
- `bash .nhost-code/tmp/mcp-preview-regression-check.sh` — exit 0, both targeted Go overlays rejected and original resource test passed.
- `nix build --no-link --print-build-logs .#checks.aarch64-linux.docs` and `.#checks.aarch64-linux.mcp` — exit 0.
- `git diff --check` — exit 0.
@dbarrosop
dbarrosop merged commit ab8bc92 into main Nov 26, 2026
82 checks passed
@dbarrosop
dbarrosop deleted the mcp-storage branch November 26, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants