Skip to content

Add a draft-only SignuDoc MCP server - #260

Open
mariomeyer wants to merge 6 commits into
NYLLON-SOFTWARE:mainfrom
ReyemTech:feat/mcp-server
Open

mariomeyer wants to merge 6 commits into
NYLLON-SOFTWARE:mainfrom
ReyemTech:feat/mcp-server

Conversation

@mariomeyer

@mariomeyer mariomeyer commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

  • Add a stateless Streamable HTTP MCP endpoint at /api/mcp, authenticated with a dedicated prepare API-key scope.
  • Add tools to request PDF uploads, create unsent drafts, list and inspect envelopes, read audit events, and download signed PDFs or completion certificates.
  • Restrict prepare keys to their own envelopes across MCP and REST reads; they cannot send, void, remind, sign, or mutate sent envelopes.
  • Document Codex and generic MCP client setup, upload paths, key rotation, and the draft review flow.

Verification

  • npm test: 510 passed.
  • npm run test:db: 414 passed.
  • npm run typecheck: passed.
  • npm run lint: passed with eight existing warnings and no new warnings.
  • next build --webpack: passed.
  • git diff --check: passed.

The default Turbopack build could not bind its internal worker port in the local environment; the production webpack build passed.

Scheduled sending is intentionally out of scope.

Note

Add draft-only SignuDoc MCP server with prepare API key scope

  • Adds an MCP server at the /api/mcp route exposing two draft tools (upload target, unsent draft creation) and four read tools (envelope list, get, events, file download). Drafts are created unsent; sending remains dashboard-only.
  • Introduces a prepare API key scope between read and write: prepare grants read plus draft creation, but sendEnvelopeForApi rejects it with 403. A DB migration widens the scope check constraint (migration).
  • Prepare keys see only envelopes created with that key. Envelope-view query helpers in envelope-view.ts accept an optional API key ID filter, applied by the v1 envelope, events, and file routes for prepare actors.
  • MCP requests require a bearer token, an exact prepare scope, host/origin checks, and a configured app URL. Inline PDF input is limited to 3 MiB and must be canonical base64 with a PDF header (draft-tools.ts).
  • Risk: envelope creation and upload routes (route.ts, route.ts) now authorize with prepare instead of write; write keys still pass, but any caller relying on the exact write requirement changes. The file-download handler in route.ts now returns 404 when its envelope lookup finds nothing.

Macroscope summarized 6fd30ff.

@vercel

vercel Bot commented Nov 23, 2026

Copy link
Copy Markdown

@mariomeyer is attempting to deploy a commit to the Basic Intelligence Team on Vercel.

A member of the Team first needs to authorize it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-23T19:34:06.376677Z 3d89e8f PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3d89e8f106

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/lib/api-keys.ts
Comment on lines +149 to +150
if (granted === "prepare") {
return needed !== "write";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict webhook-delivery reads for prepare keys

When webhooks have recorded envelope events, a prepare key can now call GET /api/v1/webhook-deliveries, since that route only requires read. Its handler calls listApiWebhookDeliveries without the actor, and src/lib/webhooks/log.ts:149–155 selects all non-test deliveries without user or API-key filtering. The returned payloads contain envelope data, signer details and metadata, exposing envelopes created by other keys or users despite the new key-scoped envelope endpoints. Reject prepare keys on this route or filter deliveries to envelopes belonging to both the authenticated user and API key.

Useful? React with 👍 / 👎.

@greptile-apps

greptile-apps Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 3/5

[Medium impact] The PR adds agent access to envelope preparation and reads within SignuDoc accounts.

Block merging until prepare keys can no longer read other envelopes through the webhook delivery log.

Findings

  1. P1 Security Draft keys read other envelopes ▶
  2. P2 Bad PDFs get retry advice ▶

Summary

Adds a draft-only MCP endpoint and a new prepare key scope.

  • MCP clients can create unsent SignuDoc drafts from PDF files.
  • MCP clients can inspect envelopes and download finished PDFs.
  • Prepare keys can create drafts and only read envelopes made with that key.

Reviews (1) · Last reviewed commit: "docs: document SignuDoc MCP setup" · Reviewed by Greptile

Comment thread src/lib/api-keys.ts
Comment on lines +149 to +150
if (granted === "prepare") {
return needed !== "write";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 security Draft keys read other envelopes

A prepare key can call GET /api/v1/webhook-deliveries because this branch grants access to every read route. That route returns stored payloads without checking the key or owner. These include other envelopes' titles, metadata, signer emails, and owner details, bypassing the new limits on envelope reads.

Block this route for prepare keys or filter its results to envelopes created by that key.

How this was verified: The read guard accepts prepare, and the delivery query returns full envelope payloads without a key or owner filter.

Comment on lines +324 to +333
} catch (error) {
if (
error instanceof DocumentImportError ||
error instanceof PendingUploadError
) {
return toolError(error.message);
}
return toolError(
"Could not create the draft. Retry with the same idempotency key or review drafts in the dashboard.",
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Bad PDFs get retry advice

decodeInlinePdf throws a plain Error for malformed base64 or a missing PDF header. This catch hides its useful message and tells the agent to retry the same request, which fails again.

Use a known input-error type and return its message so the agent knows to fix the PDF data.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

This branch has not been deployed

No deployments
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.

1 participant