@paymos/mcp 1.1.1 → 1.3.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/CHANGELOG.md +12 -0
- package/README.md +120 -104
- package/dist/index.js +429 -20
- package/package.json +7 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [1.3.0] - 2026-10-30
|
|
6
|
+
|
|
7
|
+
- fix(plugins): reject invalid Woo refund controls and unblock SDK checks
|
|
8
|
+
- feat: deliver local MCP setup and accumulated platform updates
|
|
9
|
+
- feat(invoices): accept full late payments without reopening invoices
|
|
10
|
+
|
|
11
|
+
## [1.2.0] - 2026-10-30
|
|
12
|
+
|
|
13
|
+
- fix(plugins): reject invalid Woo refund controls and unblock SDK checks
|
|
14
|
+
- feat: deliver local MCP setup and accumulated platform updates
|
|
15
|
+
- feat(invoices): accept full late payments without reopening invoices
|
|
16
|
+
|
|
5
17
|
## [1.1.1] - 2026-10-07
|
|
6
18
|
|
|
7
19
|
- fix(mcp): repository.url/bugs с канон-кейсом Paymos-labs — npm provenance строго мэтчит регистр (E422 на v1.1.0)
|
package/README.md
CHANGED
|
@@ -1,38 +1,74 @@
|
|
|
1
1
|
# @paymos/mcp
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
Code, Cursor, or your own LLM bot — builds and verifies a Paymos merchant integration
|
|
5
|
-
in minutes. It creates sandbox invoices, opens the payment URL, simulates payment,
|
|
6
|
-
watches the status turn `paid`, verifies webhook signatures, then writes the
|
|
7
|
-
production integration around `@paymos/sdk` for you. No docs to read, no skeleton code
|
|
8
|
-
to copy.
|
|
3
|
+
Connect your coding agent to the Paymos sandbox through a local MCP server. The agent can create test invoices, simulate payment scenarios, inspect invoice states, and verify webhook signatures while building your application around a Paymos server SDK.
|
|
9
4
|
|
|
10
|
-
|
|
11
|
-
refuses live and payout keys with a clear error. Live operation arrives with the
|
|
12
|
-
hosted `mcp.paymos.io` (phase 2).
|
|
5
|
+
The server runs over stdio. It exposes six tools and five documentation resources and accepts test key pairs only. Live and payout keys are refused.
|
|
13
6
|
|
|
14
7
|
## Requirements
|
|
15
8
|
|
|
16
|
-
- Node.js
|
|
17
|
-
- A Paymos merchant account with a test key pair
|
|
18
|
-
|
|
9
|
+
- Node.js 20 or newer
|
|
10
|
+
- A Paymos merchant account with a test key pair from Dashboard → Developer → API Keys (`pk_test_…` and `sk_test_…`)
|
|
11
|
+
- An MCP client that can launch a local stdio server
|
|
19
12
|
|
|
20
|
-
##
|
|
13
|
+
## Setup
|
|
21
14
|
|
|
22
|
-
|
|
15
|
+
Run:
|
|
23
16
|
|
|
24
|
-
|
|
17
|
+
```bash
|
|
18
|
+
npx -y @paymos/mcp setup
|
|
19
|
+
```
|
|
25
20
|
|
|
26
|
-
|
|
27
|
-
work; the environment wins on conflict):
|
|
21
|
+
Choose your client and enter your test key pair. Secret input is hidden. You can also supply a webhook secret for signature verification or press Enter to skip it. If the values are already in your environment, setup reads `PAYMOS_API_KEY_ID`, `PAYMOS_API_SECRET`, and optional `PAYMOS_WEBHOOK_SECRET`.
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
You can select the client in the command:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx -y @paymos/mcp setup --client codex
|
|
27
|
+
```
|
|
34
28
|
|
|
35
|
-
|
|
29
|
+
| Client | `--client` value | Default configuration |
|
|
30
|
+
|---|---|---|
|
|
31
|
+
| Codex | `codex` | `$CODEX_HOME/config.toml` or `~/.codex/config.toml` |
|
|
32
|
+
| Claude Code | `claude-code` | `~/.claude.json` |
|
|
33
|
+
| Claude Desktop | `claude-desktop` | Claude's macOS or Windows configuration |
|
|
34
|
+
| Kimi CLI | `kimi` | `$KIMI_CODE_HOME/mcp.json` or `~/.kimi-code/mcp.json` |
|
|
35
|
+
| Cursor | `cursor` | `~/.cursor/mcp.json` |
|
|
36
|
+
| Windsurf | `windsurf` | `~/.codeium/windsurf/mcp_config.json` |
|
|
37
|
+
| OpenCode | `opencode` | `OPENCODE_CONFIG`, or the user configuration under `$XDG_CONFIG_HOME/opencode` or `~/.config/opencode` |
|
|
38
|
+
| VS Code | `vscode` | `.vscode/mcp.json` in the current directory |
|
|
39
|
+
| Another client | `generic` | Explicit `--config PATH` required |
|
|
40
|
+
|
|
41
|
+
For OpenCode, setup uses an existing `opencode.jsonc` before `opencode.json`. To use a different configuration for any client, pass `--config PATH`. Claude Desktop on other operating systems needs an explicit path. Cline, Roo Code, and custom clients can use `--client generic --config PATH` with the MCP configuration path shown by that client.
|
|
42
|
+
|
|
43
|
+
Setup saves credentials separately, by default in `$XDG_CONFIG_HOME/paymos/mcp/credentials.json` or `~/.config/paymos/mcp/credentials.json` when `XDG_CONFIG_HOME` is unset. Use `--credentials-file PATH` to choose another location outside your project. The client entry contains only `PAYMOS_CREDENTIALS_FILE` with that path; it does not contain your keys. Keep the credentials file out of version control.
|
|
44
|
+
|
|
45
|
+
To preview the proposed changes, run:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npx -y @paymos/mcp setup --client codex --dry-run
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Dry-run writes no files and prints no secrets. Repeating setup with the same data does not add a duplicate entry. If existing Paymos settings or credentials differ, setup refuses to overwrite them so you can review the conflict. Other servers, comments, models, and client settings are preserved. An older Paymos entry with inline key environment variables also causes a conflict; setup does not migrate it automatically.
|
|
52
|
+
|
|
53
|
+
Restart or reconnect your MCP client after setup, then look for Paymos in its server list. Try asking the agent to create a sandbox invoice and simulate payment. Use `npx -y @paymos/mcp setup --help` for the full option list. Without an interactive terminal, provide `--client` and the required key environment variables; setup cannot ask for missing values there.
|
|
54
|
+
|
|
55
|
+
Kimi CLI is a client, distinct from the Kimi model. GLM, Kimi, and custom models can use Paymos through an MCP client if both the client and chosen model support tool calling. Setup does not change your model. For example, [Z.ai explains how to run GLM in Claude Code](https://docs.z.ai/devpack/tool/claude); add Paymos using the Claude Code adapter after configuring the model.
|
|
56
|
+
|
|
57
|
+
## Manual configuration
|
|
58
|
+
|
|
59
|
+
Create a credentials file outside the project:
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"apiKeyId": "pk_test_…",
|
|
64
|
+
"apiSecret": "sk_test_…",
|
|
65
|
+
"webhookSecret": "whsec_…"
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
`webhookSecret` is optional. On Unix, run `chmod 600 /absolute/path/credentials.json` after saving, using the actual absolute path. On Windows, keep the file in your account directory and check its existing access permissions. In the examples below, replace `/absolute/path/credentials.json` with the file's absolute path, and preserve your existing client settings.
|
|
70
|
+
|
|
71
|
+
### Claude Code, Claude Desktop, Kimi CLI, Cursor, Windsurf, and generic clients
|
|
36
72
|
|
|
37
73
|
```json
|
|
38
74
|
{
|
|
@@ -41,54 +77,48 @@ work; the environment wins on conflict):
|
|
|
41
77
|
"command": "npx",
|
|
42
78
|
"args": ["-y", "@paymos/mcp"],
|
|
43
79
|
"env": {
|
|
44
|
-
"
|
|
45
|
-
"PAYMOS_API_SECRET": "sk_test_…",
|
|
46
|
-
"PAYMOS_WEBHOOK_SECRET": "whsec_…"
|
|
80
|
+
"PAYMOS_CREDENTIALS_FILE": "/absolute/path/credentials.json"
|
|
47
81
|
}
|
|
48
82
|
}
|
|
49
83
|
}
|
|
50
84
|
}
|
|
51
85
|
```
|
|
52
86
|
|
|
53
|
-
|
|
87
|
+
Use the locations in the setup table. Claude Code also accepts a project `.mcp.json`. Claude Desktop uses `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS and `%APPDATA%\Claude\claude_desktop_config.json` on Windows. Cline and Roo Code show their configuration through MCP Servers → Configure.
|
|
88
|
+
|
|
89
|
+
### Codex
|
|
90
|
+
|
|
91
|
+
Add to `config.toml`:
|
|
54
92
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
93
|
+
```toml
|
|
94
|
+
[mcp_servers.paymos]
|
|
95
|
+
command = "npx"
|
|
96
|
+
args = ["-y", "@paymos/mcp"]
|
|
59
97
|
|
|
60
|
-
|
|
98
|
+
[mcp_servers.paymos.env]
|
|
99
|
+
PAYMOS_CREDENTIALS_FILE = "/absolute/path/credentials.json"
|
|
100
|
+
```
|
|
61
101
|
|
|
62
|
-
|
|
102
|
+
### OpenCode
|
|
63
103
|
|
|
64
104
|
```json
|
|
65
105
|
{
|
|
66
|
-
"
|
|
106
|
+
"mcp": {
|
|
67
107
|
"paymos": {
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
108
|
+
"type": "local",
|
|
109
|
+
"command": ["npx", "-y", "@paymos/mcp"],
|
|
110
|
+
"environment": {
|
|
111
|
+
"PAYMOS_CREDENTIALS_FILE": "/absolute/path/credentials.json"
|
|
112
|
+
},
|
|
113
|
+
"enabled": true
|
|
74
114
|
}
|
|
75
115
|
}
|
|
76
116
|
}
|
|
77
117
|
```
|
|
78
118
|
|
|
79
|
-
###
|
|
80
|
-
|
|
81
|
-
Same `mcpServers` block in `~/.codeium/windsurf/mcp_config.json`.
|
|
82
|
-
|
|
83
|
-
### Cline / Roo Code
|
|
84
|
-
|
|
85
|
-
Same `mcpServers` block in `cline_mcp_settings.json` for Cline and
|
|
86
|
-
`roo_mcp_settings.json` for Roo Code (MCP Servers → Configure in the extension).
|
|
87
|
-
|
|
88
|
-
### VS Code (Copilot)
|
|
119
|
+
### VS Code
|
|
89
120
|
|
|
90
|
-
`.vscode/mcp.json`
|
|
91
|
-
with an explicit transport type:
|
|
121
|
+
Add to `.vscode/mcp.json` or your user MCP configuration:
|
|
92
122
|
|
|
93
123
|
```json
|
|
94
124
|
{
|
|
@@ -98,8 +128,7 @@ with an explicit transport type:
|
|
|
98
128
|
"command": "npx",
|
|
99
129
|
"args": ["-y", "@paymos/mcp"],
|
|
100
130
|
"env": {
|
|
101
|
-
"
|
|
102
|
-
"PAYMOS_API_SECRET": "sk_test_…"
|
|
131
|
+
"PAYMOS_CREDENTIALS_FILE": "/absolute/path/credentials.json"
|
|
103
132
|
}
|
|
104
133
|
}
|
|
105
134
|
}
|
|
@@ -108,7 +137,7 @@ with an explicit transport type:
|
|
|
108
137
|
|
|
109
138
|
### Zed
|
|
110
139
|
|
|
111
|
-
`~/.zed/settings.json
|
|
140
|
+
Zed requires manual configuration; setup has no Zed adapter. On Unix, use `~/.config/zed/settings.json` for global settings or `.zed/settings.json` for project settings. On Windows, open settings in Zed to find the actual `settings.json` file. Add:
|
|
112
141
|
|
|
113
142
|
```json
|
|
114
143
|
{
|
|
@@ -117,83 +146,70 @@ with an explicit transport type:
|
|
|
117
146
|
"command": "npx",
|
|
118
147
|
"args": ["-y", "@paymos/mcp"],
|
|
119
148
|
"env": {
|
|
120
|
-
"
|
|
121
|
-
"PAYMOS_API_SECRET": "sk_test_…"
|
|
149
|
+
"PAYMOS_CREDENTIALS_FILE": "/absolute/path/credentials.json"
|
|
122
150
|
}
|
|
123
151
|
}
|
|
124
152
|
}
|
|
125
153
|
}
|
|
126
154
|
```
|
|
127
155
|
|
|
128
|
-
###
|
|
156
|
+
### Windows
|
|
129
157
|
|
|
130
|
-
|
|
131
|
-
for the Claude Code endpoint setup). Once Claude Code runs on GLM, add the
|
|
132
|
-
`paymos` server with the Claude Code config above — the MCP layer is identical.
|
|
158
|
+
For each manual example, use this launcher on Windows:
|
|
133
159
|
|
|
134
|
-
|
|
160
|
+
```json
|
|
161
|
+
"command": "cmd",
|
|
162
|
+
"args": ["/d", "/c", "npx", "-y", "@paymos/mcp"]
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
OpenCode uses a single array: `"command": ["cmd", "/d", "/c", "npx", "-y", "@paymos/mcp"]`. For Codex TOML, set `command = "cmd"` and use the same argument array. Setup selects the Windows launcher automatically.
|
|
135
166
|
|
|
136
|
-
|
|
137
|
-
remote MCP servers over HTTP. The hosted `mcp.paymos.io` (phase 2) will cover
|
|
138
|
-
ChatGPT and other hosted clients. Developers building on the OpenAI Agents SDK
|
|
139
|
-
can mount this stdio server in their own agent code today.
|
|
167
|
+
### Existing credential options
|
|
140
168
|
|
|
141
|
-
|
|
169
|
+
The server still reads `PAYMOS_API_KEY_ID`, `PAYMOS_API_SECRET`, and optional `PAYMOS_WEBHOOK_SECRET` directly. The `--api-key-id` and `--api-secret` flags also remain available. Environment values take priority over flags, which take priority over fields in the credentials file. Avoid putting secrets in command history or tracked configuration.
|
|
142
170
|
|
|
143
|
-
|
|
144
|
-
env as above.
|
|
171
|
+
## Tools
|
|
145
172
|
|
|
146
|
-
## Tools (frozen public surface)
|
|
147
173
|
|
|
148
|
-
Names and schemas are fixed from 1.0.0 — breaking changes mean a new major version.
|
|
149
174
|
|
|
150
|
-
| Tool |
|
|
175
|
+
| Tool | Purpose |
|
|
151
176
|
|---|---|
|
|
152
|
-
| `create_invoice` |
|
|
153
|
-
| `get_invoice` |
|
|
154
|
-
| `list_invoices` |
|
|
155
|
-
| `cancel_invoice` |
|
|
156
|
-
| `simulate_invoice_payment` |
|
|
157
|
-
| `verify_webhook_signature` |
|
|
177
|
+
| `create_invoice` | Create a sandbox invoice; idempotent per `external_order_id`; returns `payment_url` |
|
|
178
|
+
| `get_invoice` | Fetch the current invoice state |
|
|
179
|
+
| `list_invoices` | Fetch one cursor page of invoices, with filters |
|
|
180
|
+
| `cancel_invoice` | Cancel an unpaid invoice and store the reason |
|
|
181
|
+
| `simulate_invoice_payment` | Simulate `paid`, `paid_late`, `overpaid`, `underpay`, or `cancel` in the sandbox |
|
|
182
|
+
| `verify_webhook_signature` | Verify `X-Webhook-Signature` against the raw webhook body locally |
|
|
158
183
|
|
|
159
|
-
|
|
160
|
-
refusals use `paymos/sandbox-only`, `paymos/missing-credentials` and
|
|
161
|
-
`paymos/invalid-credentials`.
|
|
184
|
+
`paid_late` is a simulation scenario, not an invoice status. See the [sandbox documentation](https://paymos.io/docs/testing) for its behavior.
|
|
162
185
|
|
|
163
|
-
|
|
186
|
+
Tool errors use `{ "code": "paymos/<api_error_code>", "message": "…" }`. Sandbox and credential refusals use `paymos/sandbox-only`, `paymos/missing-credentials`, and `paymos/invalid-credentials`.
|
|
164
187
|
|
|
165
|
-
|
|
166
|
-
session: `paymos://docs/quick-start`, `paymos://docs/hosted-checkout`,
|
|
167
|
-
`paymos://docs/webhooks`, `paymos://docs/testing-sandbox`,
|
|
168
|
-
`paymos://docs/server-sdks`.
|
|
188
|
+
## Resources
|
|
169
189
|
|
|
170
|
-
|
|
190
|
+
Five documentation pages are available inside the MCP session:
|
|
171
191
|
|
|
172
|
-
-
|
|
173
|
-
|
|
174
|
-
-
|
|
175
|
-
-
|
|
176
|
-
|
|
192
|
+
- `paymos://docs/quick-start`
|
|
193
|
+
- `paymos://docs/hosted-checkout`
|
|
194
|
+
- `paymos://docs/webhooks`
|
|
195
|
+
- `paymos://docs/testing-sandbox`
|
|
196
|
+
- `paymos://docs/server-sdks`
|
|
177
197
|
|
|
178
|
-
##
|
|
198
|
+
## Sandbox and credentials
|
|
179
199
|
|
|
180
|
-
|
|
181
|
-
has written and verified your integration, your own code goes live with your live keys
|
|
182
|
-
— the MCP server stays out of production paths.
|
|
200
|
+
The server opens no network listener and calls the Merchant API through `@paymos/sdk`. Setup output does not print secret values. Check your chosen client and model provider's logging settings separately. Setup stores keys in a separate local file; on Unix, new credential files use mode `0600` in a private directory. On Windows, access follows the account directory's permissions; the file is not encrypted by setup.
|
|
183
201
|
|
|
184
|
-
|
|
185
|
-
Developers → API keys.
|
|
202
|
+
Live (`pk_live_`/`sk_live_`) and payout (`rk_…`) keys are rejected during setup, at server startup, and on tool calls. After checking your integration in the sandbox, run your own application with its live keys. This local MCP server stays outside production payment paths.
|
|
186
203
|
|
|
187
|
-
|
|
188
|
-
entities with scoped keys, and live operation.
|
|
204
|
+
Hosted MCP is deferred and is not available as a connection method.
|
|
189
205
|
|
|
190
206
|
## Development
|
|
191
207
|
|
|
192
208
|
```bash
|
|
193
|
-
npm install
|
|
194
|
-
npm run build:resources
|
|
195
|
-
npm test
|
|
196
|
-
npm run build
|
|
209
|
+
npm install # @paymos/sdk resolves from ../typescript-sdk
|
|
210
|
+
npm run build:resources # regenerate documentation resources
|
|
211
|
+
npm test # package tests
|
|
212
|
+
npm run build # bundle to dist/
|
|
197
213
|
```
|
|
198
214
|
|
|
199
215
|
License: MIT — see [LICENSE](LICENSE).
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,90 @@ import { realpathSync } from "fs";
|
|
|
5
5
|
import { pathToFileURL } from "url";
|
|
6
6
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
7
7
|
|
|
8
|
+
// src/credential-file.ts
|
|
9
|
+
import { constants, closeSync, fstatSync, lstatSync, openSync, readFileSync } from "fs";
|
|
10
|
+
|
|
11
|
+
// src/setup-copy.ts
|
|
12
|
+
var SETUP_COPY = {
|
|
13
|
+
title: "Connect Paymos to your MCP client",
|
|
14
|
+
chooseClient: "Choose your MCP client",
|
|
15
|
+
apiKey: "Test API key ID (pk_test_\u2026)",
|
|
16
|
+
apiSecret: "Test API secret (sk_test_\u2026; input hidden)",
|
|
17
|
+
webhookSecret: "Webhook secret (optional; press Enter to skip; input hidden)",
|
|
18
|
+
help: `Usage: npx -y @paymos/mcp setup [options]
|
|
19
|
+
|
|
20
|
+
Connect a local MCP client using a Paymos test key pair.
|
|
21
|
+
|
|
22
|
+
Options:
|
|
23
|
+
--client NAME codex, claude-code, claude-desktop, kimi, cursor,
|
|
24
|
+
windsurf, opencode, vscode, or generic
|
|
25
|
+
--config PATH Client configuration file (required for generic)
|
|
26
|
+
--credentials-file PATH Separate file for your test credentials
|
|
27
|
+
--dry-run Preview file paths and changes without writing
|
|
28
|
+
--help, -h Show this help
|
|
29
|
+
|
|
30
|
+
Without --client, setup asks you to choose a client in an interactive terminal.
|
|
31
|
+
Enter your test keys when prompted; secret input is hidden. Setup can also read
|
|
32
|
+
PAYMOS_API_KEY_ID, PAYMOS_API_SECRET, and optional PAYMOS_WEBHOOK_SECRET.
|
|
33
|
+
Live and payout keys are refused.
|
|
34
|
+
|
|
35
|
+
Credentials default to $XDG_CONFIG_HOME/paymos/mcp/credentials.json, or
|
|
36
|
+
~/.config/paymos/mcp/credentials.json when XDG_CONFIG_HOME is unset.
|
|
37
|
+
The client config contains the credentials file path, not the keys.
|
|
38
|
+
|
|
39
|
+
Examples:
|
|
40
|
+
npx -y @paymos/mcp setup
|
|
41
|
+
npx -y @paymos/mcp setup --client codex
|
|
42
|
+
npx -y @paymos/mcp setup --client kimi --dry-run
|
|
43
|
+
npx -y @paymos/mcp setup --client generic --config /path/to/mcp.json
|
|
44
|
+
|
|
45
|
+
Restart or reconnect your MCP client after setup.`,
|
|
46
|
+
configured: (path) => `Paymos is configured in ${path}.`,
|
|
47
|
+
preview: (path) => `Preview for ${path}. No files were changed.`,
|
|
48
|
+
unchanged: (path) => `Paymos already matches this setup in ${path}. No changes needed.`,
|
|
49
|
+
restart: "Restart or reconnect your MCP client to load Paymos.",
|
|
50
|
+
errors: {
|
|
51
|
+
arguments: "Check the setup options: an option is unknown, repeated, or missing its value. Run setup --help for examples.",
|
|
52
|
+
client: "Choose a supported client with --client. Run setup --help for the client names.",
|
|
53
|
+
configRequired: "This client needs a configuration path. Add --config with the path to its MCP configuration file.",
|
|
54
|
+
nonInteractive: "Setup needs an interactive terminal to ask for missing values. Set --client, PAYMOS_API_KEY_ID, and PAYMOS_API_SECRET, then retry.",
|
|
55
|
+
credentials: "Use a complete test key pair: pk_test_\u2026 and sk_test_\u2026. Live and payout keys cannot be used with this server.",
|
|
56
|
+
credentialFile: "The credentials file could not be read or is not valid. Check its path and JSON fields: apiKeyId, apiSecret, and optional webhookSecret.",
|
|
57
|
+
configFile: "The client configuration could not be read or is not valid for this client. Check the file before retrying.",
|
|
58
|
+
conflict: "The existing Paymos entry or credentials file differs from this setup. Review it or choose another path; it has not been overwritten.",
|
|
59
|
+
changed: "A target file changed during setup. Review the latest file and run setup again.",
|
|
60
|
+
symlink: "Setup cannot write through a symbolic link at a target path. Choose a regular file path.",
|
|
61
|
+
cancelled: "Setup cancelled before configuration was saved.",
|
|
62
|
+
write: "Setup could not save the files. Check the target paths and write permissions, then retry."
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/credential-file.ts
|
|
67
|
+
function readCredentialFile(path) {
|
|
68
|
+
let fd;
|
|
69
|
+
try {
|
|
70
|
+
const link = lstatSync(path);
|
|
71
|
+
if (!link.isFile() || link.isSymbolicLink()) throw new Error();
|
|
72
|
+
fd = openSync(path, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
73
|
+
const stat = fstatSync(fd);
|
|
74
|
+
if (!stat.isFile() || stat.size > 16384 || stat.ino !== link.ino) throw new Error();
|
|
75
|
+
if (process.platform !== "win32" && ((stat.mode & 63) !== 0 || process.getuid !== void 0 && stat.uid !== process.getuid())) throw new Error();
|
|
76
|
+
const value = JSON.parse(readFileSync(fd, "utf8"));
|
|
77
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new Error();
|
|
78
|
+
const record = value;
|
|
79
|
+
if (typeof record.apiKeyId !== "string" || typeof record.apiSecret !== "string" || record.webhookSecret !== void 0 && typeof record.webhookSecret !== "string") throw new Error();
|
|
80
|
+
return {
|
|
81
|
+
apiKeyId: record.apiKeyId.trim(),
|
|
82
|
+
apiSecret: record.apiSecret.trim(),
|
|
83
|
+
...typeof record.webhookSecret === "string" && record.webhookSecret.trim() !== "" ? { webhookSecret: record.webhookSecret.trim() } : {}
|
|
84
|
+
};
|
|
85
|
+
} catch {
|
|
86
|
+
throw new Error(SETUP_COPY.errors.credentialFile);
|
|
87
|
+
} finally {
|
|
88
|
+
if (fd !== void 0) closeSync(fd);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
8
92
|
// src/config.ts
|
|
9
93
|
var FLAG_NAMES = /* @__PURE__ */ new Map([
|
|
10
94
|
["--api-key-id", "apiKeyId"],
|
|
@@ -27,9 +111,10 @@ function parseFlags(argv) {
|
|
|
27
111
|
return flags;
|
|
28
112
|
}
|
|
29
113
|
function loadCredentials(env, flags) {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
114
|
+
const file = env.PAYMOS_CREDENTIALS_FILE === void 0 ? void 0 : readCredentialFile(env.PAYMOS_CREDENTIALS_FILE);
|
|
115
|
+
const apiKeyId = (env.PAYMOS_API_KEY_ID ?? flags.apiKeyId ?? file?.apiKeyId ?? "").trim();
|
|
116
|
+
const apiSecret = (env.PAYMOS_API_SECRET ?? flags.apiSecret ?? file?.apiSecret ?? "").trim();
|
|
117
|
+
const webhookSecret = (env.PAYMOS_WEBHOOK_SECRET ?? file?.webhookSecret ?? "").trim();
|
|
33
118
|
return webhookSecret === "" ? { apiKeyId, apiSecret } : { apiKeyId, apiSecret, webhookSecret };
|
|
34
119
|
}
|
|
35
120
|
|
|
@@ -74,13 +159,13 @@ var ToolError = class extends Error {
|
|
|
74
159
|
this.code = code;
|
|
75
160
|
}
|
|
76
161
|
};
|
|
77
|
-
function toolErrorFrom(
|
|
78
|
-
if (
|
|
79
|
-
if (
|
|
80
|
-
const code =
|
|
81
|
-
return new ToolError(`paymos/${code}`,
|
|
162
|
+
function toolErrorFrom(error2) {
|
|
163
|
+
if (error2 instanceof ToolError) return error2;
|
|
164
|
+
if (error2 instanceof ApiError) {
|
|
165
|
+
const code = error2.code === "" ? "api_error" : error2.code;
|
|
166
|
+
return new ToolError(`paymos/${code}`, error2.message);
|
|
82
167
|
}
|
|
83
|
-
const message =
|
|
168
|
+
const message = error2 instanceof Error ? error2.message : String(error2);
|
|
84
169
|
return new ToolError("paymos/sdk_error", message);
|
|
85
170
|
}
|
|
86
171
|
|
|
@@ -148,8 +233,8 @@ function textJson(value) {
|
|
|
148
233
|
content: [{ type: "text", text: JSON.stringify(value, null, 2) }]
|
|
149
234
|
};
|
|
150
235
|
}
|
|
151
|
-
function failure(
|
|
152
|
-
const toolError = toolErrorFrom(
|
|
236
|
+
function failure(error2) {
|
|
237
|
+
const toolError = toolErrorFrom(error2);
|
|
153
238
|
return {
|
|
154
239
|
isError: true,
|
|
155
240
|
content: [{ type: "text", text: JSON.stringify({ code: toolError.code, message: toolError.message }, null, 2) }]
|
|
@@ -158,8 +243,8 @@ function failure(error) {
|
|
|
158
243
|
async function guarded(run) {
|
|
159
244
|
try {
|
|
160
245
|
return await run();
|
|
161
|
-
} catch (
|
|
162
|
-
return failure(
|
|
246
|
+
} catch (error2) {
|
|
247
|
+
return failure(error2);
|
|
163
248
|
}
|
|
164
249
|
}
|
|
165
250
|
function registerTools(server, gateway) {
|
|
@@ -267,10 +352,10 @@ function registerTools(server, gateway) {
|
|
|
267
352
|
"simulate_invoice_payment",
|
|
268
353
|
{
|
|
269
354
|
title: "Simulate a sandbox payment",
|
|
270
|
-
description: "Sandbox only: drive a test invoice through a payment outcome without touching a blockchain. The server derives the amounts \u2014 never compute money client-side. stage=paid marks it fully paid; overpaid pays more than expected; underpay pays less (invoice lands in underpaid waiting for a top-up); cancel voids it. " + INVOICE_RESULT_HINT,
|
|
355
|
+
description: "Sandbox only: drive a test invoice through a payment outcome without touching a blockchain. The server derives the amounts \u2014 never compute money client-side. stage=paid marks it fully paid; overpaid pays more than expected; underpay pays less (invoice lands in underpaid waiting for a top-up); cancel voids it; paid_late pays the full amount after the deadline \u2014 the invoice keeps its terminal decision and gains the late-payment mark. " + INVOICE_RESULT_HINT,
|
|
271
356
|
inputSchema: {
|
|
272
357
|
invoice_id: z.string().min(1).describe("Test invoice identifier (is_test=true)"),
|
|
273
|
-
stage: z.enum(["paid", "overpaid", "underpay", "cancel"]).describe("Outcome to simulate: paid | overpaid | underpay | cancel")
|
|
358
|
+
stage: z.enum(["paid", "overpaid", "underpay", "cancel", "paid_late"]).describe("Outcome to simulate: paid | overpaid | underpay | cancel | paid_late")
|
|
274
359
|
}
|
|
275
360
|
},
|
|
276
361
|
async ({ invoice_id, stage }) => guarded(async () => {
|
|
@@ -302,8 +387,8 @@ function registerTools(server, gateway) {
|
|
|
302
387
|
try {
|
|
303
388
|
verifier.assertValid(signature_header, payload);
|
|
304
389
|
return textJson({ valid: true });
|
|
305
|
-
} catch (
|
|
306
|
-
if (
|
|
390
|
+
} catch (error2) {
|
|
391
|
+
if (error2 instanceof TimestampSkewError) return textJson({ valid: false, reason: "expired" });
|
|
307
392
|
return textJson({ valid: false, reason: "bad_signature" });
|
|
308
393
|
}
|
|
309
394
|
}
|
|
@@ -960,7 +1045,7 @@ function registerResources(server) {
|
|
|
960
1045
|
}
|
|
961
1046
|
|
|
962
1047
|
// src/version.ts
|
|
963
|
-
var MCP_VERSION = "1.
|
|
1048
|
+
var MCP_VERSION = "1.3.0";
|
|
964
1049
|
|
|
965
1050
|
// src/server.ts
|
|
966
1051
|
function buildServer(gateway) {
|
|
@@ -970,8 +1055,332 @@ function buildServer(gateway) {
|
|
|
970
1055
|
return server;
|
|
971
1056
|
}
|
|
972
1057
|
|
|
1058
|
+
// src/setup.ts
|
|
1059
|
+
import {
|
|
1060
|
+
chmodSync,
|
|
1061
|
+
closeSync as closeSync2,
|
|
1062
|
+
constants as constants2,
|
|
1063
|
+
existsSync,
|
|
1064
|
+
fstatSync as fstatSync2,
|
|
1065
|
+
linkSync,
|
|
1066
|
+
lstatSync as lstatSync2,
|
|
1067
|
+
mkdirSync,
|
|
1068
|
+
openSync as openSync2,
|
|
1069
|
+
readFileSync as readFileSync2,
|
|
1070
|
+
renameSync,
|
|
1071
|
+
unlinkSync,
|
|
1072
|
+
writeFileSync
|
|
1073
|
+
} from "fs";
|
|
1074
|
+
import { randomUUID } from "crypto";
|
|
1075
|
+
import { homedir } from "os";
|
|
1076
|
+
import { dirname, isAbsolute, join, resolve } from "path";
|
|
1077
|
+
import { createInterface } from "readline";
|
|
1078
|
+
import { Writable } from "stream";
|
|
1079
|
+
import { isDeepStrictEqual } from "util";
|
|
1080
|
+
import { applyEdits, modify, parse as parseJson, parseTree } from "jsonc-parser";
|
|
1081
|
+
import { parse as parseToml, stringify as stringifyToml } from "smol-toml";
|
|
1082
|
+
var SETUP_CLIENTS = [
|
|
1083
|
+
"codex",
|
|
1084
|
+
"claude-code",
|
|
1085
|
+
"claude-desktop",
|
|
1086
|
+
"kimi",
|
|
1087
|
+
"cursor",
|
|
1088
|
+
"windsurf",
|
|
1089
|
+
"opencode",
|
|
1090
|
+
"vscode",
|
|
1091
|
+
"generic"
|
|
1092
|
+
];
|
|
1093
|
+
function error(kind) {
|
|
1094
|
+
throw new Error(SETUP_COPY.errors[kind]);
|
|
1095
|
+
}
|
|
1096
|
+
function options(argv) {
|
|
1097
|
+
const result = { dryRun: false, help: false };
|
|
1098
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1099
|
+
const flags = /* @__PURE__ */ new Map([
|
|
1100
|
+
["--client", "client"],
|
|
1101
|
+
["--config", "config"],
|
|
1102
|
+
["--credentials-file", "credentialsFile"]
|
|
1103
|
+
]);
|
|
1104
|
+
for (let i = 0; i < argv.length; i++) {
|
|
1105
|
+
const arg = argv[i];
|
|
1106
|
+
const split = arg.indexOf("=");
|
|
1107
|
+
const flag = split < 0 ? arg : arg.slice(0, split);
|
|
1108
|
+
const normalized = flag === "-h" ? "--help" : flag;
|
|
1109
|
+
if (seen.has(normalized)) error("arguments");
|
|
1110
|
+
seen.add(normalized);
|
|
1111
|
+
if (normalized === "--help" || normalized === "--dry-run") {
|
|
1112
|
+
if (split >= 0) error("arguments");
|
|
1113
|
+
if (normalized === "--help") result.help = true;
|
|
1114
|
+
else result.dryRun = true;
|
|
1115
|
+
continue;
|
|
1116
|
+
}
|
|
1117
|
+
const field = flags.get(flag);
|
|
1118
|
+
if (!field) error("arguments");
|
|
1119
|
+
const value = split < 0 ? argv[++i] : arg.slice(split + 1);
|
|
1120
|
+
if (value === void 0 || value.trim() === "" || value.startsWith("--")) error("arguments");
|
|
1121
|
+
result[field] = value;
|
|
1122
|
+
}
|
|
1123
|
+
return result;
|
|
1124
|
+
}
|
|
1125
|
+
function object(value) {
|
|
1126
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
1127
|
+
}
|
|
1128
|
+
function equalData(left, right) {
|
|
1129
|
+
if (isDeepStrictEqual(left, right)) return true;
|
|
1130
|
+
if (!object(left) || !object(right)) return false;
|
|
1131
|
+
const plain = (value) => Object.getPrototypeOf(value) === null || Object.getPrototypeOf(value) === Object.prototype;
|
|
1132
|
+
if (!plain(left) || !plain(right)) return false;
|
|
1133
|
+
const keys = Object.keys(left);
|
|
1134
|
+
return keys.length === Object.keys(right).length && keys.every((key) => Object.hasOwn(right, key) && equalData(left[key], right[key]));
|
|
1135
|
+
}
|
|
1136
|
+
function absolute(path, context) {
|
|
1137
|
+
if (path === "~") return context.home;
|
|
1138
|
+
if (path.startsWith("~/") || path.startsWith("~\\")) return resolve(context.home, path.slice(2));
|
|
1139
|
+
return resolve(context.cwd, path);
|
|
1140
|
+
}
|
|
1141
|
+
function defaultConfigPath(client, env, context) {
|
|
1142
|
+
const configHome = env.XDG_CONFIG_HOME || join(context.home, ".config");
|
|
1143
|
+
switch (client) {
|
|
1144
|
+
case "codex":
|
|
1145
|
+
return join(env.CODEX_HOME || join(context.home, ".codex"), "config.toml");
|
|
1146
|
+
case "claude-code":
|
|
1147
|
+
return join(context.home, ".claude.json");
|
|
1148
|
+
case "kimi":
|
|
1149
|
+
return join(env.KIMI_CODE_HOME || join(context.home, ".kimi-code"), "mcp.json");
|
|
1150
|
+
case "cursor":
|
|
1151
|
+
return join(context.home, ".cursor", "mcp.json");
|
|
1152
|
+
case "windsurf":
|
|
1153
|
+
return join(context.home, ".codeium", "windsurf", "mcp_config.json");
|
|
1154
|
+
case "vscode":
|
|
1155
|
+
return join(context.cwd, ".vscode", "mcp.json");
|
|
1156
|
+
case "opencode": {
|
|
1157
|
+
if (env.OPENCODE_CONFIG) return env.OPENCODE_CONFIG;
|
|
1158
|
+
const jsonc = join(configHome, "opencode", "opencode.jsonc");
|
|
1159
|
+
return existsSync(jsonc) ? jsonc : join(configHome, "opencode", "opencode.json");
|
|
1160
|
+
}
|
|
1161
|
+
case "claude-desktop":
|
|
1162
|
+
if (context.platform === "win32" && env.APPDATA)
|
|
1163
|
+
return join(env.APPDATA, "Claude", "claude_desktop_config.json");
|
|
1164
|
+
if (context.platform === "darwin")
|
|
1165
|
+
return join(context.home, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
1166
|
+
return error("configRequired");
|
|
1167
|
+
case "generic":
|
|
1168
|
+
return error("configRequired");
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1171
|
+
function snapshot(path) {
|
|
1172
|
+
let fd;
|
|
1173
|
+
try {
|
|
1174
|
+
const stat = lstatSync2(path);
|
|
1175
|
+
if (stat.isSymbolicLink()) error("symlink");
|
|
1176
|
+
if (!stat.isFile() || stat.size > 4194304) error("configFile");
|
|
1177
|
+
fd = openSync2(path, constants2.O_RDONLY | (constants2.O_NOFOLLOW ?? 0));
|
|
1178
|
+
if (fstatSync2(fd).ino !== stat.ino) error("changed");
|
|
1179
|
+
return { path, content: readFileSync2(fd, "utf8") };
|
|
1180
|
+
} catch (cause) {
|
|
1181
|
+
if (cause.code === "ENOENT") return { path, content: null };
|
|
1182
|
+
if (cause instanceof Error && Object.values(SETUP_COPY.errors).includes(cause.message)) throw cause;
|
|
1183
|
+
return error("configFile");
|
|
1184
|
+
} finally {
|
|
1185
|
+
if (fd !== void 0) closeSync2(fd);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
function assertUnchanged(before) {
|
|
1189
|
+
if (snapshot(before.path).content !== before.content) error("changed");
|
|
1190
|
+
}
|
|
1191
|
+
function assertUniqueKeys(node) {
|
|
1192
|
+
if (node.type === "object") {
|
|
1193
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1194
|
+
for (const property of node.children ?? []) {
|
|
1195
|
+
const key = property.children?.[0]?.value;
|
|
1196
|
+
if (keys.has(key)) error("configFile");
|
|
1197
|
+
keys.add(key);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
for (const child of node.children ?? []) assertUniqueKeys(child);
|
|
1201
|
+
}
|
|
1202
|
+
function jsonConfig(text) {
|
|
1203
|
+
const errors = [];
|
|
1204
|
+
const value = parseJson(text, errors, { allowTrailingComma: true, allowEmptyContent: false });
|
|
1205
|
+
const tree = parseTree(text, [], { allowTrailingComma: true });
|
|
1206
|
+
if (errors.length !== 0 || !object(value) || !tree) error("configFile");
|
|
1207
|
+
assertUniqueKeys(tree);
|
|
1208
|
+
return value;
|
|
1209
|
+
}
|
|
1210
|
+
function planClientConfig(client, original, credentialsPath, platform) {
|
|
1211
|
+
const command = platform === "win32" ? "cmd" : "npx";
|
|
1212
|
+
const args = platform === "win32" ? ["/d", "/c", "npx", "-y", "@paymos/mcp"] : ["-y", "@paymos/mcp"];
|
|
1213
|
+
const env = { PAYMOS_CREDENTIALS_FILE: credentialsPath };
|
|
1214
|
+
const entry = client === "opencode" ? { type: "local", command: [command, ...args], environment: env, enabled: true } : { ...client === "vscode" ? { type: "stdio" } : {}, command, args, env };
|
|
1215
|
+
const text = original ?? "{}\n";
|
|
1216
|
+
if (client === "codex") {
|
|
1217
|
+
let root2;
|
|
1218
|
+
try {
|
|
1219
|
+
root2 = parseToml(original ?? "");
|
|
1220
|
+
} catch {
|
|
1221
|
+
return error("configFile");
|
|
1222
|
+
}
|
|
1223
|
+
const servers2 = root2.mcp_servers;
|
|
1224
|
+
if (servers2 !== void 0 && !object(servers2)) error("configFile");
|
|
1225
|
+
const existing2 = servers2?.paymos;
|
|
1226
|
+
if (existing2 !== void 0) {
|
|
1227
|
+
if (!equalData(existing2, entry)) error("conflict");
|
|
1228
|
+
return original;
|
|
1229
|
+
}
|
|
1230
|
+
const eol = text.includes("\r\n") ? "\r\n" : "\n";
|
|
1231
|
+
const block = stringifyToml({ mcp_servers: { paymos: entry } }).replace(/\r?\n/g, eol);
|
|
1232
|
+
const next2 = (original ?? "") + eol + block;
|
|
1233
|
+
try {
|
|
1234
|
+
const expected2 = { ...root2, mcp_servers: { ...servers2, paymos: entry } };
|
|
1235
|
+
if (!equalData(parseToml(next2), expected2)) error("configFile");
|
|
1236
|
+
} catch {
|
|
1237
|
+
return error("configFile");
|
|
1238
|
+
}
|
|
1239
|
+
return next2;
|
|
1240
|
+
}
|
|
1241
|
+
const root = jsonConfig(text);
|
|
1242
|
+
const group = client === "opencode" ? "mcp" : client === "vscode" ? "servers" : "mcpServers";
|
|
1243
|
+
const servers = root[group];
|
|
1244
|
+
if (servers !== void 0 && !object(servers)) error("configFile");
|
|
1245
|
+
const existing = servers?.paymos;
|
|
1246
|
+
if (existing !== void 0) {
|
|
1247
|
+
if (!isDeepStrictEqual(existing, entry)) error("conflict");
|
|
1248
|
+
return text;
|
|
1249
|
+
}
|
|
1250
|
+
const next = applyEdits(text, modify(text, [group, "paymos"], entry, {
|
|
1251
|
+
formattingOptions: { insertSpaces: true, tabSize: 2, eol: text.includes("\r\n") ? "\r\n" : "\n" }
|
|
1252
|
+
}));
|
|
1253
|
+
const expected = { ...root, [group]: { ...servers, paymos: entry } };
|
|
1254
|
+
if (!isDeepStrictEqual(jsonConfig(next), expected)) error("configFile");
|
|
1255
|
+
return next;
|
|
1256
|
+
}
|
|
1257
|
+
function writeConfig(before, content) {
|
|
1258
|
+
mkdirSync(dirname(before.path), { recursive: true, mode: 448 });
|
|
1259
|
+
const temp = join(dirname(before.path), `.paymos-${randomUUID()}.tmp`);
|
|
1260
|
+
let created = false;
|
|
1261
|
+
try {
|
|
1262
|
+
writeFileSync(temp, content, { encoding: "utf8", mode: 384, flag: "wx" });
|
|
1263
|
+
created = true;
|
|
1264
|
+
if (process.platform !== "win32") chmodSync(temp, 384);
|
|
1265
|
+
const identity = lstatSync2(temp);
|
|
1266
|
+
assertUnchanged(before);
|
|
1267
|
+
if (before.content === null) linkSync(temp, before.path);
|
|
1268
|
+
else renameSync(temp, before.path);
|
|
1269
|
+
return { ino: identity.ino, dev: identity.dev };
|
|
1270
|
+
} finally {
|
|
1271
|
+
if (created && existsSync(temp)) unlinkSync(temp);
|
|
1272
|
+
}
|
|
1273
|
+
}
|
|
1274
|
+
async function ask(io, label, secret = false) {
|
|
1275
|
+
if (!io.interactive) error("nonInteractive");
|
|
1276
|
+
return (await io.ask(label, secret)).trim();
|
|
1277
|
+
}
|
|
1278
|
+
function terminalIO() {
|
|
1279
|
+
return {
|
|
1280
|
+
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
1281
|
+
log: (message) => console.log(message),
|
|
1282
|
+
ask: (label, secret) => new Promise((accept, reject) => {
|
|
1283
|
+
let muted = false;
|
|
1284
|
+
const output = new Writable({ write(chunk, _encoding, done) {
|
|
1285
|
+
if (!muted) process.stdout.write(chunk);
|
|
1286
|
+
done();
|
|
1287
|
+
} });
|
|
1288
|
+
const reader = createInterface({ input: process.stdin, output, terminal: true });
|
|
1289
|
+
let settled = false;
|
|
1290
|
+
const cancel = () => {
|
|
1291
|
+
if (settled) return;
|
|
1292
|
+
settled = true;
|
|
1293
|
+
muted = false;
|
|
1294
|
+
process.stdout.write("\n");
|
|
1295
|
+
reader.close();
|
|
1296
|
+
reject(new Error(SETUP_COPY.errors.cancelled));
|
|
1297
|
+
};
|
|
1298
|
+
reader.once("SIGINT", cancel);
|
|
1299
|
+
reader.once("close", () => {
|
|
1300
|
+
if (!settled) cancel();
|
|
1301
|
+
});
|
|
1302
|
+
process.stdout.write(`${label}: `);
|
|
1303
|
+
muted = secret;
|
|
1304
|
+
reader.question("", (answer) => {
|
|
1305
|
+
settled = true;
|
|
1306
|
+
muted = false;
|
|
1307
|
+
if (secret) process.stdout.write("\n");
|
|
1308
|
+
reader.close();
|
|
1309
|
+
accept(answer);
|
|
1310
|
+
});
|
|
1311
|
+
})
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
async function runSetup(argv, env = process.env, io = terminalIO(), context = { home: homedir(), cwd: process.cwd(), platform: process.platform }) {
|
|
1315
|
+
const flags = options(argv);
|
|
1316
|
+
if (flags.help) {
|
|
1317
|
+
io.log(SETUP_COPY.help);
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
io.log(SETUP_COPY.title);
|
|
1321
|
+
const requested = flags.client ?? await ask(io, `${SETUP_COPY.chooseClient} (${SETUP_CLIENTS.join(", ")})`);
|
|
1322
|
+
if (!SETUP_CLIENTS.includes(requested)) error("client");
|
|
1323
|
+
const client = requested;
|
|
1324
|
+
const configPath = absolute(flags.config ?? defaultConfigPath(client, env, context), context);
|
|
1325
|
+
const credentialsPath = absolute(flags.credentialsFile ?? env.PAYMOS_CREDENTIALS_FILE ?? join(env.XDG_CONFIG_HOME || join(context.home, ".config"), "paymos", "mcp", "credentials.json"), context);
|
|
1326
|
+
const samePath = context.platform === "win32" ? configPath.toLowerCase() === credentialsPath.toLowerCase() : configPath === credentialsPath;
|
|
1327
|
+
if (samePath || !isAbsolute(configPath) || !isAbsolute(credentialsPath)) error("conflict");
|
|
1328
|
+
const before = snapshot(configPath);
|
|
1329
|
+
const beforeKeys = snapshot(credentialsPath);
|
|
1330
|
+
const stored = beforeKeys.content === null ? void 0 : readCredentialFile(credentialsPath);
|
|
1331
|
+
const apiKeyId = (env.PAYMOS_API_KEY_ID ?? stored?.apiKeyId ?? await ask(io, SETUP_COPY.apiKey)).trim();
|
|
1332
|
+
const apiSecret = (env.PAYMOS_API_SECRET ?? stored?.apiSecret ?? await ask(io, SETUP_COPY.apiSecret, true)).trim();
|
|
1333
|
+
const webhookSecret = (env.PAYMOS_WEBHOOK_SECRET ?? stored?.webhookSecret ?? (io.interactive ? await ask(io, SETUP_COPY.webhookSecret, true) : "")).trim();
|
|
1334
|
+
const credentials = {
|
|
1335
|
+
apiKeyId,
|
|
1336
|
+
apiSecret,
|
|
1337
|
+
...webhookSecret === "" ? {} : { webhookSecret }
|
|
1338
|
+
};
|
|
1339
|
+
if (!checkCredentials(credentials).ok) error("credentials");
|
|
1340
|
+
if (stored !== void 0 && !isDeepStrictEqual(stored, credentials)) error("conflict");
|
|
1341
|
+
const next = planClientConfig(client, before.content, credentialsPath, context.platform);
|
|
1342
|
+
if (flags.dryRun) {
|
|
1343
|
+
io.log(SETUP_COPY.preview(configPath));
|
|
1344
|
+
io.log(SETUP_COPY.preview(credentialsPath));
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
if (before.content === next && stored !== void 0) {
|
|
1348
|
+
io.log(SETUP_COPY.unchanged(configPath));
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
let createdKeys;
|
|
1352
|
+
try {
|
|
1353
|
+
assertUnchanged(before);
|
|
1354
|
+
assertUnchanged(beforeKeys);
|
|
1355
|
+
if (stored === void 0) {
|
|
1356
|
+
createdKeys = writeConfig(beforeKeys, JSON.stringify(credentials, null, 2) + "\n");
|
|
1357
|
+
}
|
|
1358
|
+
if (before.content !== next) writeConfig(before, next);
|
|
1359
|
+
} catch (cause) {
|
|
1360
|
+
if (createdKeys !== void 0) {
|
|
1361
|
+
try {
|
|
1362
|
+
const stat = lstatSync2(credentialsPath);
|
|
1363
|
+
if (!stat.isSymbolicLink() && stat.ino === createdKeys.ino && stat.dev === createdKeys.dev && isDeepStrictEqual(readCredentialFile(credentialsPath), credentials)) unlinkSync(credentialsPath);
|
|
1364
|
+
} catch {
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
if (cause instanceof Error && Object.values(SETUP_COPY.errors).includes(cause.message)) throw cause;
|
|
1368
|
+
error("write");
|
|
1369
|
+
}
|
|
1370
|
+
io.log(SETUP_COPY.configured(configPath));
|
|
1371
|
+
io.log(SETUP_COPY.restart);
|
|
1372
|
+
}
|
|
1373
|
+
|
|
973
1374
|
// src/index.ts
|
|
974
1375
|
async function main(env = process.env, argv = process.argv.slice(2)) {
|
|
1376
|
+
if (argv[0] === "setup") {
|
|
1377
|
+
await runSetup(argv.slice(1), env);
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
if (argv[0] === "--help" || argv[0] === "-h") {
|
|
1381
|
+
console.log(SETUP_COPY.help);
|
|
1382
|
+
return;
|
|
1383
|
+
}
|
|
975
1384
|
const credentials = loadCredentials(env, parseFlags(argv));
|
|
976
1385
|
const gateway = new PaymosGateway(credentials);
|
|
977
1386
|
console.error(startupLine(gateway.check(), credentials.apiKeyId));
|
|
@@ -980,8 +1389,8 @@ async function main(env = process.env, argv = process.argv.slice(2)) {
|
|
|
980
1389
|
}
|
|
981
1390
|
var isDirectRun = process.argv[1] !== void 0 && import.meta.url === pathToFileURL(realpathSync(process.argv[1])).href;
|
|
982
1391
|
if (isDirectRun) {
|
|
983
|
-
main().catch((
|
|
984
|
-
console.error(`[paymos-mcp] fatal: ${
|
|
1392
|
+
main().catch((error2) => {
|
|
1393
|
+
console.error(`[paymos-mcp] fatal: ${error2 instanceof Error ? error2.message : String(error2)}`);
|
|
985
1394
|
process.exit(1);
|
|
986
1395
|
});
|
|
987
1396
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paymos/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Official Paymos MCP server: a local stdio server that lets coding agents (Claude Code, Cursor, custom LLM bots) build and verify a merchant integration against the Paymos sandbox without reading docs.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paymos",
|
|
@@ -54,18 +54,22 @@
|
|
|
54
54
|
"build:resources": "node scripts/generate-resources.mjs",
|
|
55
55
|
"check": "tsc --noEmit",
|
|
56
56
|
"test": "vitest run",
|
|
57
|
+
"verify:local": "node scripts/verify-local-setup.mjs",
|
|
57
58
|
"prepack": "npm run check && npm test && npm run build"
|
|
58
59
|
},
|
|
59
60
|
"dependencies": {
|
|
60
61
|
"@modelcontextprotocol/sdk": "^1.31.0",
|
|
61
62
|
"@paymos/sdk": "^2.0.0",
|
|
63
|
+
"jsonc-parser": "3.3.1",
|
|
64
|
+
"smol-toml": "1.9.1",
|
|
62
65
|
"zod": "^4.6.5"
|
|
63
66
|
},
|
|
64
67
|
"devDependencies": {
|
|
65
68
|
"@types/node": "^22.10.0",
|
|
66
|
-
"tsup": "
|
|
69
|
+
"tsup": "8.5.0",
|
|
67
70
|
"typescript": "^5.8.0",
|
|
68
|
-
"vitest": "^
|
|
71
|
+
"vitest": "^4.1.12",
|
|
72
|
+
"vite": "^6.4.5"
|
|
69
73
|
},
|
|
70
74
|
"publishConfig": {
|
|
71
75
|
"access": "public",
|