otipi-mcp 0.0.0-stage → 0.1.1
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 +21 -0
- package/README.md +142 -2
- package/package.json +39 -4
- package/server.json +53 -0
- package/src/client.js +57 -0
- package/src/errors.js +53 -0
- package/src/index.js +39 -0
- package/src/protocol.js +67 -0
- package/src/server.js +31 -0
- package/src/snippets.js +227 -0
- package/src/tools.js +252 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Otipi
|
|
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,143 @@
|
|
|
1
|
-
|
|
1
|
+
<a href="https://otipi.co.il"><img src=".github/otipi-logo.png" alt="Otipi" width="64" height="64"></a>
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# otipi-mcp
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/otipi-mcp) [](https://github.com/otipi-il/otipi-mcp/actions/workflows/test.yml) [](LICENSE) [](https://otipi.co.il)
|
|
6
|
+
|
|
7
|
+
MCP server for [Otipi](https://otipi.co.il), an SMS, email and OTP API for Israel. It lets AI agents (Claude Code, Cursor, Claude Desktop, VS Code) send and verify one-time codes in test mode, check delivery, and generate ready-to-paste integration code for Next.js, Supabase and Express.
|
|
8
|
+
|
|
9
|
+
Zero runtime dependencies. Plain Node.js (>= 18), stdio transport.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
## Remote server, nothing to install
|
|
13
|
+
|
|
14
|
+
The same tools run at **https://otipi.co.il/mcp** (Streamable HTTP).
|
|
15
|
+
|
|
16
|
+
- **Claude.ai, ChatGPT** and other apps with connectors: add a custom connector with that address. You sign in to Otipi and allow it (OAuth); the app gets a test key of its own that you can revoke in the dashboard.
|
|
17
|
+
- **Claude Code**: `claude mcp add --transport http otipi https://otipi.co.il/mcp --header "Authorization: Bearer sk_test_..."`
|
|
18
|
+
- **Cursor** (`.cursor/mcp.json`): `{ "mcpServers": { "otipi": { "url": "https://otipi.co.il/mcp", "headers": { "Authorization": "Bearer sk_test_..." } } } }`
|
|
19
|
+
- **VS Code**: `{ "name": "otipi", "type": "http", "url": "https://otipi.co.il/mcp", "headers": { "Authorization": "Bearer sk_test_..." } }`
|
|
20
|
+
|
|
21
|
+
A free test key comes in one click after sign-up at https://otipi.co.il/signup. This npm package is the local alternative for clients that only run stdio servers.
|
|
22
|
+
|
|
23
|
+
## Get a key
|
|
24
|
+
|
|
25
|
+
Sign up at https://otipi.co.il/signup to get a free test key (`sk_test_...`). Live keys (`sk_live_...`) send real messages and need a subscription.
|
|
26
|
+
|
|
27
|
+
The key is read only from the `OTIPI_KEY` environment variable (`OTIPI_API_KEY` is accepted as a fallback). `OTIPI_BASE_URL` is optional and defaults to `https://otipi.co.il`.
|
|
28
|
+
|
|
29
|
+
## Install
|
|
30
|
+
|
|
31
|
+
### Claude Code
|
|
32
|
+
|
|
33
|
+
```
|
|
34
|
+
claude mcp add otipi --env OTIPI_KEY=sk_test_... -- npx -y otipi-mcp
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Cursor
|
|
38
|
+
|
|
39
|
+
`.cursor/mcp.json`:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{
|
|
43
|
+
"mcpServers": {
|
|
44
|
+
"otipi": {
|
|
45
|
+
"command": "npx",
|
|
46
|
+
"args": ["-y", "otipi-mcp"],
|
|
47
|
+
"env": { "OTIPI_KEY": "sk_test_..." }
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Claude Desktop
|
|
54
|
+
|
|
55
|
+
`claude_desktop_config.json`:
|
|
56
|
+
|
|
57
|
+
```json
|
|
58
|
+
{
|
|
59
|
+
"mcpServers": {
|
|
60
|
+
"otipi": {
|
|
61
|
+
"command": "npx",
|
|
62
|
+
"args": ["-y", "otipi-mcp"],
|
|
63
|
+
"env": { "OTIPI_KEY": "sk_test_..." }
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### VS Code
|
|
70
|
+
|
|
71
|
+
`.vscode/mcp.json`:
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{
|
|
75
|
+
"servers": {
|
|
76
|
+
"otipi": {
|
|
77
|
+
"type": "stdio",
|
|
78
|
+
"command": "npx",
|
|
79
|
+
"args": ["-y", "otipi-mcp"],
|
|
80
|
+
"env": { "OTIPI_KEY": "sk_test_..." }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
On Windows, if `npx` is not found by your client, use `"command": "cmd", "args": ["/c", "npx", "-y", "otipi-mcp"]`.
|
|
87
|
+
|
|
88
|
+
## Test-mode flow
|
|
89
|
+
|
|
90
|
+
With a test key, messages to anyone are only kept in the Otipi log (sandbox). Messages to your own numbers or emails really arrive once you confirm them with a code. Each account gets 5 free test SMS for life.
|
|
91
|
+
|
|
92
|
+
1. `add_test_recipient` with your number (`+9725XXXXXXXX`). A 6-digit code is sent to it.
|
|
93
|
+
2. The human reads the code on the device.
|
|
94
|
+
3. `confirm_test_recipient` with the number and the code.
|
|
95
|
+
4. `send_test_otp` now really delivers. The result states whether delivery was real or sandbox.
|
|
96
|
+
5. `verify_otp` with the code the human received (or the `test_code` returned in test mode).
|
|
97
|
+
|
|
98
|
+
## Tools
|
|
99
|
+
|
|
100
|
+
| Tool | What it does |
|
|
101
|
+
| --- | --- |
|
|
102
|
+
| `send_test_otp` | Send an OTP (sms or email). Reports real vs sandbox delivery and includes `test_code`. |
|
|
103
|
+
| `verify_otp` | Check a code for a recipient. |
|
|
104
|
+
| `add_test_recipient` | Start confirming a number or email as a test recipient. |
|
|
105
|
+
| `confirm_test_recipient` | Finish confirmation with the 6-digit code. |
|
|
106
|
+
| `list_test_recipients` | List recipients and the free test SMS left. |
|
|
107
|
+
| `check_delivery_status` | Look up a message and its event timeline. |
|
|
108
|
+
| `get_integration_snippet` | Offline, no key needed. Code for `nextjs`, `supabase` or `express` (`ts` or `js`). |
|
|
109
|
+
|
|
110
|
+
Tool failures are returned as normal results with `isError: true` and a plain explanation of what to do next.
|
|
111
|
+
|
|
112
|
+
## Security notes
|
|
113
|
+
|
|
114
|
+
- The API key lives in the environment only. It is never printed, logged or returned by any tool.
|
|
115
|
+
- Use free `sk_test_` keys for development. Do not put `sk_live_` keys into shared config files or repositories.
|
|
116
|
+
- Requests use a 15 second timeout, no redirects, and `Authorization: Bearer` over HTTPS.
|
|
117
|
+
- stdout carries only JSON-RPC messages; diagnostics go to stderr.
|
|
118
|
+
|
|
119
|
+
## Development
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
npm test
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
The tests spawn the server and drive it over stdio against a local fake Otipi API. No network access is needed.
|
|
126
|
+
|
|
127
|
+
## Publishing (for maintainers)
|
|
128
|
+
|
|
129
|
+
Not automated: a maintainer runs these by hand.
|
|
130
|
+
|
|
131
|
+
The GitHub owner is set to `otipi-il` in `package.json` (`mcpName`, `repository`) and `server.json` (`name`, `repository`). The `mcpName` must start with `io.github.<github-username>/` for GitHub login, so adjust all of these together if the repository lives under a different owner.
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
npm publish --access public
|
|
135
|
+
mcp-publisher login github
|
|
136
|
+
mcp-publisher publish
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
Keep `version` in `package.json` and `server.json` (both the top level and the package entry) identical on every release. `node scripts/validate-server-json.mjs <schema.json>` checks `server.json` against the schema from `https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json`.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "otipi-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "MCP server for Otipi: send and verify SMS, email and OTP codes in Israel from AI agents.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"otipi-mcp": "src/index.js"
|
|
8
|
+
},
|
|
9
|
+
"mcpName": "io.github.otipi-il/otipi-mcp",
|
|
10
|
+
"main": "src/server.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"src",
|
|
13
|
+
"server.json",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "node --test"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"mcp",
|
|
25
|
+
"model-context-protocol",
|
|
26
|
+
"otipi",
|
|
27
|
+
"sms",
|
|
28
|
+
"otp",
|
|
29
|
+
"israel",
|
|
30
|
+
"sms-israel",
|
|
31
|
+
"2fa",
|
|
32
|
+
"supabase",
|
|
33
|
+
"nextjs"
|
|
34
|
+
],
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "git+https://github.com/otipi-il/otipi-mcp.git"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://otipi.co.il"
|
|
41
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.otipi-il/otipi-mcp",
|
|
4
|
+
"title": "Otipi",
|
|
5
|
+
"description": "Send and verify SMS, email and OTP codes in Israel. Free test key, Next.js and Supabase snippets.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"url": "https://github.com/otipi-il/otipi-mcp",
|
|
8
|
+
"source": "github"
|
|
9
|
+
},
|
|
10
|
+
"version": "0.1.1",
|
|
11
|
+
"websiteUrl": "https://otipi.co.il",
|
|
12
|
+
"packages": [
|
|
13
|
+
{
|
|
14
|
+
"registryType": "npm",
|
|
15
|
+
"identifier": "otipi-mcp",
|
|
16
|
+
"version": "0.1.1",
|
|
17
|
+
"transport": {
|
|
18
|
+
"type": "stdio"
|
|
19
|
+
},
|
|
20
|
+
"environmentVariables": [
|
|
21
|
+
{
|
|
22
|
+
"name": "OTIPI_KEY",
|
|
23
|
+
"description": "Otipi API key. Use a free sk_test_ key from https://otipi.co.il/signup, or sk_live_ for real sending.",
|
|
24
|
+
"isRequired": true,
|
|
25
|
+
"isSecret": true,
|
|
26
|
+
"format": "string"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "OTIPI_BASE_URL",
|
|
30
|
+
"description": "Override the API base URL. Defaults to https://otipi.co.il.",
|
|
31
|
+
"isRequired": false,
|
|
32
|
+
"isSecret": false,
|
|
33
|
+
"format": "string",
|
|
34
|
+
"default": "https://otipi.co.il"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
"remotes": [
|
|
40
|
+
{
|
|
41
|
+
"type": "streamable-http",
|
|
42
|
+
"url": "https://otipi.co.il/mcp",
|
|
43
|
+
"headers": [
|
|
44
|
+
{
|
|
45
|
+
"name": "Authorization",
|
|
46
|
+
"description": "Bearer followed by an Otipi API key, for example \"Bearer sk_test_...\". Clients that support OAuth can sign in instead.",
|
|
47
|
+
"isRequired": false,
|
|
48
|
+
"isSecret": true
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
package/src/client.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Minimal Otipi HTTP client. The API key is read from env and never logged.
|
|
3
|
+
import { OtipiHttpError } from './errors.js';
|
|
4
|
+
|
|
5
|
+
export { OtipiHttpError };
|
|
6
|
+
|
|
7
|
+
const TIMEOUT_MS = 15000;
|
|
8
|
+
|
|
9
|
+
export function getKey() {
|
|
10
|
+
return (process.env.OTIPI_KEY || process.env.OTIPI_API_KEY || '').trim();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function getBaseUrl() {
|
|
14
|
+
return (process.env.OTIPI_BASE_URL || 'https://otipi.co.il').replace(/\/+$/, '');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {'GET'|'POST'} method
|
|
19
|
+
* @param {string} path path under /v1, starting with a slash
|
|
20
|
+
* @param {object} [body]
|
|
21
|
+
* @returns {Promise<any>} parsed JSON body of a 2xx response
|
|
22
|
+
*/
|
|
23
|
+
export async function api(method, path, body) {
|
|
24
|
+
const key = getKey();
|
|
25
|
+
if (!key) throw new OtipiHttpError(0, 'missing_key', 'OTIPI_KEY is not set');
|
|
26
|
+
const headers = { Authorization: `Bearer ${key}`, Accept: 'application/json' };
|
|
27
|
+
/** @type {RequestInit} */
|
|
28
|
+
const init = { method, headers, redirect: 'error', signal: AbortSignal.timeout(TIMEOUT_MS) };
|
|
29
|
+
if (body !== undefined) {
|
|
30
|
+
headers['Content-Type'] = 'application/json';
|
|
31
|
+
init.body = JSON.stringify(body);
|
|
32
|
+
}
|
|
33
|
+
let res;
|
|
34
|
+
try {
|
|
35
|
+
res = await fetch(`${getBaseUrl()}/v1${path}`, init);
|
|
36
|
+
} catch (err) {
|
|
37
|
+
const e = /** @type {any} */ (err);
|
|
38
|
+
if (e && (e.name === 'TimeoutError' || e.name === 'AbortError')) {
|
|
39
|
+
throw new OtipiHttpError(0, 'timeout', `Request timed out after ${TIMEOUT_MS / 1000}s`);
|
|
40
|
+
}
|
|
41
|
+
throw new OtipiHttpError(0, 'network_error', `Could not reach Otipi at ${getBaseUrl()}: ${e && e.message}`);
|
|
42
|
+
}
|
|
43
|
+
const raw = await res.text();
|
|
44
|
+
/** @type {any} */
|
|
45
|
+
let data = null;
|
|
46
|
+
try {
|
|
47
|
+
data = raw ? JSON.parse(raw) : null;
|
|
48
|
+
} catch {
|
|
49
|
+
data = null;
|
|
50
|
+
}
|
|
51
|
+
if (!res.ok) {
|
|
52
|
+
const code = (data && data.error && data.error.code) || `http_${res.status}`;
|
|
53
|
+
const message = (data && data.error && data.error.message) || `HTTP ${res.status}`;
|
|
54
|
+
throw new OtipiHttpError(res.status, code, message);
|
|
55
|
+
}
|
|
56
|
+
return data;
|
|
57
|
+
}
|
package/src/errors.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Errors of the Otipi MCP tools and how they are explained to the agent.
|
|
3
|
+
// Shared as is by the npm package (stdio) and the Otipi service (/mcp over HTTP): keep the copies the same.
|
|
4
|
+
|
|
5
|
+
export class ToolError extends Error {}
|
|
6
|
+
|
|
7
|
+
export class OtipiHttpError extends Error {
|
|
8
|
+
/**
|
|
9
|
+
* @param {number} status HTTP status, 0 for network errors
|
|
10
|
+
* @param {string} code
|
|
11
|
+
* @param {string} message
|
|
12
|
+
*/
|
|
13
|
+
constructor(status, code, message) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.status = status;
|
|
16
|
+
this.code = code;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Hints keyed by API error code. */
|
|
21
|
+
const HINTS = {
|
|
22
|
+
test_key_required: 'This action only works with a test key (sk_test_...). You are using a live key.',
|
|
23
|
+
too_many_test_recipients: 'The account reached the limit of test recipients. Ask the human to remove one in the Otipi dashboard.',
|
|
24
|
+
invalid_recipient: 'The recipient is not valid. Use an Israeli mobile number like +972501234567 or a valid email address.',
|
|
25
|
+
rate_limited: 'Too many requests. Wait a minute and try again.',
|
|
26
|
+
test_mode_busy: 'Test mode is busy right now. Retry in a few seconds.',
|
|
27
|
+
not_found: 'Nothing pending for this recipient. Call add_test_recipient first.',
|
|
28
|
+
wrong_code: 'The code is wrong. Ask the human to re-check the code they received.',
|
|
29
|
+
code_expired: 'The code expired. Call add_test_recipient again to get a new one.',
|
|
30
|
+
too_many_attempts: 'Too many wrong attempts. Wait a few minutes, then call add_test_recipient again.',
|
|
31
|
+
free_test_sms_used:
|
|
32
|
+
'The 5 free test SMS of this account are used up. Use the email channel, reuse test_code from earlier sends, or subscribe at https://otipi.co.il to get a live key.',
|
|
33
|
+
too_many_codes: 'Too many codes were requested for this number. Wait a few minutes before sending another.',
|
|
34
|
+
subscription_required: 'Live keys need an active monthly subscription. Use a free test key (sk_test_) to try things, or subscribe in the Otipi dashboard.',
|
|
35
|
+
unauthorized: 'The API key was rejected. It must start with sk_test_ or sk_live_ and must not be revoked.',
|
|
36
|
+
invalid_api_key: 'The API key was rejected. It must start with sk_test_ or sk_live_ and must not be revoked.',
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @param {unknown} err
|
|
41
|
+
* @param {string} [signupHelp] what to say when there is no key at all
|
|
42
|
+
* @returns {string}
|
|
43
|
+
*/
|
|
44
|
+
export function explainError(err, signupHelp = '') {
|
|
45
|
+
if (err instanceof ToolError) return err.message;
|
|
46
|
+
if (err instanceof OtipiHttpError) {
|
|
47
|
+
if (err.code === 'missing_key') return signupHelp || err.message;
|
|
48
|
+
const hint = /** @type {Record<string,string>} */ (HINTS)[err.code] || (err.status === 401 ? HINTS.unauthorized : '');
|
|
49
|
+
const head = err.status ? `Otipi API error ${err.status} ${err.code}: ${err.message}` : `${err.code}: ${err.message}`;
|
|
50
|
+
return hint ? `${head}\n${hint}` : head;
|
|
51
|
+
}
|
|
52
|
+
return `Unexpected error: ${err instanceof Error ? err.message : String(err)}`;
|
|
53
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @ts-check
|
|
3
|
+
// Stdio entry point: newline-delimited JSON-RPC 2.0 on stdin/stdout. Logs go to stderr only.
|
|
4
|
+
import { createInterface } from 'node:readline';
|
|
5
|
+
import { handleMessage } from './server.js';
|
|
6
|
+
|
|
7
|
+
/** @param {unknown} obj */
|
|
8
|
+
function send(obj) {
|
|
9
|
+
process.stdout.write(JSON.stringify(obj) + '\n');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
13
|
+
let pending = 0;
|
|
14
|
+
let closed = false;
|
|
15
|
+
|
|
16
|
+
rl.on('line', (line) => {
|
|
17
|
+
const text = line.trim();
|
|
18
|
+
if (!text) return;
|
|
19
|
+
pending++;
|
|
20
|
+
handleMessage(text)
|
|
21
|
+
.then((out) => {
|
|
22
|
+
if (out === null) return;
|
|
23
|
+
for (const item of Array.isArray(out) ? out : [out]) send(item);
|
|
24
|
+
})
|
|
25
|
+
.catch((err) => {
|
|
26
|
+
console.error('otipi-mcp: internal error:', err && err.message);
|
|
27
|
+
})
|
|
28
|
+
.finally(() => {
|
|
29
|
+
pending--;
|
|
30
|
+
if (closed && pending === 0) process.exit(0);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
rl.on('close', () => {
|
|
35
|
+
closed = true;
|
|
36
|
+
if (pending === 0) process.exit(0);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
console.error('otipi-mcp: ready on stdio');
|
package/src/protocol.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// JSON-RPC 2.0 handling of the Model Context Protocol, for any transport.
|
|
3
|
+
// Shared as is by the npm package (stdio) and the Otipi service (/mcp over HTTP): keep the copies the same.
|
|
4
|
+
import { explainError } from './errors.js';
|
|
5
|
+
|
|
6
|
+
export const SUPPORTED_VERSIONS = ['2025-06-18', '2025-03-26', '2024-11-05'];
|
|
7
|
+
|
|
8
|
+
export const INSTRUCTIONS =
|
|
9
|
+
'Otipi sends SMS, email and OTP codes to Israeli numbers. Use a free test key (sk_test_, https://otipi.co.il/signup). ' +
|
|
10
|
+
'Test mode only really delivers to numbers the account owner confirmed: add_test_recipient, ask the human for the 6-digit code, ' +
|
|
11
|
+
'confirm_test_recipient, then send_test_otp and verify_otp. Unconfirmed numbers are sandbox only (nothing arrives). ' +
|
|
12
|
+
'Phone format: +9725XXXXXXXX. get_integration_snippet returns Next.js, Supabase and Express code and needs no key.';
|
|
13
|
+
|
|
14
|
+
/** @param {any} id @param {number} code @param {string} message */
|
|
15
|
+
export const rpcError = (id, code, message) => ({ jsonrpc: '2.0', id: id ?? null, error: { code, message } });
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @param {{ tools: Array<{ name: string, description: string, inputSchema: object, run: (args: any) => Promise<string> }>, name: string, version: string, signupHelp?: string }} options
|
|
19
|
+
* @returns {(msg: any) => Promise<object|null>} handles one parsed message; null when no response is due
|
|
20
|
+
*/
|
|
21
|
+
export function createHandler({ tools, name, version, signupHelp = '' }) {
|
|
22
|
+
return async function handle(msg) {
|
|
23
|
+
if (!msg || typeof msg !== 'object' || Array.isArray(msg) || typeof msg.method !== 'string') {
|
|
24
|
+
return rpcError(msg && msg.id, -32600, 'Invalid Request');
|
|
25
|
+
}
|
|
26
|
+
const isNotification = msg.id === undefined || msg.id === null;
|
|
27
|
+
const { id, method, params } = msg;
|
|
28
|
+
|
|
29
|
+
switch (method) {
|
|
30
|
+
case 'initialize': {
|
|
31
|
+
const asked = params && params.protocolVersion;
|
|
32
|
+
return {
|
|
33
|
+
jsonrpc: '2.0',
|
|
34
|
+
id,
|
|
35
|
+
result: {
|
|
36
|
+
protocolVersion: SUPPORTED_VERSIONS.includes(asked) ? asked : SUPPORTED_VERSIONS[0],
|
|
37
|
+
capabilities: { tools: {} },
|
|
38
|
+
serverInfo: { name, version },
|
|
39
|
+
instructions: INSTRUCTIONS,
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
case 'ping':
|
|
44
|
+
return isNotification ? null : { jsonrpc: '2.0', id, result: {} };
|
|
45
|
+
case 'tools/list':
|
|
46
|
+
return {
|
|
47
|
+
jsonrpc: '2.0',
|
|
48
|
+
id,
|
|
49
|
+
result: { tools: tools.map(({ name: toolName, description, inputSchema }) => ({ name: toolName, description, inputSchema })) },
|
|
50
|
+
};
|
|
51
|
+
case 'tools/call': {
|
|
52
|
+
const toolName = params && params.name;
|
|
53
|
+
const tool = tools.find((t) => t.name === toolName);
|
|
54
|
+
if (!tool) return rpcError(id, -32602, `Unknown tool: ${toolName}`);
|
|
55
|
+
try {
|
|
56
|
+
const text = await tool.run((params && params.arguments) || {});
|
|
57
|
+
return { jsonrpc: '2.0', id, result: { content: [{ type: 'text', text }] } };
|
|
58
|
+
} catch (err) {
|
|
59
|
+
return { jsonrpc: '2.0', id, result: { isError: true, content: [{ type: 'text', text: explainError(err, signupHelp) }] } };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
default:
|
|
63
|
+
if (isNotification) return null; // notifications/initialized and other notifications
|
|
64
|
+
return rpcError(id, -32601, `Method not found: ${method}`);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
package/src/server.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The npm package's side: the key comes from the environment, and each stdin line is one message.
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { api, getKey } from './client.js';
|
|
5
|
+
import { createTools, STDIO_SIGNUP_HELP } from './tools.js';
|
|
6
|
+
import { createHandler, rpcError } from './protocol.js';
|
|
7
|
+
|
|
8
|
+
const pkg = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
|
|
9
|
+
export const VERSION = pkg.version;
|
|
10
|
+
|
|
11
|
+
const handle = createHandler({
|
|
12
|
+
tools: createTools({ api, hasKey: () => Boolean(getKey()) }),
|
|
13
|
+
name: 'otipi-mcp',
|
|
14
|
+
version: VERSION,
|
|
15
|
+
signupHelp: STDIO_SIGNUP_HELP,
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Handle one raw JSON line. Returns a response object, or null when no response is due.
|
|
20
|
+
* @param {string} line
|
|
21
|
+
* @returns {Promise<object|null>}
|
|
22
|
+
*/
|
|
23
|
+
export async function handleMessage(line) {
|
|
24
|
+
let msg;
|
|
25
|
+
try {
|
|
26
|
+
msg = JSON.parse(line);
|
|
27
|
+
} catch {
|
|
28
|
+
return rpcError(null, -32700, 'Parse error');
|
|
29
|
+
}
|
|
30
|
+
return handle(msg);
|
|
31
|
+
}
|
package/src/snippets.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Offline integration snippets. No API calls, no key needed.
|
|
3
|
+
|
|
4
|
+
const PHONE_RE = String.raw`/^(\+9725\d{8}|05\d{8})$/`;
|
|
5
|
+
|
|
6
|
+
/** @param {boolean} ts */
|
|
7
|
+
function nextjs(ts) {
|
|
8
|
+
const x = ts ? 'ts' : 'js';
|
|
9
|
+
const xx = ts ? 'tsx' : 'jsx';
|
|
10
|
+
const bang = ts ? '!' : '';
|
|
11
|
+
const reqT = ts ? ': Request' : '';
|
|
12
|
+
const anyT = ts ? ': any' : '';
|
|
13
|
+
const strT = ts ? ': string' : '';
|
|
14
|
+
const body = ts
|
|
15
|
+
? '(await req.json().catch(() => ({}))) as { to?: string; code?: string }'
|
|
16
|
+
: 'await req.json().catch(() => ({}))';
|
|
17
|
+
return String.raw`Next.js (App Router). Install the SDK and set the key (server only, never in a client component):
|
|
18
|
+
|
|
19
|
+
npm install otipi
|
|
20
|
+
|
|
21
|
+
# .env.local
|
|
22
|
+
OTIPI_KEY=sk_test_...
|
|
23
|
+
|
|
24
|
+
// File: lib/otipi.${x}
|
|
25
|
+
import { Otipi } from 'otipi';
|
|
26
|
+
|
|
27
|
+
export const otipi = new Otipi(process.env.OTIPI_KEY${bang});
|
|
28
|
+
|
|
29
|
+
// File: app/api/otp/send/route.${x}
|
|
30
|
+
import { NextResponse } from 'next/server';
|
|
31
|
+
import { OtipiError } from 'otipi';
|
|
32
|
+
import { otipi } from '@/lib/otipi';
|
|
33
|
+
|
|
34
|
+
const PHONE_RE = ${PHONE_RE};
|
|
35
|
+
|
|
36
|
+
export async function POST(req${reqT}) {
|
|
37
|
+
const { to } = ${body};
|
|
38
|
+
if (!to || !PHONE_RE.test(to)) {
|
|
39
|
+
return NextResponse.json({ error: 'invalid_phone' }, { status: 422 });
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const otp = await otipi.otp.send({ to, app: 'MyApp' });
|
|
43
|
+
return NextResponse.json({ id: otp.id, expiresAt: otp.expires_at });
|
|
44
|
+
} catch (err${anyT}) {
|
|
45
|
+
if (err instanceof OtipiError) {
|
|
46
|
+
return NextResponse.json({ error: err.code }, { status: err.status });
|
|
47
|
+
}
|
|
48
|
+
return NextResponse.json({ error: 'internal_error' }, { status: 500 });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// File: app/api/otp/verify/route.${x}
|
|
53
|
+
import { NextResponse } from 'next/server';
|
|
54
|
+
import { OtipiError } from 'otipi';
|
|
55
|
+
import { otipi } from '@/lib/otipi';
|
|
56
|
+
|
|
57
|
+
const PHONE_RE = ${PHONE_RE};
|
|
58
|
+
|
|
59
|
+
export async function POST(req${reqT}) {
|
|
60
|
+
const { to, code } = ${body};
|
|
61
|
+
if (!to || !PHONE_RE.test(to) || !code) {
|
|
62
|
+
return NextResponse.json({ error: 'invalid_input' }, { status: 422 });
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const result = await otipi.otp.verify({ to, code });
|
|
66
|
+
return NextResponse.json({ valid: result.valid, reason: result.reason ?? null });
|
|
67
|
+
} catch (err${anyT}) {
|
|
68
|
+
if (err instanceof OtipiError) {
|
|
69
|
+
return NextResponse.json({ error: err.code }, { status: err.status });
|
|
70
|
+
}
|
|
71
|
+
return NextResponse.json({ error: 'internal_error' }, { status: 500 });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// File: app/otp/page.${xx}
|
|
76
|
+
'use client';
|
|
77
|
+
import { useState } from 'react';
|
|
78
|
+
|
|
79
|
+
export default function OtpPage() {
|
|
80
|
+
const [phone, setPhone] = useState('');
|
|
81
|
+
const [code, setCode] = useState('');
|
|
82
|
+
const [sent, setSent] = useState(false);
|
|
83
|
+
const [message, setMessage] = useState('');
|
|
84
|
+
|
|
85
|
+
async function post(url${strT}, payload${ts ? ': object' : ''}) {
|
|
86
|
+
const res = await fetch(url, {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: { 'Content-Type': 'application/json' },
|
|
89
|
+
body: JSON.stringify(payload),
|
|
90
|
+
});
|
|
91
|
+
return res.json();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function sendCode() {
|
|
95
|
+
const data = await post('/api/otp/send', { to: phone });
|
|
96
|
+
if (data.error) return setMessage('Error: ' + data.error);
|
|
97
|
+
setSent(true);
|
|
98
|
+
setMessage('Code sent');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function verifyCode() {
|
|
102
|
+
const data = await post('/api/otp/verify', { to: phone, code });
|
|
103
|
+
setMessage(data.valid ? 'Verified' : 'Wrong or expired code');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return (
|
|
107
|
+
<main>
|
|
108
|
+
<input value={phone} onChange={(e) => setPhone(e.target.value)} placeholder="+972501234567" />
|
|
109
|
+
<button onClick={sendCode}>Send code</button>
|
|
110
|
+
{sent && (
|
|
111
|
+
<>
|
|
112
|
+
<input value={code} onChange={(e) => setCode(e.target.value)} placeholder="Code" />
|
|
113
|
+
<button onClick={verifyCode}>Verify</button>
|
|
114
|
+
</>
|
|
115
|
+
)}
|
|
116
|
+
<p>{message}</p>
|
|
117
|
+
</main>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function supabase() {
|
|
124
|
+
return String.raw`Supabase Auth with Israeli SMS and email via Otipi (Send SMS hook, Send Email hook). No code is needed on the server.
|
|
125
|
+
|
|
126
|
+
1. In the Otipi dashboard open the Connect page, tab "Supabase, SMS" (and "Supabase, email" for the auth emails).
|
|
127
|
+
Copy the hook address (https://otipi.co.il/v1/integrations/supabase/sms/<token>) and its secret (v1,whsec_...).
|
|
128
|
+
|
|
129
|
+
2. In the Supabase Dashboard: Authentication > Hooks > Send SMS hook > HTTPS.
|
|
130
|
+
Paste the address and the secret. Do not add an Authorization header: Otipi checks the Standard Webhooks signature.
|
|
131
|
+
For emails, add a Send Email hook the same way and write your Supabase project URL on the Otipi Connect page.
|
|
132
|
+
|
|
133
|
+
3. Client code (supabase-js):
|
|
134
|
+
|
|
135
|
+
// Request the code
|
|
136
|
+
const { error } = await supabase.auth.signInWithOtp({ phone: '+972501234567' });
|
|
137
|
+
|
|
138
|
+
// Verify the code the user received
|
|
139
|
+
const { data, error: verifyError } = await supabase.auth.verifyOtp({
|
|
140
|
+
phone: '+972501234567',
|
|
141
|
+
token: '123456',
|
|
142
|
+
type: 'sms',
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
The hook starts in test mode: codes really reach only your own confirmed phone (5 free SMS); switch the hook to live mode on the Connect page once a plan is active.
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** @param {boolean} ts */
|
|
150
|
+
function express(ts) {
|
|
151
|
+
const x = ts ? 'ts' : 'js';
|
|
152
|
+
const bang = ts ? '!' : '';
|
|
153
|
+
const reqT = ts ? ': Request' : '';
|
|
154
|
+
const resT = ts ? ': Response' : '';
|
|
155
|
+
const anyT = ts ? ': any' : '';
|
|
156
|
+
const imp = ts ? "import express, { Request, Response } from 'express';" : "import express from 'express';";
|
|
157
|
+
return String.raw`Express. Install and set the key:
|
|
158
|
+
|
|
159
|
+
npm install express otipi
|
|
160
|
+
export OTIPI_KEY=sk_test_...
|
|
161
|
+
|
|
162
|
+
// File: server.${x}
|
|
163
|
+
${imp}
|
|
164
|
+
import { Otipi, OtipiError } from 'otipi';
|
|
165
|
+
|
|
166
|
+
const otipi = new Otipi(process.env.OTIPI_KEY${bang});
|
|
167
|
+
const PHONE_RE = ${PHONE_RE};
|
|
168
|
+
|
|
169
|
+
const app = express();
|
|
170
|
+
app.use(express.json());
|
|
171
|
+
|
|
172
|
+
app.post('/otp/send', async (req${reqT}, res${resT}) => {
|
|
173
|
+
const { to } = req.body ?? {};
|
|
174
|
+
if (!to || !PHONE_RE.test(to)) return res.status(422).json({ error: 'invalid_phone' });
|
|
175
|
+
try {
|
|
176
|
+
const otp = await otipi.otp.send({ to, app: 'MyApp' });
|
|
177
|
+
res.status(201).json({ id: otp.id, expiresAt: otp.expires_at });
|
|
178
|
+
} catch (err${anyT}) {
|
|
179
|
+
if (err instanceof OtipiError) return res.status(err.status).json({ error: err.code });
|
|
180
|
+
res.status(500).json({ error: 'internal_error' });
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
app.post('/otp/verify', async (req${reqT}, res${resT}) => {
|
|
185
|
+
const { to, code } = req.body ?? {};
|
|
186
|
+
if (!to || !PHONE_RE.test(to) || !code) return res.status(422).json({ error: 'invalid_input' });
|
|
187
|
+
try {
|
|
188
|
+
const result = await otipi.otp.verify({ to, code });
|
|
189
|
+
res.json({ valid: result.valid, reason: result.reason ?? null });
|
|
190
|
+
} catch (err${anyT}) {
|
|
191
|
+
if (err instanceof OtipiError) return res.status(err.status).json({ error: err.code });
|
|
192
|
+
res.status(500).json({ error: 'internal_error' });
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
app.listen(3000);
|
|
197
|
+
`;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const SDK_NOTE = `
|
|
201
|
+
SDK reference (npm package "otipi"):
|
|
202
|
+
new Otipi(apiKey, { baseUrl? })
|
|
203
|
+
otipi.otp.send({ to, app, channel?, language?, length?, ttlMinutes? })
|
|
204
|
+
otipi.otp.verify({ to, code })
|
|
205
|
+
otipi.send({ channel, to, text | template + variables, subject?, from?, language? })
|
|
206
|
+
otipi.messages.get(id)
|
|
207
|
+
Errors throw OtipiError with .status and .code.
|
|
208
|
+
`;
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* @param {string} framework
|
|
212
|
+
* @param {string} [language]
|
|
213
|
+
* @returns {string}
|
|
214
|
+
*/
|
|
215
|
+
export function getSnippet(framework, language = 'ts') {
|
|
216
|
+
const ts = language !== 'js';
|
|
217
|
+
switch (framework) {
|
|
218
|
+
case 'nextjs':
|
|
219
|
+
return nextjs(ts) + SDK_NOTE;
|
|
220
|
+
case 'supabase':
|
|
221
|
+
return supabase();
|
|
222
|
+
case 'express':
|
|
223
|
+
return express(ts) + SDK_NOTE;
|
|
224
|
+
default:
|
|
225
|
+
throw new Error(`Unknown framework "${framework}". Use nextjs, supabase or express.`);
|
|
226
|
+
}
|
|
227
|
+
}
|
package/src/tools.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
// Tool definitions and handlers. Handlers return text; errors are thrown as ToolError.
|
|
3
|
+
// Shared as is by the npm package (stdio) and the Otipi service (/mcp over HTTP): keep the copies the same.
|
|
4
|
+
// The transport hands in { api, hasKey, signupHelp }: how to call the Otipi API with the caller's key.
|
|
5
|
+
import { ToolError, explainError } from './errors.js';
|
|
6
|
+
import { getSnippet } from './snippets.js';
|
|
7
|
+
|
|
8
|
+
export { ToolError };
|
|
9
|
+
|
|
10
|
+
export const STDIO_SIGNUP_HELP =
|
|
11
|
+
'No Otipi API key found. Get a free test key at https://otipi.co.il/signup (it starts with sk_test_), ' +
|
|
12
|
+
'then set it as the OTIPI_KEY environment variable in your MCP client config, for example: ' +
|
|
13
|
+
'"env": { "OTIPI_KEY": "sk_test_..." }, and restart the client. ' +
|
|
14
|
+
'Claude Code: claude mcp add otipi --env OTIPI_KEY=sk_test_... -- npx -y otipi-mcp';
|
|
15
|
+
|
|
16
|
+
const PHONE_DESC =
|
|
17
|
+
'Israeli mobile number in E.164 format +9725XXXXXXXX (05XXXXXXXX is also accepted), or an email address for the email channel.';
|
|
18
|
+
|
|
19
|
+
/** @param {any} args @param {string} name @param {number} [max] */
|
|
20
|
+
function str(args, name, max) {
|
|
21
|
+
const v = args && args[name];
|
|
22
|
+
if (typeof v !== 'string' || !v.trim()) throw new ToolError(`Missing required argument "${name}" (non-empty string).`);
|
|
23
|
+
if (max && v.length > max) throw new ToolError(`Argument "${name}" is too long (max ${max} characters).`);
|
|
24
|
+
return v.trim();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** @param {any} args @param {string} name @param {string[]} allowed @param {string} def */
|
|
28
|
+
function oneOf(args, name, allowed, def) {
|
|
29
|
+
const v = args && args[name];
|
|
30
|
+
if (v === undefined || v === null || v === '') return def;
|
|
31
|
+
if (typeof v !== 'string' || !allowed.includes(v)) {
|
|
32
|
+
throw new ToolError(`Argument "${name}" must be one of: ${allowed.join(', ')}.`);
|
|
33
|
+
}
|
|
34
|
+
return v;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** @param {unknown} data */
|
|
38
|
+
const json = (data) => JSON.stringify(data, null, 2);
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @typedef {{ name: string, description: string, inputSchema: object, run: (args: any) => Promise<string>, offline?: boolean }} Tool
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param {{ api: (method: 'GET'|'POST', path: string, body?: object) => Promise<any>, hasKey: () => boolean, signupHelp?: string }} client
|
|
46
|
+
* @returns {Tool[]}
|
|
47
|
+
*/
|
|
48
|
+
export function createTools({ api, hasKey, signupHelp = STDIO_SIGNUP_HELP }) {
|
|
49
|
+
const requireKey = () => {
|
|
50
|
+
if (!hasKey()) throw new ToolError(signupHelp);
|
|
51
|
+
};
|
|
52
|
+
const explain = (/** @type {unknown} */ err) => explainError(err, signupHelp);
|
|
53
|
+
return [
|
|
54
|
+
{
|
|
55
|
+
name: 'send_test_otp',
|
|
56
|
+
description:
|
|
57
|
+
'Send a one-time verification code (OTP) by SMS or email to a phone number in Israel using Otipi, in test mode. ' +
|
|
58
|
+
'Use this to try the login/2FA flow end to end. With a test key the message really arrives ONLY if the recipient was confirmed ' +
|
|
59
|
+
'with add_test_recipient + confirm_test_recipient; otherwise it is kept in the sandbox log and nothing is delivered. ' +
|
|
60
|
+
'The result says which case happened and includes test_code when available, so you can verify it with verify_otp. ' +
|
|
61
|
+
'Each account has 5 free test SMS for life.',
|
|
62
|
+
inputSchema: {
|
|
63
|
+
type: 'object',
|
|
64
|
+
properties: {
|
|
65
|
+
to: { type: 'string', description: PHONE_DESC },
|
|
66
|
+
app: { type: 'string', maxLength: 40, description: 'Brand name shown in the message, for example "MyApp". Max 40 characters.' },
|
|
67
|
+
channel: { type: 'string', enum: ['sms', 'email'], default: 'sms', description: 'Delivery channel. Default sms.' },
|
|
68
|
+
language: { type: 'string', enum: ['he', 'ar', 'ru', 'en'], default: 'he', description: 'Message language. Default he (Hebrew).' },
|
|
69
|
+
},
|
|
70
|
+
required: ['to', 'app'],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
},
|
|
73
|
+
async run(args) {
|
|
74
|
+
requireKey();
|
|
75
|
+
const to = str(args, 'to');
|
|
76
|
+
const app = str(args, 'app', 40);
|
|
77
|
+
const channel = oneOf(args, 'channel', ['sms', 'email'], 'sms');
|
|
78
|
+
const language = oneOf(args, 'language', ['he', 'ar', 'ru', 'en'], 'he');
|
|
79
|
+
const otp = await api('POST', '/otp/send', { to, app, channel, language });
|
|
80
|
+
const lines = [`OTP request accepted (id ${otp.id}, channel ${otp.channel}, to ${otp.to}, expires ${otp.expires_at}).`];
|
|
81
|
+
if (otp.test_code) lines.push(`test_code: ${otp.test_code} (pass it to verify_otp to complete the check).`);
|
|
82
|
+
if (otp.message_id) {
|
|
83
|
+
try {
|
|
84
|
+
const msg = await api('GET', `/messages/${encodeURIComponent(otp.message_id)}`);
|
|
85
|
+
if (msg.test_delivery === 'real') {
|
|
86
|
+
lines.push('Delivery: REAL. The recipient is confirmed, so the code was actually sent to the device. Ask the human to read it.');
|
|
87
|
+
} else if (msg.test_delivery === 'sandbox') {
|
|
88
|
+
lines.push(
|
|
89
|
+
'Delivery: SANDBOX. Nothing was delivered to a device; the message only exists in the Otipi log. Either this number is not a confirmed test recipient, or real test delivery for this channel is not switched on yet (list_test_recipients shows which). ' +
|
|
90
|
+
'To receive real messages, call add_test_recipient with this number, ask the human for the 6-digit code they receive, then call confirm_test_recipient. ' +
|
|
91
|
+
(otp.test_code ? 'You can still complete the flow now using the test_code above.' : '')
|
|
92
|
+
);
|
|
93
|
+
} else {
|
|
94
|
+
lines.push(`Delivery status: ${msg.status}${msg.mode === 'live' ? ' (live mode)' : ''}.`);
|
|
95
|
+
}
|
|
96
|
+
lines.push(`message_id: ${otp.message_id} (use check_delivery_status for details).`);
|
|
97
|
+
} catch (err) {
|
|
98
|
+
lines.push(`message_id: ${otp.message_id}. Could not fetch delivery details: ${explain(err)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return lines.join('\n');
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: 'verify_otp',
|
|
106
|
+
description:
|
|
107
|
+
'Check a one-time code that was sent with send_test_otp (or the live API) for a phone number or email. ' +
|
|
108
|
+
'Returns valid true/false and, when false, the reason (wrong_code, expired_or_missing, too_many_attempts).',
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: {
|
|
112
|
+
to: { type: 'string', description: 'The same recipient the code was sent to.' },
|
|
113
|
+
code: { type: 'string', description: 'The code entered by the user.' },
|
|
114
|
+
},
|
|
115
|
+
required: ['to', 'code'],
|
|
116
|
+
additionalProperties: false,
|
|
117
|
+
},
|
|
118
|
+
async run(args) {
|
|
119
|
+
requireKey();
|
|
120
|
+
const to = str(args, 'to');
|
|
121
|
+
const code = str(args, 'code');
|
|
122
|
+
const r = await api('POST', '/otp/verify', { to, code });
|
|
123
|
+
if (r.valid) return 'Code is valid.';
|
|
124
|
+
const why = {
|
|
125
|
+
wrong_code: 'The code is wrong. Ask for the code again or send a new one.',
|
|
126
|
+
expired_or_missing: 'The code expired or was never sent. Call send_test_otp to send a new code.',
|
|
127
|
+
too_many_attempts: 'Too many wrong attempts. Wait a few minutes and send a new code.',
|
|
128
|
+
};
|
|
129
|
+
return `Code is NOT valid. Reason: ${r.reason}. ${/** @type {Record<string,string>} */ (why)[r.reason] || ''}`.trim();
|
|
130
|
+
},
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'add_test_recipient',
|
|
134
|
+
description:
|
|
135
|
+
'Start confirming a phone number or email as a test recipient. A 6-digit code is sent to it. Once confirmed, test messages to that ' +
|
|
136
|
+
'recipient really arrive (otherwise test mode only logs them in a sandbox). Only add numbers or emails that belong to the account owner. ' +
|
|
137
|
+
'Test key (sk_test_) only. After calling this, ask the human for the 6-digit code they received and call confirm_test_recipient.',
|
|
138
|
+
inputSchema: {
|
|
139
|
+
type: 'object',
|
|
140
|
+
properties: { to: { type: 'string', description: PHONE_DESC } },
|
|
141
|
+
required: ['to'],
|
|
142
|
+
additionalProperties: false,
|
|
143
|
+
},
|
|
144
|
+
async run(args) {
|
|
145
|
+
requireKey();
|
|
146
|
+
const to = str(args, 'to');
|
|
147
|
+
const r = await api('POST', '/test-recipients', { to });
|
|
148
|
+
if (r.status === 'confirmed') return `${r.to} (${r.channel}) is already confirmed. You can call send_test_otp now.`;
|
|
149
|
+
return (
|
|
150
|
+
`A 6-digit confirmation code was sent to ${r.to} (${r.channel}). ` +
|
|
151
|
+
'Ask the human to read the code on that device, then call confirm_test_recipient with the same "to" and the code.'
|
|
152
|
+
);
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
name: 'confirm_test_recipient',
|
|
157
|
+
description:
|
|
158
|
+
'Finish confirming a test recipient with the 6-digit code the human received after add_test_recipient. ' +
|
|
159
|
+
'On success, send_test_otp to this recipient is really delivered.',
|
|
160
|
+
inputSchema: {
|
|
161
|
+
type: 'object',
|
|
162
|
+
properties: {
|
|
163
|
+
to: { type: 'string', description: 'The same number or email passed to add_test_recipient.' },
|
|
164
|
+
code: { type: 'string', description: 'The 6-digit code the human received.' },
|
|
165
|
+
},
|
|
166
|
+
required: ['to', 'code'],
|
|
167
|
+
additionalProperties: false,
|
|
168
|
+
},
|
|
169
|
+
async run(args) {
|
|
170
|
+
requireKey();
|
|
171
|
+
const to = str(args, 'to');
|
|
172
|
+
const code = str(args, 'code');
|
|
173
|
+
const r = await api('POST', '/test-recipients/verify', { to, code });
|
|
174
|
+
return `${r.to} is now a confirmed test recipient (status ${r.status}). Real test messages to it will arrive. Call send_test_otp next.`;
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'list_test_recipients',
|
|
179
|
+
description:
|
|
180
|
+
'List the confirmed and pending test recipients of this account and how many of the 5 free test SMS are left. ' +
|
|
181
|
+
'Call it before send_test_otp to know whether a number will really receive messages.',
|
|
182
|
+
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
183
|
+
async run() {
|
|
184
|
+
requireKey();
|
|
185
|
+
const r = await api('GET', '/test-recipients');
|
|
186
|
+
const rows = (r.data || []).map((/** @type {any} */ x) => `- ${x.to} (${x.channel}): ${x.status}`);
|
|
187
|
+
const fs = r.free_sms;
|
|
188
|
+
const rd = r.real_delivery;
|
|
189
|
+
const off = rd ? ['sms', 'email'].filter((c) => rd[c] === false) : [];
|
|
190
|
+
return [
|
|
191
|
+
rows.length ? `Test recipients:\n${rows.join('\n')}` : 'No test recipients yet. Use add_test_recipient.',
|
|
192
|
+
fs ? `Free test SMS: ${fs.left} left of ${fs.total} (used ${fs.used}).` : '',
|
|
193
|
+
off.length ? `Real test delivery is not switched on yet for: ${off.join(', ')}. Messages of that channel stay in the sandbox; use test_code to finish the flow.` : '',
|
|
194
|
+
]
|
|
195
|
+
.filter(Boolean)
|
|
196
|
+
.join('\n');
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'check_delivery_status',
|
|
201
|
+
description:
|
|
202
|
+
'Look up a sent message by message_id (returned by send_test_otp) and report its status ' +
|
|
203
|
+
'(queued, sent, delivered, opened, failed, bounced), whether test delivery was real or sandbox, and the event timeline.',
|
|
204
|
+
inputSchema: {
|
|
205
|
+
type: 'object',
|
|
206
|
+
properties: { message_id: { type: 'string', description: 'The message id, as returned by send_test_otp.' } },
|
|
207
|
+
required: ['message_id'],
|
|
208
|
+
additionalProperties: false,
|
|
209
|
+
},
|
|
210
|
+
async run(args) {
|
|
211
|
+
requireKey();
|
|
212
|
+
const id = str(args, 'message_id');
|
|
213
|
+
const m = await api('GET', `/messages/${encodeURIComponent(id)}`);
|
|
214
|
+
const lines = [
|
|
215
|
+
`Message ${m.id}: ${m.status} (channel ${m.channel}, mode ${m.mode}${m.test_delivery ? `, test delivery ${m.test_delivery}` : ''}).`,
|
|
216
|
+
`To: ${m.to}${m.from ? `, from: ${m.from}` : ''}${m.segments ? `, segments: ${m.segments}` : ''}.`,
|
|
217
|
+
];
|
|
218
|
+
if (m.error) lines.push(`Error: ${m.error}`);
|
|
219
|
+
if (m.test_delivery === 'sandbox') lines.push('Sandbox: not delivered to a device. Confirm the recipient with add_test_recipient to receive real messages.');
|
|
220
|
+
const times = ['created_at', 'sent_at', 'delivered_at', 'opened_at'].filter((k) => m[k]).map((k) => `${k}=${m[k]}`);
|
|
221
|
+
if (times.length) lines.push(times.join(', '));
|
|
222
|
+
if (Array.isArray(m.events) && m.events.length) {
|
|
223
|
+
lines.push('Events:', ...m.events.map((/** @type {any} */ e) => `- ${e.at} ${e.type}${e.detail ? `: ${e.detail}` : ''}`));
|
|
224
|
+
}
|
|
225
|
+
return lines.join('\n');
|
|
226
|
+
},
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
name: 'get_integration_snippet',
|
|
230
|
+
description:
|
|
231
|
+
'Return ready-to-paste code for adding Otipi phone/OTP login to a project: Next.js App Router (API routes plus a client component), ' +
|
|
232
|
+
'Supabase Auth (Send SMS hook setup plus client code) or Express. Works offline and does not need an API key. ' +
|
|
233
|
+
'Use it when the user wants to integrate SMS verification or 2FA for Israeli numbers.',
|
|
234
|
+
offline: true,
|
|
235
|
+
inputSchema: {
|
|
236
|
+
type: 'object',
|
|
237
|
+
properties: {
|
|
238
|
+
framework: { type: 'string', enum: ['nextjs', 'supabase', 'express'], description: 'Target framework.' },
|
|
239
|
+
language: { type: 'string', enum: ['ts', 'js'], default: 'ts', description: 'Code language. Default ts.' },
|
|
240
|
+
},
|
|
241
|
+
required: ['framework'],
|
|
242
|
+
additionalProperties: false,
|
|
243
|
+
},
|
|
244
|
+
async run(args) {
|
|
245
|
+
const framework = oneOf(args, 'framework', ['nextjs', 'supabase', 'express'], '');
|
|
246
|
+
if (!framework) throw new ToolError('Missing required argument "framework" (nextjs, supabase or express).');
|
|
247
|
+
const language = oneOf(args, 'language', ['ts', 'js'], 'ts');
|
|
248
|
+
return getSnippet(framework, language);
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
];
|
|
252
|
+
}
|