@straitlink/mcp 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The Strait authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,225 @@
1
- # Temporary Holding Version
1
+ <h1 align="center">Strait MCP server</h1>
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ <p align="center"><strong>Straight to the screen. On the record.</strong><br>
4
+ A tap on a Strait link goes straight to the exact screen in your app (Straight), and every tap is recorded (Stamped).</p>
5
+
6
+ <p align="center">
7
+ <a href="https://straitlink.in/docs/">Docs</a> ·
8
+ <a href="https://straitlink.in/platform-status/">Platform status</a> ·
9
+ <a href="#docs-and-support">Talk to the Strait team</a>
10
+ </p>
11
+
12
+ `@straitlink/mcp` (preview)
13
+
14
+ ```sh
15
+ claude mcp add strait --env STRAIT_SECRET_KEY=st_live_your_key -- npx -y @straitlink/mcp
16
+ ```
17
+
18
+ Use Strait from AI tools such as Claude Code, Cursor and Claude Desktop: create deep links, change them, read
19
+ analytics, check App Links / Universal Links files, see where taps on a link go, and search the Strait docs.
20
+
21
+ It is a local stdio server with 10 tools. Three of them write (`create_link`, `batch_create_links`,
22
+ `update_link`); the other seven only read. Eight need your secret key; `check_app_links`, `search_docs` and demo
23
+ `trace_tap` work without one. Other deep-link vendors also ship MCP servers that can create links, so this README
24
+ makes no "first" or "only" claim; it describes what this server does today.
25
+
26
+ **iPhone is in beta.** iPhone install matching (deferred deep linking on iOS) is in beta; Android uses the Play
27
+ Install Referrer. On iPhone the workspace chooses the method in Dashboard → Settings → iPhone installs (device
28
+ matching, paste handoff, both or neither), and the SDK reads that choice at runtime. Device matching is off for new
29
+ workspaces. The tools report iPhone results the same way, but treat iPhone install attribution as beta.
30
+
31
+ > **Preview.** The remote server (`mcp.strait.link`) is built and deploy-ready but not deployed (see "Deploy the
32
+ > remote server"). Until then, use the local server above.
33
+
34
+ ## Tools
35
+
36
+ | Tool | What it does | Key needed |
37
+ |---|---|---|
38
+ | `create_link` | Create one link and get its `shortUrl` | secret |
39
+ | `batch_create_links` | Create up to 500 links in one call (safe to re-run: existing slugs are per-item 409s) | secret |
40
+ | `get_link` | Read one link by slug | secret |
41
+ | `list_links` | List links, one page at a time | secret |
42
+ | `update_link` | Change destination, title, tags or expiry. **Asks for `confirm: true`**: without it you get a preview and nothing changes | secret |
43
+ | `get_analytics` | Taps, app opens, installs, conversions and revenue, by day / channel / link / platform (`GET /v1/analytics`). iPhone installs come from beta install matching | secret |
44
+ | `check_app_links` | Check a domain's `assetlinks.json` and `apple-app-site-association`, with a fix for each problem | none |
45
+ | `simulate_tap` | Dry-run one tap from one device or app (nothing recorded or billed) | secret |
46
+ | `trace_tap` | Walk a link through WhatsApp, Instagram, Facebook, Chrome, Safari, iPad, computer and preview bots; or read a Live Tap Trace from the website demo | secret (link) / none (demo token) |
47
+ | `search_docs` | Search the Strait docs offline (bundled index) | none |
48
+
49
+ Every tool carries MCP annotations (`readOnlyHint`, `destructiveHint`, …). Only `update_link` is destructive.
50
+ `create_link` and `batch_create_links` write new links but never change existing ones. There is no delete tool.
51
+
52
+ ## Keys
53
+
54
+ The server needs a **secret key** (`st_live_…`) from **Dashboard → Settings → Secret keys**. A secret key can change your
55
+ links, so:
56
+
57
+ - Create a separate key for your AI tools, so you can revoke it on its own.
58
+ - Keep it in the MCP client's config or environment, never in app or website code.
59
+ - A publishable key (`st_pub_live_…`) does not work here: it is for the SDKs in your apps.
60
+
61
+ Without a key, `check_app_links`, `search_docs` and demo `trace_tap` still work.
62
+
63
+ | Variable | Meaning |
64
+ |---|---|
65
+ | `STRAIT_SECRET_KEY` | Your secret key (`st_live_…`) |
66
+ | `STRAIT_API_URL` | Engine URL. Default `https://strait.link`. Use `http://localhost:3000` for a local engine |
67
+
68
+ ## Install
69
+
70
+ ### Claude Code
71
+
72
+ ```sh
73
+ claude mcp add strait --env STRAIT_SECRET_KEY=st_live_your_key -- npx -y @straitlink/mcp
74
+ ```
75
+
76
+ ### Cursor
77
+
78
+ `~/.cursor/mcp.json` (all projects) or `.cursor/mcp.json` (one project; don't commit a key):
79
+
80
+ ```json
81
+ {
82
+ "mcpServers": {
83
+ "strait": {
84
+ "command": "npx",
85
+ "args": ["-y", "@straitlink/mcp"],
86
+ "env": { "STRAIT_SECRET_KEY": "st_live_your_key" }
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ### Claude Desktop
93
+
94
+ Settings → Developer → Edit config, then add the same `"strait"` entry under `mcpServers` and restart.
95
+
96
+ ### From a checkout
97
+
98
+ ```sh
99
+ cd mcp-server && npm ci && npm run build
100
+ claude mcp add strait --env STRAIT_SECRET_KEY=st_live_your_key -- node "$PWD/dist/stdio.js"
101
+ ```
102
+
103
+ In Cursor or Claude Desktop use `"command": "node", "args": ["/absolute/path/to/mcp-server/dist/stdio.js"]`.
104
+
105
+ ## Try it
106
+
107
+ - "Create a Strait link `summer` to https://shop.hilltop.example/summer with the title Summer sale."
108
+ - "Which channel brought the most installs last month?"
109
+ - "My links open the browser instead of the app. Check hilltop.strait.link and shop.hilltop.example."
110
+ - "What happens when someone taps `summer` inside Instagram on an iPhone?"
111
+ - "How do I receive links in Expo Router?"
112
+
113
+ Hilltop Shoes (`hilltop.strait.link`, `*.hilltop.example`) is a made-up shop used in examples.
114
+
115
+ ## MCP registry listing (drafted, not published)
116
+
117
+ `server.json` and the `mcpName` field in `package.json` are drafts for the
118
+ [official MCP registry](https://registry.modelcontextprotocol.io). The registry checks that `mcpName` in the published npm package matches `server.json` `name`
119
+ ([package types](https://github.com/modelcontextprotocol/registry/blob/main/docs/modelcontextprotocol-io/package-types.mdx)).
120
+
121
+ - **Namespace `in.straitlink/mcp` (recommended).** Reverse-DNS of `straitlink.in`, so the listing carries the
122
+ product's own domain. It needs DNS authentication: the Strait team adds a TXT record on the apex `straitlink.in`
123
+ (`v=MCPv1; k=ed25519; p=<public key>`) and runs `mcp-publisher login dns --domain straitlink.in --private-key …`
124
+ ([authentication](https://github.com/modelcontextprotocol/registry/blob/main/docs/modelcontextprotocol-io/authentication.mdx)).
125
+ Keep the private key out of the repo.
126
+ - **Alternative `io.github.<owner>/strait-mcp`.** Uses GitHub OAuth (`mcp-publisher login github`) and needs no DNS
127
+ change, but the name shows a personal GitHub account rather than the product domain, and it requires the public
128
+ GitHub repo, which does not exist yet. To switch, change `name` in `server.json` and `mcpName` in `package.json`
129
+ together (a test checks they match).
130
+ - `remotes` is left out until `mcp.strait.link` is deployed; add
131
+ `{"type": "streamable-http", "url": "https://mcp.strait.link/mcp"}` then. Add `"repository": {"url": "https://github.com/bazingga08/strait-mcp", "source": "github"}`
132
+ once the GitHub repo exists.
133
+ - Order when the Strait team is ready: create the repo, publish `@straitlink/mcp` to npm, add the TXT record, then
134
+ `mcp-publisher publish`.
135
+
136
+ ## Licence
137
+
138
+ MIT. See [LICENSE](LICENSE).
139
+
140
+ ## Remote server (built, not deployed)
141
+
142
+ `src/worker.ts` is a Cloudflare Worker serving MCP over Streamable HTTP at `https://mcp.strait.link/mcp`. It answers
143
+ 404 everywhere unless `REMOTE_MCP=on` (only `env.production` in `wrangler.jsonc` turns it on).
144
+
145
+ - **Bearer-key mode:** `Authorization: Bearer st_live_…` on `/mcp`, for clients that take a header.
146
+ - **OAuth** (`@cloudflare/workers-oauth-provider`): dynamic client registration (`/register`), `/authorize`, `/token`,
147
+ authorization-server metadata and RFC 9728 protected-resource metadata
148
+ (`/.well-known/oauth-protected-resource/mcp`). PKCE, registered redirect URIs only.
149
+ - The consent page asks for a secret key, checks it with `GET /v1/links?limit=1`, and keeps it only inside the
150
+ grant, which the provider encrypts with the token (a test checks that KV never holds the key in plain text).
151
+ It shows where the user is sent back to, has a Cancel button (`access_denied` back to the client), and sends
152
+ `X-Frame-Options: DENY`, a strict CSP and `Cache-Control: no-store`.
153
+ - Access tokens last 1 hour; refresh tokens 30 days.
154
+ - Next step before a wide launch: replace the paste-a-key page with dashboard sign-in that mints a scoped key.
155
+ - **`/healthz`** returns `{ ok, service, version, mcp }` with no upstream call, for the post-deploy check.
156
+
157
+ ### Try it locally
158
+
159
+ ```sh
160
+ cp .dev.vars.example .dev.vars # REMOTE_MCP=on, STRAIT_API_URL=http://localhost:3000
161
+ npm run dev:remote # wrangler dev on http://localhost:8787 (local KV, nothing leaves the machine)
162
+ curl http://localhost:8787/healthz
163
+ npx -y @modelcontextprotocol/inspector@0.17.5 # connect to http://localhost:8787/mcp
164
+ ```
165
+
166
+ ### Deploy the remote server (Strait team only)
167
+
168
+ Agents prepare this; only the Strait team deploys. Needs the Cloudflare account that holds the `strait.link` zone
169
+ (`CLOUDFLARE_API_TOKEN` / `CLOUDFLARE_ACCOUNT_ID` from `redirect-engine/.env` work). The bundle is about 1.9 MB
170
+ (360 KB gzipped), inside the free plan's size limit; Workers Paid (already planned) is recommended for its higher
171
+ CPU time per request.
172
+
173
+ ```sh
174
+ cd mcp-server && npm ci
175
+ npm run typecheck && npx vitest run # all green
176
+ # 1. Create the OAuth store once and paste its id into env.production.kv_namespaces in wrangler.jsonc
177
+ npx -y wrangler@4 kv namespace create OAUTH_KV --env production
178
+ npm run deploy:preflight # exit 0 = config ready (fails while the id is a placeholder)
179
+ npm run deploy:check # wrangler dry run, nothing uploaded
180
+ # 2. Deploy. The custom domain creates the mcp.strait.link DNS record and certificate.
181
+ npx -y wrangler@4 deploy --env production
182
+ # 3. Check it
183
+ curl -s https://mcp.strait.link/healthz # {"ok":true,...}
184
+ curl -s https://mcp.strait.link/.well-known/oauth-protected-resource/mcp # resource: https://mcp.strait.link/mcp
185
+ curl -s -o /dev/null -w '%{http_code}\n' -X POST https://mcp.strait.link/mcp # 401 (needs a token)
186
+ claude mcp add --transport http strait https://mcp.strait.link/mcp # then /mcp in Claude Code to sign in
187
+ ```
188
+
189
+ Roll back with `npx -y wrangler@4 rollback --env production`, or switch it off by setting `REMOTE_MCP` to `"off"`
190
+ in `env.production.vars` and deploying again (every route then answers 404). Revoking the secret key a user pasted
191
+ cuts that connection off at the API.
192
+
193
+ ## Claude Code skill
194
+
195
+ `skills/strait-setup/SKILL.md` teaches Claude Code how to add Strait to an app (React Native / Expo, Flutter,
196
+ Android, iOS, Unity, Capacitor, web, and a Node server). Copy the folder into `~/.claude/skills/` or a project's
197
+ `.claude/skills/`, or download it from https://straitlink.in/ai/strait-setup/SKILL.md.
198
+
199
+ The site repo owns it (`site/lib/skill.mjs`, fed by `site.config.json`, so install lines and versions match the
200
+ docs). Don't edit this copy by hand: run `npm run skill:sync` (needs `../site` or `SITE_DIR`). The site's tests fail
201
+ when this copy drifts.
202
+
203
+ ## Develop
204
+
205
+ ```sh
206
+ npm ci
207
+ npm run typecheck # Node, tests and the Worker
208
+ npm test # unit, protocol, Worker and an end-to-end test against a local engine
209
+ npm run build
210
+ npm run inspect # MCP Inspector CLI: lists the tools
211
+ npm run docs-index # rebuild src/docs-index.json from ../site/content/docs
212
+ npm run skill:sync # regenerate skills/strait-setup/SKILL.md from ../site
213
+ npm run deploy:check # wrangler dry run of the production Worker (nothing uploaded)
214
+ ```
215
+
216
+ The end-to-end test (`test/integration.test.ts`) starts the real engine from `../redirect-engine` (or
217
+ `ENGINE_DIR`) with its in-memory store, runs this server over stdio as a child process, creates a link and reads
218
+ it back. It is skipped when no engine checkout with installed dependencies is next to this repo.
219
+
220
+ ## Docs and support
221
+
222
+ - **Docs:** [straitlink.in/docs/](https://straitlink.in/docs/) · [platform status](https://straitlink.in/platform-status/) · [troubleshooting](https://straitlink.in/docs/troubleshooting/)
223
+ - **Talk to the Strait team:** [support@straitlink.in](mailto:support@straitlink.in) (replies within 1 working day, IST) or call +91 81218 61890.
224
+ - **Bugs and feature requests:** [open an issue](https://github.com/bazingga08/strait-mcp/issues) on this repo.
225
+ - **Security:** never in a public issue. Write to security@straitlink.in.
package/dist/client.js ADDED
@@ -0,0 +1,98 @@
1
+ /**
2
+ * A small client for the Strait HTTP API (https://strait.link). Web-standard only
3
+ * (fetch, URL), so the same code runs in Node (stdio server) and in Cloudflare
4
+ * Workers (remote server). Operation names follow the OpenAPI operationIds.
5
+ */
6
+ export const DEFAULT_API_URL = 'https://strait.link';
7
+ /** An error answer from the API, with its status and JSON body. */
8
+ export class StraitApiError extends Error {
9
+ status;
10
+ body;
11
+ operation;
12
+ constructor(status, body, operation) {
13
+ const msg = body && typeof body === 'object' && 'error' in body ? String(body.error) : `HTTP ${status}`;
14
+ super(`${operation}: ${msg} (HTTP ${status})`);
15
+ this.status = status;
16
+ this.body = body;
17
+ this.operation = operation;
18
+ this.name = 'StraitApiError';
19
+ }
20
+ }
21
+ /** True when this looks like a secret key (never a publishable key). */
22
+ export function isSecretKey(key) {
23
+ return !!key && /^st_(live|test)_[A-Za-z0-9_-]+$/.test(key) && !key.startsWith('st_pub_');
24
+ }
25
+ export class StraitClient {
26
+ apiUrl;
27
+ secretKey;
28
+ fetchImpl;
29
+ userAgent;
30
+ constructor(opts = {}) {
31
+ this.apiUrl = (opts.apiUrl ?? DEFAULT_API_URL).replace(/\/+$/, '');
32
+ this.secretKey = opts.secretKey;
33
+ this.fetchImpl = opts.fetch ?? ((...a) => fetch(...a));
34
+ this.userAgent = opts.userAgent;
35
+ }
36
+ get hasSecretKey() {
37
+ return isSecretKey(this.secretKey);
38
+ }
39
+ async call(operation, method, path, opts = {}) {
40
+ const auth = opts.auth ?? true;
41
+ if (auth && !this.hasSecretKey) {
42
+ throw new StraitApiError(401, { error: 'no secret key configured: set STRAIT_SECRET_KEY to a key from Dashboard → Settings → Secret keys (st_live_…)' }, operation);
43
+ }
44
+ const url = new URL(this.apiUrl + path);
45
+ for (const [k, v] of Object.entries(opts.query ?? {}))
46
+ if (v !== undefined && v !== '')
47
+ url.searchParams.set(k, String(v));
48
+ const headers = { accept: 'application/json' };
49
+ if (auth)
50
+ headers.authorization = `Bearer ${this.secretKey}`;
51
+ if (opts.body !== undefined)
52
+ headers['content-type'] = 'application/json';
53
+ if (this.userAgent)
54
+ headers['user-agent'] = this.userAgent;
55
+ const res = await this.fetchImpl(url, { method, headers, body: opts.body === undefined ? undefined : JSON.stringify(opts.body) });
56
+ if (res.status === 204)
57
+ return undefined;
58
+ const text = await res.text();
59
+ let json = text;
60
+ try {
61
+ json = text ? JSON.parse(text) : null;
62
+ }
63
+ catch {
64
+ // not JSON: keep the text
65
+ }
66
+ if (!res.ok)
67
+ throw new StraitApiError(res.status, json, operation);
68
+ return json;
69
+ }
70
+ createLink(link) {
71
+ return this.call('createLink', 'POST', '/v1/links', { body: link });
72
+ }
73
+ batchCreateLinks(links) {
74
+ return this.call('batchCreateLinks', 'POST', '/v1/links/batch', { body: { links } });
75
+ }
76
+ getLink(slug) {
77
+ return this.call('getLink', 'GET', `/v1/links/${encodeURIComponent(slug)}`);
78
+ }
79
+ listLinks(opts = {}) {
80
+ return this.call('listLinks', 'GET', '/v1/links', { query: { limit: opts.limit ?? 50, cursor: opts.cursor } });
81
+ }
82
+ updateLink(slug, patch) {
83
+ return this.call('updateLink', 'PATCH', `/v1/links/${encodeURIComponent(slug)}`, { body: patch });
84
+ }
85
+ getAnalytics(q = {}) {
86
+ return this.call('getAnalytics', 'GET', '/v1/analytics', { query: q });
87
+ }
88
+ simulateTap(url, ua) {
89
+ return this.call('simulateTap', 'GET', '/v1/simulate', { query: { url, ua } });
90
+ }
91
+ checkAppLinks(domain) {
92
+ return this.call('checkAppLinks', 'GET', '/v1/tools/app-links', { query: { domain }, auth: false });
93
+ }
94
+ /** Live Tap Trace of the website demo (204 = no tap yet → null). */
95
+ getTapTrace(token) {
96
+ return this.call('getTapTrace', 'GET', `/v1/trace/${encodeURIComponent(token)}`, { auth: false }).then((r) => r ?? null);
97
+ }
98
+ }