Esta página ainda não foi traduzida. Ler o original em inglês

Documentação

NSH MCP Server

The NSH MCP server (NSH Preview) connects AI models to Native Shell. It gives the model the NSH documentation of one release, so the code it writes matches the APIs that release has. In Claude or ChatGPT, it also runs that code: you describe a screen, the model writes it as NSH TSX, and the chat shows a live NSH app you can tap through, switch to a phone size or dark mode, and send errors from back to the model. The result downloads as an nsh init project that runs on every NSH target.

The server address is:

https://mcp.nsh.dev

Open that address in a browser for the same connection steps, with copy buttons.

MCP (Model Context Protocol) is the standard way chat apps and coding agents connect to outside tools. The live preview uses MCP Apps, the MCP extension that lets a tool result show an interactive page in the chat. The server needs no account, key or sign-in.

Coding agents such as Claude Code and Codex use the same server for the docs, and pair it with the nsh CLI and the NSH skills in your project (Develop locally).

#Connect a client

Client How you add it Shows the live preview
ChatGPT (web) App in developer mode Yes
Claude (web and desktop) Custom connector Not yet: the docs, and the preview’s controls without the running app
Claude Code claude mcp add No: the docs and text results
Codex codex mcp add No: the docs and text results
Other clients (Cursor, VS Code, …) JSON config Only if the client renders MCP Apps

Claude and ChatGPT connect from their own servers, so they need the public HTTPS address above. They can’t reach localhost.

#Claude (web and desktop)

Claude doesn’t run the live preview yet. The preview runs the app in a frame from https://mcp-preview.nsh.dev, and Claude doesn’t allow frames from other addresses inside an app, whatever the app declares (anthropics/claude-ai-mcp#40). The preview shows its controls and says the app can’t run here. The model still reads the docs and writes the project, which you can download and run with nsh run (Keep working on it). Once Claude allows these frames, the preview works there with no change on your side. Until then, use ChatGPT for the live preview.

  1. Open Customize → Connectors in Claude (claude.ai/customize/connectors).
  2. Click Add custom connector. Enter NSH Preview as the name and https://mcp.nsh.dev as the server URL.
  3. Leave the OAuth Client ID and Secret empty, and click Add. The server needs no sign-in.
  4. In a chat, click + → Connectors and turn on NSH Preview.
  5. Ask for a UI, for example: “Use NSH to build a calculator.”

Free, Pro and Max users can add custom connectors themselves. The Free plan allows one. On Team and Enterprise, an Owner adds the connector under Organization settings → Connectors first, and members then turn it on.

#ChatGPT

  1. Turn on Developer mode in ChatGPT settings (Settings → Security and login). On Business, Enterprise and Edu, a workspace admin has to allow it first.
  2. In settings, open Apps and click Create. Enter NSH Preview as the name and https://mcp.nsh.dev as the MCP server URL.
  3. Set Authentication to no authentication, confirm that you trust the app, and create it.
  4. In a chat, click +, pick NSH Preview, and ask for a UI, for example: “Use NSH to build a calculator.”

In newer versions of ChatGPT, connected apps are listed under Plugins in the sidebar. ChatGPT changes its menu names between versions, and plan availability follows OpenAI’s current terms.

#Claude Code

claude mcp add --transport http nsh-preview https://mcp.nsh.dev

Claude Code runs in a terminal, so it can’t show the live preview. The model can still read the NSH docs through the docs tool. To build an NSH app in your project with Claude Code, set up the nsh CLI and the NSH skills (Develop locally). They give the model the same docs, plus type checking, running and testing.

#Codex

codex mcp add nsh-preview --url https://mcp.nsh.dev

As in Claude Code, Codex gets the docs and text results, not the preview. For local development, use the CLI and skills.

#Other clients

Most clients that accept a JSON server list take this entry. The field names vary by client, so check its docs:

{
  "mcpServers": {
    "nsh-preview": { "type": "http", "url": "https://mcp.nsh.dev" }
  }
}

Test the server from a terminal. The first command asks for the tool list, and the second prints the server’s status and NSH release:

curl -s https://mcp.nsh.dev \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

curl -s https://mcp.nsh.dev/health

#Use the preview

Ask for the UI you want in plain words. The model first reads the NSH docs, then calls preview with the code. The preview appears under the model’s reply:

┌ Calculator · Running                                                     [▭|▯]  ☾  ↻  <>  ↓  ⤢ ┐
│                                                                                                    │
│                         your UI, running on NSH's web runtime                                      │
│                                                                                                    │
├ diagnostics (when there are errors)                                                                ┤
└ [Send errors to AI]  [Ask for a change…                                                   ] [Send] ┘

The toolbar buttons are icons; hover one for its name.

Control What it does
Desktop / Phone (monitor, phone) Resizes the running UI to a desktop size or a phone-sized frame, keeping its state. The idiom is the one the UI started with; Restart runs it with the current size’s idiom.
Dark / Light (moon, sun) Switches the UI’s theme. The preview starts in the chat’s theme.
Restart (circular arrow) Starts the UI again from a clean state.
Source (<>) Shows the files the model wrote, with syntax highlighting.
Download (down arrow) Saves the project as a ZIP (see Keep working on it).
Full screen (expand arrows) Shows the preview over the whole chat, in chats that offer it.
Send errors to AI Sends the compile or runtime errors to the model, which fixes them and calls preview again.
Ask for a change Sends your request, with the current errors, to the model.

The status next to the title says where the preview is:

Status Meaning
Starting NSH… The runtime is loading.
Compiling… The TSX is compiling in your browser.
Running The UI is on screen and responds to input.
Compile error The code doesn’t compile. The diagnostics show the file, line, column and code frame.
Runtime error The code threw while running, or the runtime didn’t start.
Invalid project The server refused the project (see Limits).
Closed The chat closed the preview.

Each call to preview shows a new preview with the complete project. The model doesn’t patch an earlier one.

#Send feedback to the model

Send errors to AI and Ask for a change send a message like this one:

NSH preview feedback for "Calculator" (revision 431c7e6db00261ef, NSH 0.7.2).

Diagnostics:
- compile App.tsx:6:18: Unexpected token

Fix it and call the preview tool again with the complete project.

How the message arrives depends on the chat:

  • If the chat lets the preview post messages, it appears in the conversation and the model answers it.
  • If the chat only lets the preview add context, the status says “Added to the conversation’s context: send a message to continue”. Send any message, such as “fix it”, and the model sees the feedback.
  • If the chat allows neither, the preview shows the text for you to copy and paste.

#Keep working on it

Download saves a ZIP laid out like an app from nsh init:

calculator/
├── App.tsx          the code from the preview
├── nsh.json
├── tsconfig.json
├── .gitignore
└── README.md

Unpack it and run it with the NSH CLI on any target:

cd calculator
nsh run                    # this machine's backend
nsh run --target ios       # the iOS simulator

Some chats block downloads from the preview. In that case, the preview says so and opens Source, so you can copy the files instead.

#Develop locally

A design that starts in a chat continues in a project on your machine. There, you and coding agents such as Claude Code and Codex work with the nsh CLI:

curl -fsSL https://nsh.dev/install.sh | sh     # Windows: irm https://nsh.dev/install.ps1 | iex
npx skills add longbridge/nsh                  # the Coding and Design Guides as skills for your agent
nsh init my-app
cd my-app
nsh run

In a project, the CLI adds:

  • Type checking against the declarations generated for your NSH release (.nsh/types).
  • Every target: nsh run --target ios, android, macos, windows, linux or web.
  • Headless tests with nsh test, which reports errors and the views produced.
  • Whole projects: many modules, assets, Rust extensions and packaging.

A project downloaded from the preview is already an nsh init app, so you can move from a chat to your machine at any time. See Installation and Getting started.

#What the model can write

The preview runs one release of NSH, the one the server reports at https://mcp.nsh.dev/health. The docs the model reads are the documentation of that same release.

  • One file. The preview compiles the entry file only, usually App.tsx. The model is told to put the whole UI there. Other files are kept in the project and the download, but the preview warns that it doesn’t load them.
  • NSH modules only. Imports are nsh and its modules. npm packages are not available.
  • No network. The UI can’t fetch data from the internet. The model writes sample data into the code.
  • A web preview. The UI runs on NSH’s web backend in your browser. It looks and behaves like the Web target, not like an iOS or Android device. Run the downloaded project with nsh run to see it on a device.

#Tools

The server has two tools. The model calls them, so you don’t need to. Chats list them by their titles, Read NSH docs and Preview UI.

#docs

Reads the NSH documentation of the release the server runs.

Parameter Type Description
topic string, optional An element, module or guide page, such as button, list, layout or style-reference. Without it, the tool returns the overview: the minimal app, the preview’s rules, the modules and the reactivity rules.
section string, optional One ## section of the page. Long pages (over 40 KB) return their introduction and outline without it.
version string, optional The NSH release. Only the server’s release is available.

An unknown topic returns up to eight close matches to choose from.

#preview

Shows a project in the chat. It validates the project and returns it with its revision. The project compiles and runs in the preview afterwards, so a successful result doesn’t mean the code compiled.

Parameter Type Description
title string What the UI is, such as Mail client. Up to 120 characters.
project.schemaVersion 1 The project format.
project.runtimeVersion string The NSH release, which must equal the server’s.
project.entry string The entry file, usually App.tsx.
project.files object Every file, by relative path, as text.
preview.viewport "desktop" or "phone", optional How the preview starts. Default desktop.
preview.theme "light" or "dark", optional How the preview starts. Default: the chat’s theme.

The revision is the first 16 hex digits of a SHA-256 hash of the project. The same code always gets the same revision.

#Limits

Limit Value
Files per project 32
Size of one file 256 KB
Size of all files 1 MB
Length of a path 128 characters
Paths Relative, without .., ending in .tsx, .ts or .json
Feedback message 4,000 characters

A project over a limit gets “Invalid project” and a message that names the file and the problem.

#Privacy and isolation

  • The server stores nothing. It checks the project and returns it in the tool result. The chat app keeps the conversation, the server keeps no copy. It runs no code and calls no model.
  • The code runs in your browser, in a frame from its own address, https://mcp-preview.nsh.dev. That address has no cookies or sign-in. The browser keeps the code away from the chat page and from the preview’s controls.
  • The code can’t reach the internet. The preview’s content security policy allows connections to its own address only.
  • Each restart and new version gets a new frame. The old frame and everything running in it are removed.

A UI that never yields, such as a while (true) loop, can freeze the preview until you close it.

#Troubleshooting

Problem What to do
The model answers without a preview Check that the NSH Preview connector or app is turned on in this chat. A client without MCP Apps support shows only the text result.
“This chat doesn’t allow the preview’s frame from https://mcp-preview.nsh.dev” The chat doesn’t allow frames from other addresses inside an app. Claude doesn’t yet (Claude). Use ChatGPT for the live preview, or download the project and run it with nsh run.
“runtimeVersion … is not available; this server runs NSH …” The model named another NSH release. The model sees this error in the tool result and usually resubmits with the server’s release by itself.
Download does nothing The chat blocks downloads. Copy the files from Source.
Runtime error lines don’t match the code Runtime errors point at the compiled code, so a line can be a few lines off from the TSX. Compile errors point at the TSX.