@missionsquad/mcp-server-tron 1.2.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.
Files changed (193) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +537 -0
  3. package/bin/cli.js +51 -0
  4. package/build/core/chains.d.ts +17 -0
  5. package/build/core/chains.js +87 -0
  6. package/build/core/chains.js.map +1 -0
  7. package/build/core/prompts.d.ts +19 -0
  8. package/build/core/prompts.js +485 -0
  9. package/build/core/prompts.js.map +1 -0
  10. package/build/core/resources.d.ts +14 -0
  11. package/build/core/resources.js +42 -0
  12. package/build/core/resources.js.map +1 -0
  13. package/build/core/services/account-data.d.ts +144 -0
  14. package/build/core/services/account-data.js +228 -0
  15. package/build/core/services/account-data.js.map +1 -0
  16. package/build/core/services/account-resource.d.ts +56 -0
  17. package/build/core/services/account-resource.js +133 -0
  18. package/build/core/services/account-resource.js.map +1 -0
  19. package/build/core/services/account.d.ts +141 -0
  20. package/build/core/services/account.js +191 -0
  21. package/build/core/services/account.js.map +1 -0
  22. package/build/core/services/address.d.ts +8 -0
  23. package/build/core/services/address.js +52 -0
  24. package/build/core/services/address.js.map +1 -0
  25. package/build/core/services/agent-wallet.d.ts +62 -0
  26. package/build/core/services/agent-wallet.js +234 -0
  27. package/build/core/services/agent-wallet.js.map +1 -0
  28. package/build/core/services/balance.d.ts +26 -0
  29. package/build/core/services/balance.js +60 -0
  30. package/build/core/services/balance.js.map +1 -0
  31. package/build/core/services/blocks.d.ts +25 -0
  32. package/build/core/services/blocks.js +65 -0
  33. package/build/core/services/blocks.js.map +1 -0
  34. package/build/core/services/broadcast.d.ts +13 -0
  35. package/build/core/services/broadcast.js +24 -0
  36. package/build/core/services/broadcast.js.map +1 -0
  37. package/build/core/services/clients.d.ts +5 -0
  38. package/build/core/services/clients.js +29 -0
  39. package/build/core/services/clients.js.map +1 -0
  40. package/build/core/services/contract-data.d.ts +31 -0
  41. package/build/core/services/contract-data.js +54 -0
  42. package/build/core/services/contract-data.js.map +1 -0
  43. package/build/core/services/contracts.d.ts +108 -0
  44. package/build/core/services/contracts.js +482 -0
  45. package/build/core/services/contracts.js.map +1 -0
  46. package/build/core/services/events.d.ts +56 -0
  47. package/build/core/services/events.js +99 -0
  48. package/build/core/services/events.js.map +1 -0
  49. package/build/core/services/governance.d.ts +78 -0
  50. package/build/core/services/governance.js +207 -0
  51. package/build/core/services/governance.js.map +1 -0
  52. package/build/core/services/index.d.ts +28 -0
  53. package/build/core/services/index.js +81 -0
  54. package/build/core/services/index.js.map +1 -0
  55. package/build/core/services/mempool.d.ts +12 -0
  56. package/build/core/services/mempool.js +32 -0
  57. package/build/core/services/mempool.js.map +1 -0
  58. package/build/core/services/multicall-abi.d.ts +55 -0
  59. package/build/core/services/multicall-abi.js +61 -0
  60. package/build/core/services/multicall-abi.js.map +1 -0
  61. package/build/core/services/nodes.d.ts +8 -0
  62. package/build/core/services/nodes.js +18 -0
  63. package/build/core/services/nodes.js.map +1 -0
  64. package/build/core/services/proposals.d.ts +33 -0
  65. package/build/core/services/proposals.js +95 -0
  66. package/build/core/services/proposals.js.map +1 -0
  67. package/build/core/services/query.d.ts +34 -0
  68. package/build/core/services/query.js +60 -0
  69. package/build/core/services/query.js.map +1 -0
  70. package/build/core/services/staking.d.ts +40 -0
  71. package/build/core/services/staking.js +113 -0
  72. package/build/core/services/staking.js.map +1 -0
  73. package/build/core/services/tokens.d.ts +22 -0
  74. package/build/core/services/tokens.js +68 -0
  75. package/build/core/services/tokens.js.map +1 -0
  76. package/build/core/services/transactions.d.ts +16 -0
  77. package/build/core/services/transactions.js +42 -0
  78. package/build/core/services/transactions.js.map +1 -0
  79. package/build/core/services/transfer.d.ts +24 -0
  80. package/build/core/services/transfer.js +84 -0
  81. package/build/core/services/transfer.js.map +1 -0
  82. package/build/core/services/trongrid-client.d.ts +14 -0
  83. package/build/core/services/trongrid-client.js +19 -0
  84. package/build/core/services/trongrid-client.js.map +1 -0
  85. package/build/core/services/utils.d.ts +13 -0
  86. package/build/core/services/utils.js +39 -0
  87. package/build/core/services/utils.js.map +1 -0
  88. package/build/core/services/wallet.d.ts +13 -0
  89. package/build/core/services/wallet.js +18 -0
  90. package/build/core/services/wallet.js.map +1 -0
  91. package/build/core/tools/account-data.d.ts +2 -0
  92. package/build/core/tools/account-data.js +253 -0
  93. package/build/core/tools/account-data.js.map +1 -0
  94. package/build/core/tools/account-resource.d.ts +2 -0
  95. package/build/core/tools/account-resource.js +269 -0
  96. package/build/core/tools/account-resource.js.map +1 -0
  97. package/build/core/tools/account.d.ts +2 -0
  98. package/build/core/tools/account.js +451 -0
  99. package/build/core/tools/account.js.map +1 -0
  100. package/build/core/tools/address.d.ts +2 -0
  101. package/build/core/tools/address.js +45 -0
  102. package/build/core/tools/address.js.map +1 -0
  103. package/build/core/tools/balance.d.ts +2 -0
  104. package/build/core/tools/balance.js +94 -0
  105. package/build/core/tools/balance.js.map +1 -0
  106. package/build/core/tools/block.d.ts +2 -0
  107. package/build/core/tools/block.js +74 -0
  108. package/build/core/tools/block.js.map +1 -0
  109. package/build/core/tools/broadcast.d.ts +2 -0
  110. package/build/core/tools/broadcast.js +102 -0
  111. package/build/core/tools/broadcast.js.map +1 -0
  112. package/build/core/tools/contract-data.d.ts +2 -0
  113. package/build/core/tools/contract-data.js +159 -0
  114. package/build/core/tools/contract-data.js.map +1 -0
  115. package/build/core/tools/contract.d.ts +2 -0
  116. package/build/core/tools/contract.js +600 -0
  117. package/build/core/tools/contract.js.map +1 -0
  118. package/build/core/tools/event.d.ts +2 -0
  119. package/build/core/tools/event.js +159 -0
  120. package/build/core/tools/event.js.map +1 -0
  121. package/build/core/tools/governance.d.ts +6 -0
  122. package/build/core/tools/governance.js +424 -0
  123. package/build/core/tools/governance.js.map +1 -0
  124. package/build/core/tools/index.d.ts +15 -0
  125. package/build/core/tools/index.js +93 -0
  126. package/build/core/tools/index.js.map +1 -0
  127. package/build/core/tools/mempool.d.ts +2 -0
  128. package/build/core/tools/mempool.js +116 -0
  129. package/build/core/tools/mempool.js.map +1 -0
  130. package/build/core/tools/network.d.ts +2 -0
  131. package/build/core/tools/network.js +114 -0
  132. package/build/core/tools/network.js.map +1 -0
  133. package/build/core/tools/node.d.ts +2 -0
  134. package/build/core/tools/node.js +75 -0
  135. package/build/core/tools/node.js.map +1 -0
  136. package/build/core/tools/proposals.d.ts +6 -0
  137. package/build/core/tools/proposals.js +219 -0
  138. package/build/core/tools/proposals.js.map +1 -0
  139. package/build/core/tools/query.d.ts +2 -0
  140. package/build/core/tools/query.js +399 -0
  141. package/build/core/tools/query.js.map +1 -0
  142. package/build/core/tools/staking.d.ts +2 -0
  143. package/build/core/tools/staking.js +281 -0
  144. package/build/core/tools/staking.js.map +1 -0
  145. package/build/core/tools/transaction.d.ts +2 -0
  146. package/build/core/tools/transaction.js +65 -0
  147. package/build/core/tools/transaction.js.map +1 -0
  148. package/build/core/tools/transfer.d.ts +2 -0
  149. package/build/core/tools/transfer.js +101 -0
  150. package/build/core/tools/transfer.js.map +1 -0
  151. package/build/core/tools/types.d.ts +13 -0
  152. package/build/core/tools/types.js +2 -0
  153. package/build/core/tools/types.js.map +1 -0
  154. package/build/core/tools/wallet.d.ts +2 -0
  155. package/build/core/tools/wallet.js +172 -0
  156. package/build/core/tools/wallet.js.map +1 -0
  157. package/build/index.d.ts +1 -0
  158. package/build/index.js +21 -0
  159. package/build/index.js.map +1 -0
  160. package/build/middleware/auth.d.ts +16 -0
  161. package/build/middleware/auth.js +44 -0
  162. package/build/middleware/auth.js.map +1 -0
  163. package/build/oauth/OAuthService.d.ts +100 -0
  164. package/build/oauth/OAuthService.js +507 -0
  165. package/build/oauth/OAuthService.js.map +1 -0
  166. package/build/oauth/page.d.ts +1 -0
  167. package/build/oauth/page.js +255 -0
  168. package/build/oauth/page.js.map +1 -0
  169. package/build/oauth/types.d.ts +65 -0
  170. package/build/oauth/types.js +2 -0
  171. package/build/oauth/types.js.map +1 -0
  172. package/build/server/http-app.d.ts +9 -0
  173. package/build/server/http-app.js +128 -0
  174. package/build/server/http-app.js.map +1 -0
  175. package/build/server/http-server.d.ts +1 -0
  176. package/build/server/http-server.js +35 -0
  177. package/build/server/http-server.js.map +1 -0
  178. package/build/server/oauth-routes.d.ts +7 -0
  179. package/build/server/oauth-routes.js +157 -0
  180. package/build/server/oauth-routes.js.map +1 -0
  181. package/build/server/server.d.ts +9 -0
  182. package/build/server/server.js +54 -0
  183. package/build/server/server.js.map +1 -0
  184. package/build/tenant/TenantManager.d.ts +35 -0
  185. package/build/tenant/TenantManager.js +167 -0
  186. package/build/tenant/TenantManager.js.map +1 -0
  187. package/build/tenant/context.d.ts +11 -0
  188. package/build/tenant/context.js +23 -0
  189. package/build/tenant/context.js.map +1 -0
  190. package/build/tenant/types.d.ts +16 -0
  191. package/build/tenant/types.js +2 -0
  192. package/build/tenant/types.js.map +1 -0
  193. package/package.json +95 -0
@@ -0,0 +1,255 @@
1
+ export function renderOAuthWalletPage() {
2
+ return `<!doctype html>
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <title>TRON MCP Authorization</title>
8
+ <style>
9
+ :root {
10
+ color-scheme: light;
11
+ font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
12
+ }
13
+ body {
14
+ margin: 0;
15
+ min-height: 100vh;
16
+ display: grid;
17
+ place-items: center;
18
+ background:
19
+ radial-gradient(circle at top right, rgba(255, 78, 80, 0.18), transparent 35%),
20
+ linear-gradient(180deg, #fff7f5 0%, #fff 100%);
21
+ color: #1f2937;
22
+ }
23
+ .card {
24
+ width: min(560px, calc(100vw - 32px));
25
+ background: rgba(255,255,255,0.95);
26
+ border: 1px solid rgba(226, 232, 240, 0.9);
27
+ border-radius: 20px;
28
+ box-shadow: 0 30px 80px rgba(15, 23, 42, 0.12);
29
+ padding: 28px;
30
+ }
31
+ h1 {
32
+ margin: 0 0 8px;
33
+ font-size: 28px;
34
+ }
35
+ p {
36
+ margin: 0 0 14px;
37
+ line-height: 1.5;
38
+ }
39
+ .actions {
40
+ display: grid;
41
+ gap: 12px;
42
+ margin-top: 20px;
43
+ }
44
+ button {
45
+ border: 0;
46
+ border-radius: 12px;
47
+ padding: 14px 16px;
48
+ font-size: 15px;
49
+ font-weight: 600;
50
+ cursor: pointer;
51
+ }
52
+ .primary {
53
+ background: #111827;
54
+ color: white;
55
+ }
56
+ .secondary {
57
+ background: #fee2e2;
58
+ color: #991b1b;
59
+ }
60
+ .panel {
61
+ display: none;
62
+ margin-top: 18px;
63
+ padding: 16px;
64
+ border-radius: 12px;
65
+ background: #f8fafc;
66
+ border: 1px solid #e2e8f0;
67
+ }
68
+ .panel.visible {
69
+ display: block;
70
+ }
71
+ .secret {
72
+ word-break: break-all;
73
+ font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
74
+ background: #111827;
75
+ color: #fff;
76
+ border-radius: 10px;
77
+ padding: 12px;
78
+ margin: 12px 0;
79
+ }
80
+ .status {
81
+ margin-top: 14px;
82
+ padding: 12px;
83
+ border-radius: 10px;
84
+ font-size: 14px;
85
+ }
86
+ .status.error {
87
+ background: #fee2e2;
88
+ color: #991b1b;
89
+ }
90
+ .status.info {
91
+ background: #e0f2fe;
92
+ color: #075985;
93
+ }
94
+ .status.success {
95
+ background: #dcfce7;
96
+ color: #166534;
97
+ }
98
+ label {
99
+ display: flex;
100
+ align-items: flex-start;
101
+ gap: 10px;
102
+ font-size: 14px;
103
+ line-height: 1.4;
104
+ margin-top: 10px;
105
+ }
106
+ </style>
107
+ </head>
108
+ <body>
109
+ <main class="card">
110
+ <h1>Authorize TRON MCP Access</h1>
111
+ <p>
112
+ This server uses OAuth2 for MissionSquad compatibility. During authorization you can either
113
+ prove ownership of an existing managed wallet or create a new managed wallet.
114
+ </p>
115
+
116
+ <div class="actions">
117
+ <button id="connect-existing" class="primary">Connect Existing Managed Wallet</button>
118
+ <button id="create-wallet" class="secondary">Create New Managed Wallet</button>
119
+ </div>
120
+
121
+ <section id="create-wallet-panel" class="panel" aria-live="polite">
122
+ <p><strong>Save this private key now.</strong> It is shown exactly once.</p>
123
+ <div><strong>Wallet Address</strong></div>
124
+ <div id="created-wallet-address" class="secret"></div>
125
+ <div><strong>Private Key</strong></div>
126
+ <div id="created-private-key" class="secret"></div>
127
+ <label>
128
+ <input id="saved-private-key" type="checkbox" />
129
+ <span>I have saved this private key securely and understand it will not be shown again.</span>
130
+ </label>
131
+ <div class="actions">
132
+ <button id="complete-create-wallet" class="primary" disabled>Continue to MissionSquad</button>
133
+ </div>
134
+ </section>
135
+
136
+ <div id="status" class="status info" hidden>Ready.</div>
137
+ </main>
138
+
139
+ <script>
140
+ const statusEl = document.getElementById("status");
141
+ const createPanel = document.getElementById("create-wallet-panel");
142
+ const connectExistingButton = document.getElementById("connect-existing");
143
+ const createWalletButton = document.getElementById("create-wallet");
144
+ const createdWalletAddressEl = document.getElementById("created-wallet-address");
145
+ const createdPrivateKeyEl = document.getElementById("created-private-key");
146
+ const savedPrivateKeyCheckbox = document.getElementById("saved-private-key");
147
+ const completeCreateWalletButton = document.getElementById("complete-create-wallet");
148
+
149
+ let pendingRedirect = null;
150
+
151
+ function setStatus(kind, message) {
152
+ statusEl.hidden = false;
153
+ statusEl.className = "status " + kind;
154
+ statusEl.textContent = message;
155
+ }
156
+
157
+ async function requestJson(url, body) {
158
+ const response = await fetch(url, {
159
+ method: "POST",
160
+ credentials: "same-origin",
161
+ headers: {
162
+ "Content-Type": "application/json",
163
+ "Accept": "application/json",
164
+ },
165
+ body: JSON.stringify(body),
166
+ });
167
+
168
+ const payload = await response.json().catch(() => ({}));
169
+ if (!response.ok) {
170
+ throw new Error(payload.error || payload.message || "Request failed.");
171
+ }
172
+ return payload;
173
+ }
174
+
175
+ async function getInjectedTronWeb() {
176
+ const provider = window.tron || window.tronWeb;
177
+ if (!provider) {
178
+ throw new Error("No TRON browser wallet was found. Install TronLink or another compatible wallet.");
179
+ }
180
+
181
+ if (window.tron && typeof window.tron.request === "function") {
182
+ try {
183
+ await window.tron.request({ method: "eth_requestAccounts" });
184
+ } catch (error) {
185
+ throw new Error("Wallet connection was rejected.");
186
+ }
187
+ }
188
+
189
+ const tronWeb = window.tronWeb || (window.tron && window.tron.tronWeb) || provider;
190
+ if (!tronWeb || !tronWeb.defaultAddress || !tronWeb.defaultAddress.base58) {
191
+ throw new Error("Unable to read the connected TRON wallet address.");
192
+ }
193
+ return tronWeb;
194
+ }
195
+
196
+ async function connectExistingManagedWallet() {
197
+ setStatus("info", "Connecting browser wallet...");
198
+ const tronWeb = await getInjectedTronWeb();
199
+ const walletAddress = tronWeb.defaultAddress.base58;
200
+ setStatus("info", "Requesting wallet challenge...");
201
+ const challengeResponse = await requestJson("/oauth/authorize/challenge", { walletAddress });
202
+
203
+ setStatus("info", "Waiting for wallet signature...");
204
+ const signature = await tronWeb.trx.signMessageV2(challengeResponse.challenge);
205
+
206
+ setStatus("info", "Verifying wallet proof...");
207
+ const verifyResponse = await requestJson("/oauth/authorize/verify", {
208
+ walletAddress,
209
+ challenge: challengeResponse.challenge,
210
+ signature,
211
+ });
212
+
213
+ setStatus("success", "Wallet verified. Redirecting to MissionSquad...");
214
+ window.location.assign(verifyResponse.redirectTo);
215
+ }
216
+
217
+ async function createManagedWallet() {
218
+ setStatus("info", "Creating managed wallet...");
219
+ const response = await requestJson("/oauth/authorize/create-wallet", {});
220
+ pendingRedirect = response.redirectTo;
221
+ createdWalletAddressEl.textContent = response.walletAddress;
222
+ createdPrivateKeyEl.textContent = response.privateKey;
223
+ createPanel.classList.add("visible");
224
+ savedPrivateKeyCheckbox.checked = false;
225
+ completeCreateWalletButton.disabled = true;
226
+ setStatus("success", "Managed wallet created. Save the private key before continuing.");
227
+ }
228
+
229
+ connectExistingButton.addEventListener("click", () => {
230
+ connectExistingManagedWallet().catch((error) => {
231
+ setStatus("error", error instanceof Error ? error.message : String(error));
232
+ });
233
+ });
234
+
235
+ createWalletButton.addEventListener("click", () => {
236
+ createManagedWallet().catch((error) => {
237
+ setStatus("error", error instanceof Error ? error.message : String(error));
238
+ });
239
+ });
240
+
241
+ savedPrivateKeyCheckbox.addEventListener("change", () => {
242
+ completeCreateWalletButton.disabled = !savedPrivateKeyCheckbox.checked || !pendingRedirect;
243
+ });
244
+
245
+ completeCreateWalletButton.addEventListener("click", () => {
246
+ if (pendingRedirect) {
247
+ setStatus("success", "Redirecting to MissionSquad...");
248
+ window.location.assign(pendingRedirect);
249
+ }
250
+ });
251
+ </script>
252
+ </body>
253
+ </html>`;
254
+ }
255
+ //# sourceMappingURL=page.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page.js","sourceRoot":"","sources":["../../src/oauth/page.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,qBAAqB;IACnC,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QA2PD,CAAC;AACT,CAAC"}
@@ -0,0 +1,65 @@
1
+ export interface PendingAuthorizationRequest {
2
+ authRequestId: string;
3
+ clientId: string;
4
+ redirectUri: string;
5
+ state: string;
6
+ scope: string[];
7
+ resource: string;
8
+ codeChallenge: string;
9
+ codeChallengeMethod: "S256";
10
+ issuedAt: number;
11
+ expiresAt: number;
12
+ }
13
+ export interface ChallengeRecord {
14
+ nonce: string;
15
+ authRequestId: string;
16
+ tenantId: string;
17
+ walletAddressBase58: string;
18
+ walletAddressHex: string;
19
+ challenge: string;
20
+ issuedAt: number;
21
+ expiresAt: number;
22
+ usedAt: number | null;
23
+ }
24
+ export interface AuthorizationCodeRecord {
25
+ code: string;
26
+ clientId: string;
27
+ redirectUri: string;
28
+ tenantId: string;
29
+ walletAddressBase58: string;
30
+ walletId: "primary";
31
+ scope: string[];
32
+ codeChallenge: string;
33
+ codeChallengeMethod: "S256";
34
+ issuedAt: number;
35
+ expiresAt: number;
36
+ usedAt: number | null;
37
+ }
38
+ export interface RefreshTokenRecord {
39
+ tokenHash: string;
40
+ tenantId: string;
41
+ walletAddressBase58: string;
42
+ walletId: "primary";
43
+ clientId: string;
44
+ scopes: string[];
45
+ sessionVersion: number;
46
+ createdAt: number;
47
+ expiresAt: number;
48
+ rotatedAt: number | null;
49
+ revokedAt: number | null;
50
+ replacedByTokenHash: string | null;
51
+ }
52
+ export interface OAuthAccessTokenPayload {
53
+ sub: string;
54
+ tenantId: string;
55
+ walletId: "primary";
56
+ walletAddress: string;
57
+ clientId: string;
58
+ scope: string;
59
+ sessionVersion: number;
60
+ iss: string;
61
+ aud: string;
62
+ iat: number;
63
+ exp: number;
64
+ jti: string;
65
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/oauth/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import express from "express";
2
+ export type HttpAppContext = {
3
+ app: express.Express;
4
+ shutdown: () => Promise<void>;
5
+ getActiveSessionCount: () => number;
6
+ };
7
+ export declare function createHttpApp(options?: {
8
+ readOnly?: boolean;
9
+ }): HttpAppContext;
@@ -0,0 +1,128 @@
1
+ import { join } from "node:path";
2
+ import express from "express";
3
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
4
+ import { optionalOAuthTenantAuth } from "../middleware/auth.js";
5
+ import { OAuthService } from "../oauth/OAuthService.js";
6
+ import { runWithRequestContext } from "../tenant/context.js";
7
+ import { TenantManager } from "../tenant/TenantManager.js";
8
+ import { registerOAuthRoutes } from "./oauth-routes.js";
9
+ import startServer, { MCP_PROTOCOL_VERSION, version } from "./server.js";
10
+ export function createHttpApp(options = {}) {
11
+ const publicOrigin = process.env.MCP_PUBLIC_ORIGIN?.trim();
12
+ const jwtSecret = process.env.JWT_SECRET?.trim();
13
+ const tenantMasterSecret = process.env.MCP_TENANT_MASTER_SECRET?.trim();
14
+ if (!publicOrigin) {
15
+ throw new Error("MCP_PUBLIC_ORIGIN is required in HTTP mode.");
16
+ }
17
+ if (!jwtSecret) {
18
+ throw new Error("JWT_SECRET is required in HTTP mode.");
19
+ }
20
+ if (!tenantMasterSecret) {
21
+ throw new Error("MCP_TENANT_MASTER_SECRET is required in HTTP mode.");
22
+ }
23
+ const dataDir = process.env.MCP_DATA_DIR?.trim() || join(process.cwd(), "data");
24
+ const tenantManager = new TenantManager({
25
+ dataDir,
26
+ tenantMasterSecret,
27
+ });
28
+ const oauthService = new OAuthService({
29
+ publicOrigin,
30
+ jwtSecret,
31
+ dataDir,
32
+ authChallengeTtlSeconds: parsePositiveInt(process.env.MCP_AUTH_CHALLENGE_TTL_SECONDS) ?? 300,
33
+ oauthAuthCodeTtlSeconds: parsePositiveInt(process.env.MCP_OAUTH_AUTH_CODE_TTL_SECONDS) ?? 300,
34
+ oauthAccessTokenTtlSeconds: parsePositiveInt(process.env.MCP_OAUTH_ACCESS_TOKEN_TTL_SECONDS) ?? 3600,
35
+ oauthRefreshTokenTtlSeconds: parsePositiveInt(process.env.MCP_OAUTH_REFRESH_TOKEN_TTL_SECONDS) ?? 2_592_000,
36
+ clientMetadataTimeoutMs: parsePositiveInt(process.env.MCP_OAUTH_CLIENT_METADATA_TIMEOUT_MS) ?? 10_000,
37
+ });
38
+ const app = express();
39
+ app.use(express.json({ limit: "10mb" }));
40
+ app.use(express.urlencoded({ extended: false }));
41
+ registerOAuthRoutes(app, { oauthService, tenantManager });
42
+ app.use(optionalOAuthTenantAuth({
43
+ tenantManager,
44
+ jwtSecret,
45
+ issuer: oauthService.publicOrigin,
46
+ audience: oauthService.resourceUri,
47
+ }));
48
+ app.post("/mcp", async (req, res) => {
49
+ console.log(`Received POST /mcp request from ${req.ip}`);
50
+ let server;
51
+ const transport = new StreamableHTTPServerTransport({
52
+ sessionIdGenerator: undefined,
53
+ });
54
+ try {
55
+ await runWithRequestContext({
56
+ transport: "http",
57
+ tenantManager,
58
+ auth: req.tenantAuth ?? null,
59
+ }, async () => {
60
+ server = await startServer({ readOnly: options.readOnly, transport: "http" });
61
+ await server.connect(transport);
62
+ await transport.handleRequest(req, res, req.body);
63
+ });
64
+ }
65
+ catch (error) {
66
+ console.error(`Error handling request: ${error}`);
67
+ if (!res.headersSent) {
68
+ res.status(500).json({ error: "Internal server error" });
69
+ }
70
+ }
71
+ finally {
72
+ if (server) {
73
+ await server.close().catch((closeError) => {
74
+ console.error(`Error closing stateless server: ${closeError}`);
75
+ });
76
+ }
77
+ }
78
+ });
79
+ app.get("/mcp", async (_req, res) => {
80
+ res.setHeader("Allow", "POST");
81
+ res.status(405).json({ error: "GET not supported for stateless Streamable HTTP" });
82
+ });
83
+ app.delete("/mcp", async (_req, res) => {
84
+ res.setHeader("Allow", "POST");
85
+ res.status(405).json({ error: "DELETE not supported for stateless Streamable HTTP" });
86
+ });
87
+ app.get("/health", (_req, res) => {
88
+ res.status(200).json({
89
+ status: "ok",
90
+ server: "ready",
91
+ mode: "stateless",
92
+ activeSessions: 0,
93
+ });
94
+ });
95
+ app.get("/", (_req, res) => {
96
+ res.status(200).json({
97
+ name: "mcp-server-tron",
98
+ version,
99
+ protocol: `MCP ${MCP_PROTOCOL_VERSION}`,
100
+ transport: "Streamable HTTP",
101
+ mode: "stateless",
102
+ endpoints: {
103
+ mcp: "/mcp",
104
+ health: "/health",
105
+ authorize: "/oauth/authorize",
106
+ token: "/oauth/token",
107
+ },
108
+ status: "ready",
109
+ activeSessions: 0,
110
+ });
111
+ });
112
+ return {
113
+ app,
114
+ shutdown: async () => { },
115
+ getActiveSessionCount: () => 0,
116
+ };
117
+ }
118
+ function parsePositiveInt(value) {
119
+ if (!value) {
120
+ return undefined;
121
+ }
122
+ const parsed = Number.parseInt(value, 10);
123
+ if (!Number.isFinite(parsed) || parsed <= 0) {
124
+ return undefined;
125
+ }
126
+ return parsed;
127
+ }
128
+ //# sourceMappingURL=http-app.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-app.js","sourceRoot":"","sources":["../../src/server/http-app.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,OAA8B,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,WAAW,EAAE,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAQzE,MAAM,UAAU,aAAa,CAAC,UAAkC,EAAE;IAChE,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,IAAI,EAAE,CAAC;IAC3D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC;IACjD,MAAM,kBAAkB,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAwB,EAAE,IAAI,EAAE,CAAC;IAExE,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CAAC,6CAA6C,CAAC,CAAC;IACjE,CAAC;IACD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,CAAC,kBAAkB,E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gBACX,MAAM,EAAE,SAAS;gBACjB,SAAS,EAAE,kBAAkB;gBAC7B,KAAK,EAAE,cAAc;aACtB;YACD,MAAM,EAAE,OAAO;YACf,cAAc,EAAE,CAAC;SAClB,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,GAAG;QACH,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAE,CAAC;QACxB,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;KAC/B,CAAC;AACJ,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAyB;IACjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1C,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;QAC5C,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import { createHttpApp } from "./http-app.js";
2
+ import { MCP_PROTOCOL_VERSION } from "./server.js";
3
+ // Environment variables
4
+ const PORT = parseInt(process.env.MCP_PORT || "3001", 10);
5
+ const HOST = process.env.MCP_HOST || "0.0.0.0";
6
+ console.log(`Configured to listen on ${HOST}:${PORT}`);
7
+ const isReadOnly = process.argv.includes("--readonly") || process.argv.includes("-r");
8
+ const { app, shutdown } = createHttpApp({ readOnly: isReadOnly });
9
+ // Handle process termination gracefully
10
+ process.on("SIGINT", async () => {
11
+ console.log("Shutting down server...");
12
+ await shutdown();
13
+ process.exit(0);
14
+ });
15
+ process.on("SIGTERM", async () => {
16
+ console.log("Received SIGTERM, shutting down...");
17
+ await shutdown();
18
+ process.exit(0);
19
+ });
20
+ // Start the HTTP server
21
+ const httpServer = app
22
+ .listen(PORT, HOST, () => {
23
+ console.log(`mcp-server-tron running at http://${HOST}:${PORT}`);
24
+ console.log(`MCP endpoint: http://${HOST}:${PORT}/mcp`);
25
+ console.log(`Health check: http://${HOST}:${PORT}/health`);
26
+ console.log(`Protocol: MCP ${MCP_PROTOCOL_VERSION} (Streamable HTTP)`);
27
+ })
28
+ .on("error", (err) => {
29
+ console.error(`Server error: ${err}`);
30
+ process.exit(1);
31
+ });
32
+ // Set server timeout to prevent hanging connections
33
+ httpServer.timeout = 120000; // 2 minutes
34
+ httpServer.keepAliveTimeout = 65000; // 65 seconds
35
+ //# sourceMappingURL=http-server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-server.js","sourceRoot":"","sources":["../../src/server/http-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,wBAAwB;AACxB,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,MAAM,EAAE,EAAE,CAAC,CAAC;AAC1D,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,IAAI,SAAS,CAAC;AAE/C,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;AAEvD,MAAM,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACtF,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,CAAC,CAAC;AAElE,wCAAwC;AACxC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,KAAK,IAAI,EAAE;IAC9B,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;IACvC,MAAM,QAAQ,EAAE,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;IAC/B,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;IAClD,MAAM,QAAQ,EAAE,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEH,wBAAwB;AACxB,MAAM,UAAU,GAAG,GAAG;KACnB,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE;IACvB,OAAO,CAAC,GAAG,CAAC,qCAAqC,IAAI,IAAI,IAAI,EAAE,CAAC,CAAC;IACjE,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC;IACxD,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,IAAI,IAAI,SAAS,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,iBAAiB,oBAAoB,oBAAoB,CAAC,CAAC;AACzE,CAAC,CAAC;KACD,EAAE,CAAC,OAAO,EAAE,CAAC,GAAU,EAAE,EAAE;IAC1B,OAAO,CAAC,KAAK,CAAC,iBAAiB,GAAG,EAAE,CAAC,CAAC;IACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC;AAEL,oDAAoD;AACpD,UAAU,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,YAAY;AACzC,UAAU,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAC,aAAa"}
@@ -0,0 +1,7 @@
1
+ import type { Express } from "express";
2
+ import type { OAuthService } from "../oauth/OAuthService.js";
3
+ import type { TenantManager } from "../tenant/TenantManager.js";
4
+ export declare function registerOAuthRoutes(app: Express, params: {
5
+ oauthService: OAuthService;
6
+ tenantManager: TenantManager;
7
+ }): void;