@tongateway/mcp 0.3.0 → 0.4.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/dist/index.js +24 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,8 +2,29 @@
|
|
|
2
2
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
+
import { readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
|
6
|
+
import { join } from 'node:path';
|
|
7
|
+
import { homedir } from 'node:os';
|
|
5
8
|
const API_URL = process.env.AGENT_GATEWAY_API_URL ?? 'https://api.tongateway.ai';
|
|
6
|
-
|
|
9
|
+
const TOKEN_FILE = join(homedir(), '.tongateway', 'token');
|
|
10
|
+
function loadToken() {
|
|
11
|
+
if (process.env.AGENT_GATEWAY_TOKEN)
|
|
12
|
+
return process.env.AGENT_GATEWAY_TOKEN;
|
|
13
|
+
try {
|
|
14
|
+
return readFileSync(TOKEN_FILE, 'utf-8').trim();
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return '';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function saveToken(token) {
|
|
21
|
+
try {
|
|
22
|
+
mkdirSync(join(homedir(), '.tongateway'), { recursive: true });
|
|
23
|
+
writeFileSync(TOKEN_FILE, token, 'utf-8');
|
|
24
|
+
}
|
|
25
|
+
catch { }
|
|
26
|
+
}
|
|
27
|
+
let TOKEN = loadToken();
|
|
7
28
|
async function apiCall(path, options = {}) {
|
|
8
29
|
const headers = {
|
|
9
30
|
'Content-Type': 'application/json',
|
|
@@ -91,8 +112,9 @@ server.tool('get_auth_token', 'Check if the user has completed wallet authentica
|
|
|
91
112
|
],
|
|
92
113
|
};
|
|
93
114
|
}
|
|
94
|
-
// Store the token for future API calls
|
|
115
|
+
// Store the token for future API calls and persist to disk
|
|
95
116
|
TOKEN = data.token;
|
|
117
|
+
saveToken(TOKEN);
|
|
96
118
|
return {
|
|
97
119
|
content: [
|
|
98
120
|
{
|