---
name: nexus402-endpoint
description: Use when building, changing or debugging an HTTPS endpoint that serves MCP tools through Nexus402. Covers the signed request, the hello, the X-Nexus-Proof header, the result shape, limits and publishing.
---

# Building a Nexus402 tool endpoint

Nexus402 hosts nothing. The creator runs an HTTPS endpoint; the gateway
meters calls and forwards each paid `tools/call` to it, signed. Start from
the tested samples rather than from scratch:
https://www.nexus402.dev/docs/agents/examples/server.mjs and https://www.nexus402.dev/docs/agents/examples/verify.mjs
(Node 18+, no dependencies), or a tested starter kit in Node.js, TypeScript,
Python, Go, PHP, Rust, Java, C# or Ruby at https://www.nexus402.dev/docs/creators/build-a-server/#starters
(each downloads as https://www.nexus402.dev/downloads/starters/nexus402-<language>.zip).

## What the endpoint receives
- Always `POST` to the exact published URL. Body: the developer's MCP
  `tools/call` request, byte for byte. Dispatch on the LAST segment of
  `params.name` (`acme/text@v2/word_count` -> `word_count`).
- `initialize`, `tools/list` and notifications never arrive: the gateway
  answers them from the published description and input schema.
- Headers: `X-Nexus-Signature` (`ed25519:` + base64), `X-Nexus-Timestamp`
  (unix seconds), `X-Correlation-ID`, `X-Nexus-Creator-Key` (`nx_crt_`).

## Verifying
- Signature: Ed25519 over six lines joined by `\n`, no trailing newline:
  method, the host you PUBLISHED (not the inbound Host header), path with
  query, timestamp, correlation id, lowercase hex SHA-256 of the RAW body.
  Public keys: `GET https://api.nexus402.dev/v1/signing-key`; accept any key listed.
- Refuse a timestamp more than 60 seconds from now in either direction.
- Compare `X-Nexus-Creator-Key` in constant time. Keep the key in an
  environment variable, never in the repository.

## The hello
When a version is published, the gateway sends one signed `POST` with an
EMPTY body and NO creator key. Verify its signature, skip the key check, run
no tool, and answer `200` with the proof. Without this, publishing fails
with `422 endpoint_hello_failed`.

## What the endpoint returns
- `X-Nexus-Proof: sha256:` + unpadded base64url of SHA-256 over
  `nexus-endpoint-proof-v1\n<X-Correlation-ID>\n<X-Nexus-Timestamp>\n<X-Nexus-Signature>`.
  Set it on EVERY answer to a verified request, before the status line.
  A `2xx` without a valid proof is voided: nobody is charged or paid.
- On success, the BARE MCP result with `Content-Type: application/json`, for
  example `{"content":[{"type":"text","text":"4"}]}`. Never wrap it in
  `jsonrpc`/`id`: the gateway does, and a second envelope would nest.
- `2xx` is a paid call, even with `"isError": true`. Any `4xx` or `5xx`
  refunds the developer; a proved `4xx` is never counted against the
  endpoint, a `5xx` always is. Twenty failures in a row de-list the version.
- A developer never pays for your failure: when the tool itself fails, answer
  a `5xx`; when the request is wrong before any work, a `4xx`. Keep
  `"isError": true` (paid) for a call the caller's input made fail after the
  tool did work.

## Limits
Headers within 5 s, no silence over 5 s, 120 s per call, 10 MiB response,
HTTPS on port 443 to public addresses only, no redirects followed.

## Reference
- Build a Server: https://www.nexus402.dev/docs/creators/build-a-server/
- Verifying a request: https://www.nexus402.dev/docs/creators/verifying/
- All docs as Markdown: https://www.nexus402.dev/llms-full.txt
