Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 34 additions & 17 deletions packages/mcp/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,42 @@ export function createRelayMcpServer(options: McpServerOptions): McpServer {
session.wsBridge = null;
session.subscriptions = null;
}
if (shouldResetBridge) {
session.wsInitAttempted = false;
}

// When an agent token is set, initialize the WebSocket bridge.
if (nextAgentToken && !session.wsBridge) {
const subscriptions = new SubscriptionManager();
const wsClient = new WsClient({
token: nextAgentToken,
baseUrl: options.baseUrl,
});
const wsBridge = new WsBridge(
wsClient,
subscriptions,
(uri: string) => {
mcpServer.server.sendResourceUpdated({ uri }).catch(() => {
// Silently ignore notification failures
});
},
);
wsBridge.start();
Object.assign(session, partial, { wsBridge, subscriptions });
if (nextAgentToken && !session.wsBridge && !session.wsInitAttempted) {
try {
const subscriptions = new SubscriptionManager();
const wsClient = new WsClient({
token: nextAgentToken,
baseUrl: options.baseUrl,
});
const wsBridge = new WsBridge(
wsClient,
subscriptions,
(uri: string) => {
mcpServer.server.sendResourceUpdated({ uri }).catch(() => {
// Silently ignore notification failures
});
},
);
wsBridge.start();
Object.assign(session, partial, {
wsBridge,
subscriptions,
wsInitAttempted: true,
});
} catch {
// In non-WS runtimes (e.g. some test environments), keep session usable
// without real-time resource updates.
Object.assign(session, partial, {
wsBridge: null,
subscriptions: null,
wsInitAttempted: true,
});
}
telemetry.capture('relaycast_mcp_session_authenticated', {
source_surface: 'mcp',
agent_name: nextAgentName,
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Expand Down
10 changes: 9 additions & 1 deletion packages/mcp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ export interface SessionState {
agentName: string | null;
wsBridge: WsBridge | null;
subscriptions: SubscriptionManager | null;
wsInitAttempted: boolean;
}

export function createInitialSession(workspaceKey: string | null = null): SessionState {
return { workspaceKey, agentToken: null, agentName: null, wsBridge: null, subscriptions: null };
return {
workspaceKey,
agentToken: null,
agentName: null,
wsBridge: null,
subscriptions: null,
wsInitAttempted: false,
};
}
25 changes: 25 additions & 0 deletions smithery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
startCommand:
type: stdio
configSchema:
type: object
additionalProperties: false
properties:
relayApiKey:
type: string
description: Workspace API key (`rk_live_...`) used to pre-authenticate the MCP session.
relayBaseUrl:
type: string
description: Override API base URL for self-hosted Relaycast deployments.
default: https://api.relaycast.dev
commandFunction: |-
(config) => {
const env = {};
if (config.relayApiKey) env.RELAY_API_KEY = config.relayApiKey;
if (config.relayBaseUrl) env.RELAY_BASE_URL = config.relayBaseUrl;

return {
command: "npx",
args: ["-y", "tsx", "packages/mcp/src/stdio.ts"],
env
};
}
Loading