Hosted mode¶
Hosted mode puts your MCP server at a URL. Anyone can add that URL to Claude, ChatGPT or another MCP client that supports OAuth, sign in with their own account, and use your API from there. Every tool call runs with that person's credential. Hosted mode needs an oryva key.
The examples here use a notes API named notebook, where each member has their own member key.
Turn it on¶
Add x-oryva-gateway to the spec's info:
info:
x-oryva-gateway:
sign_in:
scheme: memberKey # a securitySchemes entry: an API key or token
label: Notebook member key # the sign-in field's label
help: Create one under Settings, then Member keys. # optional
connect: # optional: sign in on your own page instead
url: https://app.notebook.example/connect
exchange: exchangeConnectGrant # operationId: takes {grant}, returns the credential
credential: key # dotted path to it in the exchange response
identity:
operation: getMe # operationId, called with the credential to check it
display: "{member.email}, {workspace.name}" # optional: logged at sign-in
bind: # optional: filled on every call, left out of tool inputs
workspaceId: workspace.id # parameter -> dotted path into getMe's response
tools:
tags: [notes, comments, folders] # optional: only these operations become hosted tools
Then generate, install and start the server:
oryva generate openapi.yaml
pip install out/notebook/python out/notebook/mcp
export ORYVA_GATEWAY_SECRET="$(python3 -c 'import secrets; print(secrets.token_urlsafe(32))')"
export ORYVA_GATEWAY_URL=https://mcp.notebook.example # the public URL, without a path
notebook-mcp serve --host 0.0.0.0 --port 8000
People add https://mcp.notebook.example/mcp in Claude under Settings, then Connectors, then Add
custom connector. In Claude Code:
claude mcp add --transport http notebook https://mcp.notebook.example/mcp
The client registers itself with the server and sends the person to the server's sign-in page. After they sign in, Claude has the notes tools, and each call carries their member key. To run the server in production, see Deploying.
The gateway config¶
sign_in.scheme names the credential people sign in with. When the API needs several credentials
sent together, map each scheme to its field's label and let label name them as a set:
scheme: {clientId: Client ID, clientSecret: Client secret} with
label: Example client ID and secret. Every call then sends both.
identity.operation checks the credential at sign-in. bind fills parameters from that response,
such as the workspace id here, so no tool asks for them.
tools.tags limits which operations become hosted tools. Operations that upload files or return
binary data never become hosted tools.
oryva generate checks the config against the spec and stops, saying why, when:
- a scheme or operation doesn't exist;
- a bound name is not a parameter of any hosted tool;
- a tag is unused;
- a hosted operation can't be called with the sign-in schemes alone.
With connect, it also stops when connect names several schemes, or connect.credential is not
a dotted path. It stops too when the exchange operation is unknown, needs a credential, has no
grant body field, or needs other inputs.
Server settings¶
The same package still speaks stdio. serve switches it to hosted mode and reads:
ORYVA_GATEWAY_SECRET: at least 32 random characters, the same on every instance. Changing it signs everyone out.ORYVA_GATEWAY_URL: the public URL. It must behttpsunless it islocalhost.NOTEBOOK_BASE_URL, the SDK's base URL variable, when the API is not at its default URL.ORYVA_GATEWAY_CONNECT_URL, withconnect, when your connect page is not atconnect.url, as on a staging server. Set it empty to have people paste their key instead.
GET /healthz answers ok.
Sign-in and consent¶
The server is its own OAuth 2.1 authorization server, with metadata, dynamic client registration, PKCE and refresh tokens.
Because clients register themselves, they pick their own names. So before anyone signs in, the server's page shows the client's name, says the client will act as the person, and names the host the browser returns to. Someone who doesn't recognise the client can stop there.
Without connect, that page asks for the credential, using label as the field's name and help
below it. The server checks the credential with identity.operation and sends the person back to
the client.
With connect, the page shows a Continue button instead, which takes the browser to your connect
page.
Your connect page¶
With connect, people sign in on your app's own page instead of pasting a key. The server sends
the browser to connect.url with three query parameters:
client_name: the name the MCP client registered.return_to:<ORYVA_GATEWAY_URL>/connect/return.state: an opaque value to send back unchanged.
Your page signs the person in and asks them to allow the client. Then it sends the browser to
return_to?grant=...&state=..., or to return_to?error=access_denied&state=... if they cancel.
The server calls the exchange operation with {grant} and no credential, and reads the
credential at connect.credential in the response. It checks the credential with
identity.operation and sends the person back to the client. A refused or expired grant returns
to the client as an OAuth error. Only the browser that started the sign-in can come back with its
state.
The grant is the only secret in that exchange. Make it random, short-lived and single-use, and send
it only to a return_to you trust. Your page must accept <ORYVA_GATEWAY_URL>/connect/return as a
place to send people back.
Tokens and sessions¶
The server stores nothing. It seals client registrations, codes and tokens with
ORYVA_GATEWAY_SECRET, so any number of instances can run behind one URL.
- Access tokens last an hour and refresh tokens 30 days. A sign-in lasts 90 days, however often it is refreshed.
- A token can't be revoked before it expires. Changing the secret signs everyone out.
- OAuth 2.1 asks that a code and a refresh token each work once. Without a database, each works until it expires: 5 minutes for a code. With the Slack app's database, each works once.
- The MCP client's token never reaches your API. When the API refuses someone's credential, their tool calls tell them to reconnect.