@financedistrict/fdx 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +26 -0
- package/.prettierrc +6 -0
- package/LICENSE +21 -0
- package/README.md +154 -0
- package/bin/commands/call.js +62 -0
- package/bin/commands/logout.js +12 -0
- package/bin/commands/setup.js +148 -0
- package/bin/commands/status.js +58 -0
- package/bin/fdx.js +66 -0
- package/docs/ARCHITECTURE.md +148 -0
- package/docs/DEVELOPMENT.md +147 -0
- package/docs/UNINSTALL.md +57 -0
- package/package.json +57 -0
- package/src/credential-store.js +226 -0
- package/src/factory.js +29 -0
- package/src/index.js +11 -0
- package/src/mcp-auth.js +480 -0
- package/src/mcp-client.js +151 -0
- package/src/storage.js +38 -0
- package/src/utils/args.js +44 -0
- package/src/utils/logger.js +85 -0
- package/src/utils/pkce.js +27 -0
- package/src/wallet-client.js +275 -0
package/.eslintrc.cjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
root: true,
|
|
3
|
+
env: {
|
|
4
|
+
es2022: true,
|
|
5
|
+
node: true,
|
|
6
|
+
},
|
|
7
|
+
extends: ['eslint:recommended', 'plugin:import/recommended', 'plugin:prettier/recommended'],
|
|
8
|
+
parserOptions: {
|
|
9
|
+
ecmaVersion: 'latest',
|
|
10
|
+
sourceType: 'script',
|
|
11
|
+
},
|
|
12
|
+
plugins: ['import', 'prettier'],
|
|
13
|
+
rules: {
|
|
14
|
+
'prettier/prettier': 'error',
|
|
15
|
+
'import/order': [
|
|
16
|
+
'error',
|
|
17
|
+
{
|
|
18
|
+
'newlines-between': 'always',
|
|
19
|
+
alphabetize: {
|
|
20
|
+
order: 'asc',
|
|
21
|
+
caseInsensitive: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
};
|
package/.prettierrc
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Finance District
|
|
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
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# FDX — Agent Wallet CLI
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@financedistrict/fdx)
|
|
4
|
+
[](https://github.com/financedistrict-platform/fd-agent-wallet-cli/actions/workflows/ci.yml)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
A command-line interface to the [Finance District](https://fd.xyz) MCP wallet server. Gives AI agents crypto wallet capabilities — hold, send, swap, and earn yield on assets across multiple chains — without managing private keys.
|
|
8
|
+
|
|
9
|
+
## Why FDX?
|
|
10
|
+
|
|
11
|
+
FDX is designed for AI agents and agent frameworks that need wallet tooling but don't natively support the [Model Context Protocol (MCP)](https://modelcontextprotocol.io). Instead of integrating an MCP client, agents invoke `fdx call <method>` from the command line and parse JSON output.
|
|
12
|
+
|
|
13
|
+
- **No Key Management** — OAuth 2.1 secured. No seed phrases. No private key files.
|
|
14
|
+
- **Agent-Native** — Structured JSON input/output designed for tool-calling agents.
|
|
15
|
+
- **Multi-Chain** — Ethereum, BSC, Arbitrum, Base, Solana. One wallet, all chains.
|
|
16
|
+
- **DeFi Enabled** — Transfer, swap, and earn yield through integrated DeFi protocols.
|
|
17
|
+
- **Smart Accounts** — Account abstraction with multi-signature support (ERC-4337).
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install -g @financedistrict/fdx
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
Run the setup (opens browser for OAuth):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
fdx setup
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Check that authentication succeeded:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
fdx status
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
To remove stored credentials:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
fdx logout
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Authentication
|
|
44
|
+
|
|
45
|
+
FDX uses OAuth 2.1 with [Microsoft Entra External ID](https://learn.microsoft.com/en-us/entra/external-id/). Authentication is always tied to a user identity — the agent acts as a delegate on the user's behalf.
|
|
46
|
+
|
|
47
|
+
### Interactive flow (default)
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
fdx setup
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Opens the authorization URL in your browser. After consent, the browser redirects back to `localhost:6260` and the CLI completes the flow automatically. Requires a browser on the same machine and an available local port.
|
|
54
|
+
|
|
55
|
+
### Device authorization flow (headless)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
fdx setup --device
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Designed for environments without a browser redirect — Docker containers, CI pipelines, remote servers, and autonomous agents. The CLI retrieves a short one-time code and prints it alongside the verification URL:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
──────────────────────────────────────────────────────────
|
|
65
|
+
Verification URL: https://microsoft.com/devicelogin
|
|
66
|
+
Enter code: ABCD-1234
|
|
67
|
+
──────────────────────────────────────────────────────────
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Open the URL on any device (or have your agent navigate to it), enter the code, and complete sign-in. The CLI polls in the background and stores the token once authorization is confirmed.
|
|
71
|
+
|
|
72
|
+
### Token storage
|
|
73
|
+
|
|
74
|
+
Tokens are stored in the OS credential store where available:
|
|
75
|
+
|
|
76
|
+
| Platform | Backend |
|
|
77
|
+
|----------|---------|
|
|
78
|
+
| macOS | Keychain (`security` CLI) |
|
|
79
|
+
| Linux | libsecret (`secret-tool` CLI) |
|
|
80
|
+
| Windows | DPAPI (encrypted file in `~/.fdx/`) |
|
|
81
|
+
|
|
82
|
+
If no credential store is available (e.g. a minimal container), tokens fall back to plaintext in `~/.fdx/auth.json` with a `SecurityWarning` emitted. Tokens are refreshed automatically using the stored refresh token.
|
|
83
|
+
|
|
84
|
+
### Logging out
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
fdx logout
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Removes the stored access and refresh tokens from the OS credential store and clears them from `~/.fdx/auth.json`. Client registrations (DCR) are preserved so the next `fdx setup` skips re-registration and goes straight to authentication.
|
|
91
|
+
|
|
92
|
+
## Usage
|
|
93
|
+
|
|
94
|
+
Invoke any MCP tool via the CLI:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Check wallet overview
|
|
98
|
+
fdx call getWalletOverview --chainKey ethereum
|
|
99
|
+
|
|
100
|
+
# Send tokens
|
|
101
|
+
fdx call transferTokens --chainKey ethereum --recipientAddress 0xABC... --amount 0.1
|
|
102
|
+
|
|
103
|
+
# Discover yield strategies
|
|
104
|
+
fdx call discoverYieldStrategies --chainKey base
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
All output is JSON, making it easy for agents to parse:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
fdx call getMyInfo | jq '.email'
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Run `fdx call` without arguments to see all available methods.
|
|
114
|
+
|
|
115
|
+
## SDK Usage
|
|
116
|
+
|
|
117
|
+
FDX can also be used as a Node.js library:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
const { createClientFromEnv } = require('@financedistrict/fdx');
|
|
121
|
+
|
|
122
|
+
const client = createClientFromEnv();
|
|
123
|
+
const result = await client.getWalletOverview({ chainKey: 'ethereum' });
|
|
124
|
+
console.log(result.data);
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Configuration
|
|
128
|
+
|
|
129
|
+
| Environment Variable | Description | Default |
|
|
130
|
+
| -------------------- | ------------------ | -------------------------------------- |
|
|
131
|
+
| `FDX_MCP_SERVER` | MCP server URL | `https://mcp.fd.xyz` |
|
|
132
|
+
| `FDX_REDIRECT_URI` | OAuth callback URI | `http://localhost:6260/oauth/callback` |
|
|
133
|
+
| `FDX_STORE_PATH` | Token store path | `~/.fdx/auth.json` |
|
|
134
|
+
| `FDX_LOG_PATH` | Log file path | `~/.fdx/fdx.log` |
|
|
135
|
+
| `FDX_LOG_LEVEL` | Log verbosity (`debug`\|`info`\|`warn`\|`error`\|`off`) | `info` |
|
|
136
|
+
|
|
137
|
+
## Documentation
|
|
138
|
+
|
|
139
|
+
- [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) — System design overview
|
|
140
|
+
- [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) — Running from source
|
|
141
|
+
- [docs/UNINSTALL.md](docs/UNINSTALL.md) — Removal instructions
|
|
142
|
+
|
|
143
|
+
## Contributing
|
|
144
|
+
|
|
145
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
|
|
146
|
+
|
|
147
|
+
## Support
|
|
148
|
+
|
|
149
|
+
- **Issues**: [GitHub Issues](https://github.com/financedistrict-platform/fd-agent-wallet-cli/issues)
|
|
150
|
+
- **Source**: [GitHub Repository](https://github.com/financedistrict-platform/fd-agent-wallet-cli)
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const { createSpinner } = require('nanospinner');
|
|
2
|
+
const pc = require('picocolors');
|
|
3
|
+
|
|
4
|
+
const { createClientFromEnv } = require('../../src');
|
|
5
|
+
const { parseArgs } = require('../../src/utils/args');
|
|
6
|
+
|
|
7
|
+
const METHODS = [
|
|
8
|
+
'getMyInfo',
|
|
9
|
+
'getAppVersion',
|
|
10
|
+
'helpNarrative',
|
|
11
|
+
'onboardingAssistant',
|
|
12
|
+
'reportIssue',
|
|
13
|
+
'getWalletOverview',
|
|
14
|
+
'getAccountActivity',
|
|
15
|
+
'deploySmartAccount',
|
|
16
|
+
'manageSmartAccountOwnership',
|
|
17
|
+
'transferTokens',
|
|
18
|
+
'swapTokens',
|
|
19
|
+
'discoverYieldStrategies',
|
|
20
|
+
'depositForYield',
|
|
21
|
+
'withdrawFromYield',
|
|
22
|
+
'authorizePayment',
|
|
23
|
+
'getX402Content',
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
module.exports = async function call(argv) {
|
|
27
|
+
const method = argv[0];
|
|
28
|
+
|
|
29
|
+
if (!method || !METHODS.includes(method)) {
|
|
30
|
+
console.log(`Usage: fdx call ${pc.cyan('<method>')} [--param value ...]`);
|
|
31
|
+
console.log('');
|
|
32
|
+
console.log(pc.dim('Methods:'));
|
|
33
|
+
for (const m of METHODS) {
|
|
34
|
+
console.log(` ${m}`);
|
|
35
|
+
}
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const args = parseArgs(argv.slice(1));
|
|
40
|
+
const client = createClientFromEnv();
|
|
41
|
+
|
|
42
|
+
const spinner = createSpinner(`Calling ${pc.cyan(method)}...`).start();
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const result = await client[method](args);
|
|
46
|
+
|
|
47
|
+
if (result.error) {
|
|
48
|
+
spinner.error({ text: `${method} failed` });
|
|
49
|
+
console.error(JSON.stringify({ error: result.error }, null, 2));
|
|
50
|
+
process.exit(1);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
spinner.success({ text: `${method}` });
|
|
54
|
+
console.log(JSON.stringify(result.data, null, 2));
|
|
55
|
+
} catch (error) {
|
|
56
|
+
spinner.error({ text: `${method} failed` });
|
|
57
|
+
console.error(pc.red(error.message));
|
|
58
|
+
process.exit(1);
|
|
59
|
+
} finally {
|
|
60
|
+
await client.close().catch(() => {});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const pc = require('picocolors');
|
|
2
|
+
|
|
3
|
+
const { createClientFromEnv } = require('../../src');
|
|
4
|
+
|
|
5
|
+
module.exports = async function logout() {
|
|
6
|
+
const client = createClientFromEnv();
|
|
7
|
+
|
|
8
|
+
await client.logout();
|
|
9
|
+
|
|
10
|
+
console.log(pc.green('Logged out.') + ' Credentials removed.');
|
|
11
|
+
console.log(` Run ${pc.cyan('"fdx setup"')} to authenticate again.`);
|
|
12
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const { URL } = require('url');
|
|
3
|
+
|
|
4
|
+
const { createSpinner } = require('nanospinner');
|
|
5
|
+
const pc = require('picocolors');
|
|
6
|
+
|
|
7
|
+
const { createClientFromEnv } = require('../../src');
|
|
8
|
+
|
|
9
|
+
module.exports = async function setup({ device = false } = {}) {
|
|
10
|
+
const client = createClientFromEnv();
|
|
11
|
+
|
|
12
|
+
console.log(pc.bold(`FDX - Setup${device ? ' (Device Flow)' : ''}`));
|
|
13
|
+
console.log('');
|
|
14
|
+
console.log(`${pc.dim('MCP Server:')} ${client.authClient.mcpServerUrl}`);
|
|
15
|
+
if (!device) {
|
|
16
|
+
console.log(`${pc.dim('Redirect URI:')} ${client.authClient.redirectUri}`);
|
|
17
|
+
}
|
|
18
|
+
console.log(`${pc.dim('Store Path:')} ${client.authClient.storePath}`);
|
|
19
|
+
console.log('');
|
|
20
|
+
|
|
21
|
+
let tokens;
|
|
22
|
+
|
|
23
|
+
if (device) {
|
|
24
|
+
const initSpinner = createSpinner('Registering device client...').start();
|
|
25
|
+
await client.initializeForDevice();
|
|
26
|
+
initSpinner.success({ text: `Client ID: ${pc.cyan(client.authClient.deviceClientId)}` });
|
|
27
|
+
console.log('');
|
|
28
|
+
|
|
29
|
+
const deviceSpinner = createSpinner('Requesting device code...').start();
|
|
30
|
+
const deviceInfo = await client.startDeviceFlow();
|
|
31
|
+
deviceSpinner.success({ text: 'Device code received' });
|
|
32
|
+
|
|
33
|
+
console.log('');
|
|
34
|
+
console.log(pc.bold('─'.repeat(58)));
|
|
35
|
+
console.log(` ${pc.dim('Verification URL:')} ${pc.underline(deviceInfo.verificationUri)}`);
|
|
36
|
+
console.log(` ${pc.bold('Enter code:')} ${pc.cyan(pc.bold(deviceInfo.userCode))}`);
|
|
37
|
+
console.log(pc.bold('─'.repeat(58)));
|
|
38
|
+
console.log('');
|
|
39
|
+
|
|
40
|
+
const pollSpinner = createSpinner('Waiting for authorization...').start();
|
|
41
|
+
tokens = await client.pollDeviceToken({
|
|
42
|
+
deviceCode: deviceInfo.deviceCode,
|
|
43
|
+
interval: deviceInfo.interval,
|
|
44
|
+
});
|
|
45
|
+
pollSpinner.success({ text: 'Authentication successful' });
|
|
46
|
+
} else {
|
|
47
|
+
const initSpinner = createSpinner('Registering client...').start();
|
|
48
|
+
await client.initialize();
|
|
49
|
+
initSpinner.success({ text: `Client ID: ${pc.cyan(client.authClient.clientId)}` });
|
|
50
|
+
console.log('');
|
|
51
|
+
|
|
52
|
+
const port = new URL(client.authClient.redirectUri).port || 6260;
|
|
53
|
+
const { url, state, codeVerifier } = await client.getAuthorizationUrl();
|
|
54
|
+
|
|
55
|
+
console.log('Open this URL in your browser:');
|
|
56
|
+
console.log('');
|
|
57
|
+
console.log(pc.underline(url));
|
|
58
|
+
console.log('');
|
|
59
|
+
|
|
60
|
+
const callbackSpinner = createSpinner('Waiting for callback...').start();
|
|
61
|
+
|
|
62
|
+
const callback = await waitForCallback(port, client.authClient.redirectUri);
|
|
63
|
+
callbackSpinner.success({ text: 'Callback received' });
|
|
64
|
+
|
|
65
|
+
if (callback.state !== state) {
|
|
66
|
+
console.error(pc.red('OAuth state mismatch — possible CSRF attack. Aborting.'));
|
|
67
|
+
process.exit(1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const tokenSpinner = createSpinner('Exchanging code for token...').start();
|
|
71
|
+
tokens = await client.exchangeCodeForToken({ code: callback.code, state, codeVerifier });
|
|
72
|
+
tokenSpinner.success({ text: 'Authentication successful' });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
console.log('');
|
|
76
|
+
console.log(` ${pc.dim('Token Type:')} ${tokens.token_type}`);
|
|
77
|
+
console.log(` ${pc.dim('Expires In:')} ${tokens.expires_in}s`);
|
|
78
|
+
console.log(
|
|
79
|
+
` ${pc.dim('Has Refresh:')} ${tokens.refresh_token ? pc.green('yes') : pc.yellow('no')}`,
|
|
80
|
+
);
|
|
81
|
+
console.log('');
|
|
82
|
+
console.log(
|
|
83
|
+
pc.green('Done.') +
|
|
84
|
+
' You can now use ' +
|
|
85
|
+
pc.cyan('"fdx call <method>"') +
|
|
86
|
+
' to invoke MCP tools.',
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
function escapeHtml(str) {
|
|
91
|
+
return str
|
|
92
|
+
.replace(/&/g, '&')
|
|
93
|
+
.replace(/</g, '<')
|
|
94
|
+
.replace(/>/g, '>')
|
|
95
|
+
.replace(/"/g, '"');
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function waitForCallback(port, redirectUri) {
|
|
99
|
+
const callbackPath = new URL(redirectUri).pathname;
|
|
100
|
+
|
|
101
|
+
return new Promise((resolve, reject) => {
|
|
102
|
+
const server = http.createServer((req, res) => {
|
|
103
|
+
const url = new URL(req.url, `http://localhost:${port}`);
|
|
104
|
+
|
|
105
|
+
if (url.pathname === callbackPath) {
|
|
106
|
+
const code = url.searchParams.get('code');
|
|
107
|
+
const error = url.searchParams.get('error');
|
|
108
|
+
const errorDescription = url.searchParams.get('error_description');
|
|
109
|
+
|
|
110
|
+
if (error) {
|
|
111
|
+
res.writeHead(400, { 'Content-Type': 'text/html' });
|
|
112
|
+
res.end(
|
|
113
|
+
`<html><body><h1>Error: ${escapeHtml(error)}</h1><p>${escapeHtml(errorDescription || '')}</p></body></html>`,
|
|
114
|
+
);
|
|
115
|
+
server.close();
|
|
116
|
+
clearTimeout(timer);
|
|
117
|
+
reject(new Error(`${error}: ${errorDescription}`));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (code) {
|
|
122
|
+
const callbackState = url.searchParams.get('state');
|
|
123
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
124
|
+
res.end('<html><body><h1>Success</h1><p>You can close this window.</p></body></html>');
|
|
125
|
+
server.close();
|
|
126
|
+
clearTimeout(timer);
|
|
127
|
+
resolve({ code, state: callbackState });
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
res.writeHead(404);
|
|
133
|
+
res.end('Not Found');
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const TIMEOUT_MS = 5 * 60 * 1000;
|
|
137
|
+
const timer = setTimeout(() => {
|
|
138
|
+
server.close();
|
|
139
|
+
reject(new Error('OAuth callback timed out after 5 minutes'));
|
|
140
|
+
}, TIMEOUT_MS);
|
|
141
|
+
|
|
142
|
+
server.listen(port, '127.0.0.1', () => {});
|
|
143
|
+
server.on('error', (err) => {
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
reject(new Error(`Callback server error: ${err.message}`));
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const pc = require('picocolors');
|
|
2
|
+
|
|
3
|
+
const { createClientFromEnv } = require('../../src');
|
|
4
|
+
|
|
5
|
+
module.exports = async function status() {
|
|
6
|
+
const client = createClientFromEnv();
|
|
7
|
+
const storePath = client.authClient.storePath;
|
|
8
|
+
const mcpServer = client.authClient.mcpServerUrl;
|
|
9
|
+
|
|
10
|
+
let state;
|
|
11
|
+
try {
|
|
12
|
+
state = await client.getTokenState();
|
|
13
|
+
} catch (error) {
|
|
14
|
+
console.log(pc.red('Status: not configured'));
|
|
15
|
+
console.log(` ${pc.dim('MCP server:')} ${mcpServer}`);
|
|
16
|
+
console.log(` ${pc.dim('Store path:')} ${storePath} (${error.message})`);
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!state.authenticated) {
|
|
21
|
+
console.log(pc.yellow('Status: not authenticated'));
|
|
22
|
+
console.log(` ${pc.dim('MCP server:')} ${mcpServer}`);
|
|
23
|
+
console.log(` ${pc.dim('Store path:')} ${storePath}`);
|
|
24
|
+
console.log(` Run ${pc.cyan('"fdx setup"')} to authenticate.`);
|
|
25
|
+
process.exit(1);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const statusLabel = state.expired ? pc.yellow('token expired') : pc.green('authenticated');
|
|
29
|
+
console.log(`Status: ${statusLabel}`);
|
|
30
|
+
console.log(` ${pc.dim('MCP server:')} ${mcpServer}`);
|
|
31
|
+
console.log(` ${pc.dim('Store path:')} ${storePath}`);
|
|
32
|
+
console.log(` ${pc.dim('Client ID:')} ${state.clientId || 'unknown'}`);
|
|
33
|
+
console.log(
|
|
34
|
+
` ${pc.dim('Token expires:')} ${state.expiresAt ? new Date(state.expiresAt).toISOString() : 'unknown'}`,
|
|
35
|
+
);
|
|
36
|
+
console.log(
|
|
37
|
+
` ${pc.dim('Has refresh:')} ${state.hasRefresh ? pc.green('yes') : pc.yellow('no')}`,
|
|
38
|
+
);
|
|
39
|
+
console.log(
|
|
40
|
+
` ${pc.dim('Credentials:')} ${state.usingCredentialStore ? pc.green('OS credential store') : pc.yellow('plaintext file')}`,
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
if (state.expired && !state.hasRefresh) {
|
|
44
|
+
console.log('');
|
|
45
|
+
console.log(
|
|
46
|
+
pc.red('Token expired and no refresh token.') +
|
|
47
|
+
` Run ${pc.cyan('"fdx setup"')} to re-authenticate.`,
|
|
48
|
+
);
|
|
49
|
+
process.exit(1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (state.expired && state.hasRefresh) {
|
|
53
|
+
console.log('');
|
|
54
|
+
console.log(
|
|
55
|
+
pc.dim('Token expired but refresh token available. Will auto-refresh on next call.'),
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
};
|
package/bin/fdx.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
require('dotenv').config({ path: require('path').resolve(process.cwd(), '.env') });
|
|
4
|
+
|
|
5
|
+
const { Command } = require('commander');
|
|
6
|
+
const pc = require('picocolors');
|
|
7
|
+
|
|
8
|
+
const pkg = require('../package.json');
|
|
9
|
+
|
|
10
|
+
const program = new Command();
|
|
11
|
+
|
|
12
|
+
program
|
|
13
|
+
.name('fdx')
|
|
14
|
+
.description('Agent wallet CLI — Finance District MCP wallet client')
|
|
15
|
+
.version(pkg.version)
|
|
16
|
+
.enablePositionalOptions()
|
|
17
|
+
.addHelpText(
|
|
18
|
+
'after',
|
|
19
|
+
[
|
|
20
|
+
'',
|
|
21
|
+
`${pc.dim('Environment:')}`,
|
|
22
|
+
` FDX_MCP_SERVER MCP server URL (default: https://mcp.fd.xyz)`,
|
|
23
|
+
` FDX_REDIRECT_URI OAuth callback URI (default: http://localhost:6260/oauth/callback)`,
|
|
24
|
+
` FDX_STORE_PATH Token store path (default: ~/.fdx/auth.json)`,
|
|
25
|
+
` FDX_LOG_PATH Log file path (default: ~/.fdx/fdx.log)`,
|
|
26
|
+
` FDX_LOG_LEVEL Log verbosity: debug|info|warn|error|off (default: info)`,
|
|
27
|
+
].join('\n'),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
program
|
|
31
|
+
.command('setup')
|
|
32
|
+
.description('Run OAuth 2.1 authentication flow')
|
|
33
|
+
.option('--device', 'Use device authorization flow (no browser redirect required)')
|
|
34
|
+
.action(async (opts) => {
|
|
35
|
+
await require('./commands/setup')(opts);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
program
|
|
39
|
+
.command('status')
|
|
40
|
+
.description('Check authentication status')
|
|
41
|
+
.action(async () => {
|
|
42
|
+
await require('./commands/status')();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
program
|
|
46
|
+
.command('logout')
|
|
47
|
+
.description('Remove stored credentials')
|
|
48
|
+
.action(async () => {
|
|
49
|
+
await require('./commands/logout')();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
program
|
|
53
|
+
.command('call')
|
|
54
|
+
.description('Invoke an MCP tool')
|
|
55
|
+
.argument('<method>', 'tool name to invoke')
|
|
56
|
+
.allowUnknownOption()
|
|
57
|
+
.allowExcessArguments(true)
|
|
58
|
+
.passThroughOptions()
|
|
59
|
+
.action(async (method, _opts, cmd) => {
|
|
60
|
+
await require('./commands/call')([method, ...cmd.args.slice(1)]);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
program.parseAsync().catch((error) => {
|
|
64
|
+
console.error(pc.red(error.message));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
});
|