Skip to main content
Glama
Japanese Listening for Commuters

Japanese Listening for Commuters

by EmCarlss
README.md
# Japanese Listening for Commuters

An open-source listening practice project for commuters. The planned weekly lesson covers three significant international news stories from the preceding seven days, with 10–15 Japanese sentences per story. Learners will control playback in short segments and selectively reveal Swedish translations. The project starts with Japanese and Swedish and is designed to support other language pairs later.

## Phase 1 status

The server exposes one read-only tool, `show_diagnostic_card`. The visible card contains **ふたご座流星群は**. Its bundled JavaScript initializes the MCP Apps bridge. The card loads its code and styles from the HTML resource itself.

The Phase 1 production endpoint is `https://japanese-listening-mcp-production.up.railway.app/mcp`. The corrected tool points to `ui://japanese-listening/diagnostic-v2.html`.

| Check | Result |
| --- | --- |
| TypeScript build and local HTTP integration | Eight automated tests passed on Node.js 22.12.0. |
| Railway production and MCP Inspector 2.18.0 | Deployment of `214cf12` succeeded. The public endpoint passed initialization, tool invocation, resource metadata and retrieval, and `/health` checks. |
| Official MCP Apps Basic Host | The reference quickstart and corrected production card initialized and rendered in Chrome and WebKit with zero CSP violations observed. The original card stayed waiting for initialization. |
| ChatGPT rendering | Safari reported “The app did not respond in time” for the original card. The corrected card still needs a visual check in ChatGPT. |
| ChatGPT Live and native playback | Deferred to the dedicated voice experiment. |

The original resource served HTML and CSS without a script, so it could not send `ui/initialize` or `ui/notifications/initialized`. The comparison reproduced the missing lifecycle in the official Basic Host. The connection to the ChatGPT timeout remains a hypothesis until the corrected card is retested there. [MCP Apps App lifecycle](https://apps.extensions.modelcontextprotocol.io/api/classes/app.App.html#connect)

## Local development and tests

Use Node.js 22.12 or later and npm. Open the repository root in VS Code or run these commands from a terminal.

```sh
npm ci
npm test
npm start
```

`npm test` builds the TypeScript and exercises the server over HTTP with the official MCP client. Use `npm run build` on its own when you only need to compile. The default endpoints are `http://127.0.0.1:8787/mcp` and `http://127.0.0.1:8787/health`.

### MCP Inspector

With the server running, use the commands below in another terminal. Inspector 2.18.0 has a newer Node.js requirement than the app. These commands run it with Node.js 22.23.5 without adding it to the project dependencies.

```sh
inspector() {
  npx --yes --package=node@22.23.5 --package=@modelcontextprotocol/inspector@2.18.0 mcp-inspector --cli "$@"
}
mcp_url=http://127.0.0.1:8787/mcp
inspector "$mcp_url" --method tools/list --strict
inspector "$mcp_url" --method resources/list
inspector "$mcp_url" --method resources/read --uri ui://japanese-listening/diagnostic-v2.html
inspector "$mcp_url" --method tools/call --tool-name show_diagnostic_card
inspector "$mcp_url" --protocol-era modern --method tools/list --advertise-apps --app-info
```

Check that `_meta.ui.resourceUri` matches the listed and returned resource URI, the MIME type is `text/html;profile=mcp-app`, and the retrieved HTML contains the exact Japanese phrase. The tool result provides a short status message. These are protocol checks. [MCP Inspector](https://github.com/modelcontextprotocol/inspector)

### Browser initialization check

The comparison used the upstream `quickstart` and `basic-host` examples at commit `87bcdc8`. Run Basic Host with its sandbox and point it at the MCP server through a same-origin test proxy. Call `show_diagnostic_card` and check for `MCP App initialized` in the host console and `[Japanese listening diagnostic] MCP Apps initialization complete` in the app frame console. The app frame logs when initialization starts or fails as well. Check the sandbox console for CSP errors and confirm that the card displays only the diagnostic phrase. [Official Basic Host](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/basic-host) · [OpenAI troubleshooting](https://developers.openai.com/plugins/deploy/troubleshooting)

## Railway deployment

1. Push the project to a public GitHub repository. In Railway, create a service from that repository and use its root as the source directory.
2. In the service settings, use Railpack, set the build command to `npm run build`, the start command to `npm start`, and the health check path to `/health`.
3. Generate a public domain under **Networking**. In the service variables, set `HOST` to `0.0.0.0` and `MCP_PUBLIC_HOSTNAME` to the generated bare hostname, such as `your-service.up.railway.app`. Railway supplies `PORT`.
4. Deploy the settings and wait for a successful deployment. Request `https://<domain>/health` and confirm it returns `ok`. Run the Inspector checks above with `mcp_url=https://<domain>/mcp` to confirm that the public endpoint also serves MCP traffic.

[Railway build configuration](https://docs.railway.com/builds/build-configuration) · [Public networking](https://docs.railway.com/networking/public-networking) · [Health checks](https://docs.railway.com/deployments/healthchecks)

To self-host elsewhere, build with `npm ci` and `npm run build`. On the runtime machine, keep `dist/` alongside `package.json` and `package-lock.json`, run `npm ci --omit=dev`, then `npm start`. Serve `/mcp` through a public HTTPS reverse proxy that preserves the configured hostname and supports streamed responses. Set `MCP_PUBLIC_HOSTNAME` to the public hostname. Set `HOST` and `PORT` for the network interface and port used by the proxy. The default loopback bind also works with a proxy on the same machine.

## Verify the card in ChatGPT

1. In Safari, open **ChatGPT Plugins** in the workspace with the installed connection. Open **Japanese Listening for Commuters** and select **Refresh**. Confirm that `show_diagnostic_card` is still listed and check that its resource points to `diagnostic-v2.html` if the details show tool metadata. [OpenAI connection and refresh guide](https://developers.openai.com/plugins/deploy/connect-chatgpt)
2. For a first installation, select **+ → Add custom MCP server**. Name the connection `Japanese Listening for Commuters`, enter `https://japanese-listening-mcp-production.up.railway.app/mcp`, and select **No authentication**. Create and install the plugin.
3. Open a new chat, type `@`, select **Japanese Listening for Commuters**, and send `Call show_diagnostic_card to display the Japanese diagnostic card.`
4. Confirm that ChatGPT calls `show_diagnostic_card` and that a distinct app card displays exactly `ふたご座流星群は`. Record the result in Safari on macOS and repeat on iOS if the plugin is available there. Keep Phase 1 open until the visual pass condition is observed.
5. If the panel still times out, capture the app frame console in Safari Web Inspector. Look for messages beginning `[Japanese listening diagnostic]` and for CSP or script errors. Record the exact error, the browser version, and whether the tool call succeeded. [OpenAI troubleshooting](https://developers.openai.com/plugins/deploy/troubleshooting)

## Architecture and dependencies

The design follows the official MCP Apps quickstart. `registerAppTool` and `registerAppResource` from `@modelcontextprotocol/ext-apps` link the tool and resource through the standard URI and MIME type. The view imports `App` and calls `App.connect()` using the SDK's default postMessage transport. Vite and `vite-plugin-singlefile` embed the bundle in the HTML returned by `resources/read`. The resource needs no external asset or connection allowlist. [MCP Apps quickstart](https://github.com/modelcontextprotocol/ext-apps/tree/main/examples/quickstart) · [OpenAI UI guide](https://developers.openai.com/plugins/build/chatgpt-ui)

The HTTP entry point uses Node's built-in server and the split v2 SDK packages, `@modelcontextprotocol/server` and `@modelcontextprotocol/node`. The SDK handler serves stateless Streamable HTTP and supports the legacy handshake and the 2026-07-28 protocol. SDK middleware validates the MCP request's Host and Origin headers. `/health` supports deployment checks. [TypeScript SDK HTTP reference](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/docs/serving/http.md)

`zod` defines the empty tool input schema. `@modelcontextprotocol/client` is an MCP Apps peer dependency and drives the integration tests. `typescript` and `@types/node` support compilation and type checking. Exact versions are recorded in `package.json` and `package-lock.json`.

## Privacy

The app receives MCP connection and request metadata and returns the fixed card and tool status. The tool takes no user input. The app keeps no user profiles or lesson state and has no analytics or tracking. The server logs startup and the class of unexpected MCP errors without logging request bodies or conversations. Initialization diagnostics stay in the app frame's browser console. The hosting provider may process traffic metadata and retain process logs. ChatGPT processes the conversation and the MCP exchange under its own policies.

## License

[MIT](LICENSE)