@tongateway/mcp 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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/index.js ADDED
@@ -0,0 +1,126 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { z } from 'zod';
5
+ const API_URL = process.env.AGENT_GATEWAY_API_URL ?? 'https://api.tongateway.ai';
6
+ const TOKEN = process.env.AGENT_GATEWAY_TOKEN;
7
+ if (!TOKEN) {
8
+ console.error('AGENT_GATEWAY_TOKEN environment variable is required');
9
+ process.exit(1);
10
+ }
11
+ async function apiCall(path, options = {}) {
12
+ const res = await fetch(`${API_URL}${path}`, {
13
+ ...options,
14
+ headers: {
15
+ 'Content-Type': 'application/json',
16
+ Authorization: `Bearer ${TOKEN}`,
17
+ ...options.headers,
18
+ },
19
+ });
20
+ const data = await res.json();
21
+ if (!res.ok) {
22
+ throw new Error(data.error ?? `API error ${res.status}`);
23
+ }
24
+ return data;
25
+ }
26
+ const server = new McpServer({
27
+ name: 'agent-gateway',
28
+ version: '0.1.0',
29
+ });
30
+ server.tool('request_transfer', 'Request a TON transfer from the wallet owner. The request will be queued and the owner must approve it via TON Connect.', {
31
+ to: z.string().describe('Destination TON address'),
32
+ amountNano: z.string().describe('Amount in nanoTON (1 TON = 1000000000)'),
33
+ payloadBoc: z.string().optional().describe('Optional BOC-encoded payload for the transaction'),
34
+ }, async ({ to, amountNano, payloadBoc }) => {
35
+ try {
36
+ const body = { to, amountNano };
37
+ if (payloadBoc)
38
+ body.payloadBoc = payloadBoc;
39
+ const result = await apiCall('/v1/safe/tx/transfer', {
40
+ method: 'POST',
41
+ body: JSON.stringify(body),
42
+ });
43
+ return {
44
+ content: [
45
+ {
46
+ type: 'text',
47
+ text: [
48
+ `Transfer request created.`,
49
+ `ID: ${result.id}`,
50
+ `To: ${result.to}`,
51
+ `Amount: ${result.amountNano} nanoTON`,
52
+ `Status: ${result.status}`,
53
+ `Expires: ${new Date(result.expiresAt).toISOString()}`,
54
+ ``,
55
+ `The wallet owner must approve this in their TON Connect client.`,
56
+ ].join('\n'),
57
+ },
58
+ ],
59
+ };
60
+ }
61
+ catch (e) {
62
+ return {
63
+ content: [{ type: 'text', text: `Error: ${e.message}` }],
64
+ isError: true,
65
+ };
66
+ }
67
+ });
68
+ server.tool('get_request_status', 'Check the status of a previously submitted transfer request.', {
69
+ id: z.string().describe('The request ID returned by request_transfer'),
70
+ }, async ({ id }) => {
71
+ try {
72
+ const result = await apiCall(`/v1/safe/tx/${id}`);
73
+ return {
74
+ content: [
75
+ {
76
+ type: 'text',
77
+ text: [
78
+ `Request ${result.id}`,
79
+ `Status: ${result.status}`,
80
+ `To: ${result.to}`,
81
+ `Amount: ${result.amountNano} nanoTON`,
82
+ result.txHash ? `TX Hash: ${result.txHash}` : null,
83
+ `Created: ${new Date(result.createdAt).toISOString()}`,
84
+ `Expires: ${new Date(result.expiresAt).toISOString()}`,
85
+ ]
86
+ .filter(Boolean)
87
+ .join('\n'),
88
+ },
89
+ ],
90
+ };
91
+ }
92
+ catch (e) {
93
+ return {
94
+ content: [{ type: 'text', text: `Error: ${e.message}` }],
95
+ isError: true,
96
+ };
97
+ }
98
+ });
99
+ server.tool('list_pending_requests', 'List all pending transfer requests waiting for wallet owner approval.', {}, async () => {
100
+ try {
101
+ const data = await apiCall('/v1/safe/tx/pending');
102
+ const requests = data.requests;
103
+ if (!requests.length) {
104
+ return {
105
+ content: [{ type: 'text', text: 'No pending requests.' }],
106
+ };
107
+ }
108
+ const lines = requests.map((r) => `- ${r.id}: ${r.amountNano} nanoTON → ${r.to} (expires ${new Date(r.expiresAt).toISOString()})`);
109
+ return {
110
+ content: [
111
+ {
112
+ type: 'text',
113
+ text: `${requests.length} pending request(s):\n${lines.join('\n')}`,
114
+ },
115
+ ],
116
+ };
117
+ }
118
+ catch (e) {
119
+ return {
120
+ content: [{ type: 'text', text: `Error: ${e.message}` }],
121
+ isError: true,
122
+ };
123
+ }
124
+ });
125
+ const transport = new StdioServerTransport();
126
+ await server.connect(transport);
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@tongateway/mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for Agent Gateway — lets AI agents request TON blockchain transfers",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/tongateway/agent-gateway-mcp"
9
+ },
10
+ "keywords": ["mcp", "ton", "blockchain", "agent", "ai", "wallet"],
11
+ "type": "module",
12
+ "bin": {
13
+ "agent-gateway-mcp": "./dist/index.js"
14
+ },
15
+ "files": ["dist"],
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "dev": "tsx src/index.ts"
19
+ },
20
+ "dependencies": {
21
+ "@modelcontextprotocol/sdk": "^1.12.1",
22
+ "zod": "^4.3.6"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^22.17.2",
26
+ "tsx": "^4.20.5",
27
+ "typescript": "^5.9.2"
28
+ }
29
+ }