@relayrail/server 0.1.2 → 0.1.4
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/cli.js +1959 -0
- package/dist/index.d.ts +58 -2
- package/dist/index.js +83 -53
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ interface ServerConfig {
|
|
|
22
22
|
telnyxPhoneNumber?: string;
|
|
23
23
|
/** Base URL for response pages */
|
|
24
24
|
baseUrl: string;
|
|
25
|
+
/** API key for proxy mode (when email/SMS credentials unavailable locally) */
|
|
26
|
+
apiKey?: string;
|
|
25
27
|
}
|
|
26
28
|
/**
|
|
27
29
|
* Context passed to tool handlers
|
|
@@ -379,11 +381,19 @@ interface RouteResult {
|
|
|
379
381
|
/** Quota error if send was blocked */
|
|
380
382
|
quotaError?: QuotaError;
|
|
381
383
|
}
|
|
384
|
+
/**
|
|
385
|
+
* Common interface for message routing
|
|
386
|
+
* Implemented by both RequestRouter (direct sending) and ProxyRouter (API proxy)
|
|
387
|
+
*/
|
|
388
|
+
interface MessageRouter {
|
|
389
|
+
routeApproval(params: RouteApprovalParams, user: User, agent: Agent): Promise<RouteResult>;
|
|
390
|
+
routeNotification(params: RouteNotificationParams, user: User, agent: Agent): Promise<RouteResult>;
|
|
391
|
+
}
|
|
382
392
|
/**
|
|
383
393
|
* Request router that sends requests via the appropriate channel
|
|
384
394
|
* with quota enforcement and overage billing
|
|
385
395
|
*/
|
|
386
|
-
declare class RequestRouter {
|
|
396
|
+
declare class RequestRouter implements MessageRouter {
|
|
387
397
|
private emailService;
|
|
388
398
|
private smsService?;
|
|
389
399
|
private usageService;
|
|
@@ -412,6 +422,10 @@ declare class RequestRouter {
|
|
|
412
422
|
*/
|
|
413
423
|
private createQuotaErrorResult;
|
|
414
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Create a request router instance
|
|
427
|
+
*/
|
|
428
|
+
declare function createRouter(config: RouterConfig, supabase: TypedSupabaseClient): RequestRouter;
|
|
415
429
|
|
|
416
430
|
/**
|
|
417
431
|
* HTTP Transport for MCP Server
|
|
@@ -504,4 +518,46 @@ declare class HTTPTransport {
|
|
|
504
518
|
*/
|
|
505
519
|
declare function createHTTPTransport(config: HTTPTransportConfig): HTTPTransport;
|
|
506
520
|
|
|
507
|
-
|
|
521
|
+
/**
|
|
522
|
+
* Proxy Router
|
|
523
|
+
* Routes requests to the hosted RelayRail API for message sending
|
|
524
|
+
* Used when local email/SMS credentials are not available
|
|
525
|
+
*/
|
|
526
|
+
|
|
527
|
+
interface ProxyRouterConfig {
|
|
528
|
+
apiUrl: string;
|
|
529
|
+
apiKey: string;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Proxy router that sends messages via the RelayRail API
|
|
533
|
+
* Implements the same interface as RequestRouter for drop-in replacement
|
|
534
|
+
*/
|
|
535
|
+
declare class ProxyRouter implements MessageRouter {
|
|
536
|
+
private apiUrl;
|
|
537
|
+
private apiKey;
|
|
538
|
+
constructor(config: ProxyRouterConfig);
|
|
539
|
+
/**
|
|
540
|
+
* Route an approval request via the API
|
|
541
|
+
* @param params - Approval parameters
|
|
542
|
+
* @param _user - User (unused, API handles lookup)
|
|
543
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
544
|
+
*/
|
|
545
|
+
routeApproval(params: RouteApprovalParams, _user: User, _agent: Agent): Promise<RouteResult>;
|
|
546
|
+
/**
|
|
547
|
+
* Route a notification via the API
|
|
548
|
+
* @param params - Notification parameters
|
|
549
|
+
* @param _user - User (unused, API handles lookup)
|
|
550
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
551
|
+
*/
|
|
552
|
+
routeNotification(params: RouteNotificationParams, _user: User, _agent: Agent): Promise<RouteResult>;
|
|
553
|
+
/**
|
|
554
|
+
* Send a message via the RelayRail API
|
|
555
|
+
*/
|
|
556
|
+
private sendViaApi;
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Create a proxy router instance
|
|
560
|
+
*/
|
|
561
|
+
declare function createProxyRouter(config: ProxyRouterConfig): ProxyRouter;
|
|
562
|
+
|
|
563
|
+
export { type ApprovalRequestParams, type ApprovalResponse, type AuthResult, type AwaitResponseParams, type AwaitResult, type GetPendingCommandsParams, HTTPTransport, type HTTPTransportConfig, type MCPNotification, type MCPRequest, type MCPResponse, MCP_ERRORS, type MessageRouter, type NotificationParams, type NotificationResponse, ProxyRouter, type ProxyRouterConfig, RelayRailServer, RequestRouter, type RouteApprovalParams, type RouteNotificationParams, type RouteResult, type RouterConfig, type ServerConfig, type ToolContext, type UserCommand, VERSION, authenticateApiKey, createHTTPTransport, createProxyRouter, createRouter, createServer, generateApiKey, getApiKeyPrefix, hashApiKey };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
1
|
// src/server.ts
|
|
4
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -1497,6 +1495,81 @@ function createRouter(config, supabase) {
|
|
|
1497
1495
|
return new RequestRouter(config, supabase);
|
|
1498
1496
|
}
|
|
1499
1497
|
|
|
1498
|
+
// src/services/proxy-router.ts
|
|
1499
|
+
var ProxyRouter = class {
|
|
1500
|
+
apiUrl;
|
|
1501
|
+
apiKey;
|
|
1502
|
+
constructor(config) {
|
|
1503
|
+
this.apiUrl = config.apiUrl.replace(/\/$/, "");
|
|
1504
|
+
this.apiKey = config.apiKey;
|
|
1505
|
+
}
|
|
1506
|
+
/**
|
|
1507
|
+
* Route an approval request via the API
|
|
1508
|
+
* @param params - Approval parameters
|
|
1509
|
+
* @param _user - User (unused, API handles lookup)
|
|
1510
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
1511
|
+
*/
|
|
1512
|
+
async routeApproval(params, _user, _agent) {
|
|
1513
|
+
return this.sendViaApi(params.requestId, "approval");
|
|
1514
|
+
}
|
|
1515
|
+
/**
|
|
1516
|
+
* Route a notification via the API
|
|
1517
|
+
* @param params - Notification parameters
|
|
1518
|
+
* @param _user - User (unused, API handles lookup)
|
|
1519
|
+
* @param _agent - Agent (unused, API handles lookup)
|
|
1520
|
+
*/
|
|
1521
|
+
async routeNotification(params, _user, _agent) {
|
|
1522
|
+
return this.sendViaApi(params.requestId, "notification");
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Send a message via the RelayRail API
|
|
1526
|
+
*/
|
|
1527
|
+
async sendViaApi(requestId, type) {
|
|
1528
|
+
try {
|
|
1529
|
+
const response = await fetch(`${this.apiUrl}/api/send-message`, {
|
|
1530
|
+
method: "POST",
|
|
1531
|
+
headers: {
|
|
1532
|
+
"Content-Type": "application/json",
|
|
1533
|
+
"Authorization": `Bearer ${this.apiKey}`
|
|
1534
|
+
},
|
|
1535
|
+
body: JSON.stringify({
|
|
1536
|
+
request_id: requestId,
|
|
1537
|
+
type
|
|
1538
|
+
})
|
|
1539
|
+
});
|
|
1540
|
+
const data = await response.json();
|
|
1541
|
+
if (!response.ok) {
|
|
1542
|
+
console.error(`[ProxyRouter] API error:`, data);
|
|
1543
|
+
return {
|
|
1544
|
+
success: false,
|
|
1545
|
+
channel: "email",
|
|
1546
|
+
error: data.error || `API error: ${response.status}`
|
|
1547
|
+
};
|
|
1548
|
+
}
|
|
1549
|
+
return {
|
|
1550
|
+
success: data.success,
|
|
1551
|
+
channel: data.channel || "email",
|
|
1552
|
+
channel_requested: data.channel_requested,
|
|
1553
|
+
fallback_reason: data.fallback_reason,
|
|
1554
|
+
messageId: data.message_id,
|
|
1555
|
+
error: data.error,
|
|
1556
|
+
quota: data.quota,
|
|
1557
|
+
quotaError: data.quota_error
|
|
1558
|
+
};
|
|
1559
|
+
} catch (error) {
|
|
1560
|
+
console.error(`[ProxyRouter] Network error:`, error);
|
|
1561
|
+
return {
|
|
1562
|
+
success: false,
|
|
1563
|
+
channel: "email",
|
|
1564
|
+
error: error instanceof Error ? error.message : "Network error"
|
|
1565
|
+
};
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
};
|
|
1569
|
+
function createProxyRouter(config) {
|
|
1570
|
+
return new ProxyRouter(config);
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1500
1573
|
// src/server.ts
|
|
1501
1574
|
var VERSION = "0.1.0";
|
|
1502
1575
|
var RelayRailServer = class {
|
|
@@ -1529,6 +1602,12 @@ var RelayRailServer = class {
|
|
|
1529
1602
|
},
|
|
1530
1603
|
this.supabase
|
|
1531
1604
|
);
|
|
1605
|
+
} else if (config.apiKey) {
|
|
1606
|
+
console.log("[RelayRail] Using proxy router for message delivery");
|
|
1607
|
+
this.router = createProxyRouter({
|
|
1608
|
+
apiUrl: config.baseUrl,
|
|
1609
|
+
apiKey: config.apiKey
|
|
1610
|
+
});
|
|
1532
1611
|
}
|
|
1533
1612
|
this.server = new McpServer({
|
|
1534
1613
|
name: "relayrail",
|
|
@@ -2199,57 +2278,6 @@ var HTTPTransport = class {
|
|
|
2199
2278
|
function createHTTPTransport(config) {
|
|
2200
2279
|
return new HTTPTransport(config);
|
|
2201
2280
|
}
|
|
2202
|
-
|
|
2203
|
-
// src/index.ts
|
|
2204
|
-
async function main() {
|
|
2205
|
-
const apiKey = process.env.RELAYRAIL_API_KEY;
|
|
2206
|
-
if (!apiKey) {
|
|
2207
|
-
console.error("Error: RELAYRAIL_API_KEY environment variable is required");
|
|
2208
|
-
console.error("");
|
|
2209
|
-
console.error("Get your API key from https://relayrail.dev/dashboard/agents");
|
|
2210
|
-
console.error("");
|
|
2211
|
-
console.error("Example MCP configuration:");
|
|
2212
|
-
console.error(JSON.stringify({
|
|
2213
|
-
mcpServers: {
|
|
2214
|
-
relayrail: {
|
|
2215
|
-
command: "npx",
|
|
2216
|
-
args: ["@relayrail/server"],
|
|
2217
|
-
env: {
|
|
2218
|
-
RELAYRAIL_API_KEY: "rr_your_api_key_here"
|
|
2219
|
-
}
|
|
2220
|
-
}
|
|
2221
|
-
}
|
|
2222
|
-
}, null, 2));
|
|
2223
|
-
process.exit(1);
|
|
2224
|
-
}
|
|
2225
|
-
const config = {
|
|
2226
|
-
supabaseUrl: process.env.SUPABASE_URL || process.env.NEXT_PUBLIC_SUPABASE_URL || "https://lcmdokppykqmigqcwnol.supabase.co",
|
|
2227
|
-
supabaseServiceRoleKey: process.env.SUPABASE_SERVICE_ROLE_KEY || "sb_secret_cj-1Y1KxjlapuwyXvfSKLA_xBJ0oS8i",
|
|
2228
|
-
baseUrl: process.env.RELAYRAIL_BASE_URL || "https://relayrail.dev",
|
|
2229
|
-
resendApiKey: process.env.RESEND_API_KEY,
|
|
2230
|
-
telnyxApiKey: process.env.TELNYX_API_KEY,
|
|
2231
|
-
telnyxPhoneNumber: process.env.TELNYX_PHONE_NUMBER
|
|
2232
|
-
};
|
|
2233
|
-
try {
|
|
2234
|
-
const server = createServer(config);
|
|
2235
|
-
const authenticated = await server.authenticate(apiKey);
|
|
2236
|
-
if (!authenticated) {
|
|
2237
|
-
console.error("Error: Invalid API key");
|
|
2238
|
-
console.error("");
|
|
2239
|
-
console.error("Please check your RELAYRAIL_API_KEY and try again.");
|
|
2240
|
-
console.error("Get a new API key from https://relayrail.dev/dashboard/agents");
|
|
2241
|
-
process.exit(1);
|
|
2242
|
-
}
|
|
2243
|
-
await server.start();
|
|
2244
|
-
} catch (error) {
|
|
2245
|
-
console.error("Failed to start RelayRail MCP server:", error);
|
|
2246
|
-
process.exit(1);
|
|
2247
|
-
}
|
|
2248
|
-
}
|
|
2249
|
-
main().catch((error) => {
|
|
2250
|
-
console.error("Unexpected error:", error);
|
|
2251
|
-
process.exit(1);
|
|
2252
|
-
});
|
|
2253
2281
|
export {
|
|
2254
2282
|
HTTPTransport,
|
|
2255
2283
|
MCP_ERRORS,
|
|
@@ -2257,6 +2285,8 @@ export {
|
|
|
2257
2285
|
VERSION,
|
|
2258
2286
|
authenticateApiKey,
|
|
2259
2287
|
createHTTPTransport,
|
|
2288
|
+
createProxyRouter,
|
|
2289
|
+
createRouter,
|
|
2260
2290
|
createServer,
|
|
2261
2291
|
generateApiKey,
|
|
2262
2292
|
getApiKeyPrefix,
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@relayrail/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "RelayRail MCP Server - SMS/Email connectivity for AI agents",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
8
|
"bin": {
|
|
9
|
-
"relayrail": "./dist/
|
|
10
|
-
"relayrail-server": "./dist/
|
|
9
|
+
"relayrail": "./dist/cli.js",
|
|
10
|
+
"relayrail-server": "./dist/cli.js"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|