Skip to content
Open
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
59 changes: 25 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
"@agent-relay/utils": "3.2.18",
"@modelcontextprotocol/sdk": "^1.0.0",
"@relaycast/mcp": "1.0.0",
"@relaycast/sdk": "1.0.0",
"@relaycast/sdk": "1.1.0",
"@sinclair/typebox": "^0.34.14",
"chalk": "^4.1.2",
"chokidar": "^5.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/openclaw/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"postinstall": "node -e \"try{require('child_process').execSync('ldd --version 2>&1',{stdio:'pipe'})}catch{try{require('child_process').execSync('apk info gcompat 2>/dev/null',{stdio:'pipe'})}catch{console.warn('\\n\\u26a0\\ufe0f @agent-relay/openclaw: Alpine detected without gcompat. Spawning requires glibc.\\n Install with: apk add gcompat libstdc++\\n')}}\""
},
"dependencies": {
"@agent-relay/sdk": "3.2.18",
"@relaycast/sdk": "^1.0.0",
"@agent-relay/sdk": "^3.2.18",
"@relaycast/sdk": "^1.1.0",
"ws": "^8.0.0"
},
"optionalDependencies": {
Expand Down
47 changes: 7 additions & 40 deletions packages/openclaw/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,54 +203,21 @@ export async function setup(options: SetupOptions): Promise<SetupResult> {
let apiKey = options.apiKey;

if (!apiKey) {
try {
const res = await fetch(`${baseUrl}/v1/workspaces`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: `${clawName}-workspace` }),
});
const workspaceName = `${clawName}-workspace`;

if (res.status === 409) {
// Workspace already exists — look up its API key
const lookupRes = await fetch(`${baseUrl}/v1/workspaces/by-name/${encodeURIComponent(`${clawName}-workspace`)}`, {
headers: { 'Content-Type': 'application/json' },
});
if (lookupRes.ok) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const lookupBody = (await lookupRes.json()) as any;
apiKey = lookupBody.apiKey ?? lookupBody.api_key ?? lookupBody.data?.apiKey ?? lookupBody.data?.api_key;
}
if (!apiKey) {
return {
ok: false,
apiKey: '',
clawName,
skillDir: '',
message: `Workspace "${clawName}-workspace" already exists. Pass the workspace key: @agent-relay/openclaw setup <key> --name ${clawName}`,
};
}
} else if (!res.ok) {
const body = await res.text();
return {
ok: false,
apiKey: '',
clawName,
skillDir: '',
message: `Failed to create workspace: ${res.status} ${body}`,
};
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const successBody = (await res.json()) as any;
apiKey = successBody.apiKey ?? successBody.api_key ?? successBody.data?.apiKey ?? successBody.data?.api_key;
}
try {
const workspace = await RelayCast.ensureWorkspace(workspaceName, baseUrl);
apiKey = workspace.apiKey;

if (!apiKey) {
return {
ok: false,
apiKey: '',
clawName,
skillDir: '',
message: 'Workspace created but no API key returned.',
message: workspace.existed
? `Workspace "${workspaceName}" already exists. Pass the workspace key: @agent-relay/openclaw setup <key> --name ${clawName}`
: 'Workspace created but no API key returned.',
};
}
} catch (err) {
Expand Down
30 changes: 14 additions & 16 deletions src/cli/relaycast-mcp.startup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ async function loadRelaycastMcpModule(options: LoadOptions = {}) {
}
}

const createWorkspace = vi.fn(async (name: string) => ({
apiKey: 'rk_live_created',
workspaceName: name,
}));

const createInternalRelayCast = vi.fn((config: Record<string, unknown>, origin: Record<string, unknown>) => {
const inbox = vi.fn(async (token?: string) => behavior.inboxImpl(String(token ?? '')));
const registerOrRotate = vi.fn(async (input: { name: string; type?: string }) => behavior.registerImpl(input));
Expand Down Expand Up @@ -160,6 +165,11 @@ async function loadRelaycastMcpModule(options: LoadOptions = {}) {
vi.doMock('@modelcontextprotocol/sdk/server/mcp.js', () => ({ McpServer: FakeMcpServer }));
vi.doMock('@modelcontextprotocol/sdk/server/stdio.js', () => ({ StdioServerTransport: FakeTransport }));
vi.doMock('@modelcontextprotocol/sdk/types.js', () => ({ ListToolsRequestSchema: { type: 'tools/list' } }));
vi.doMock('@relaycast/sdk', () => ({
RelayCast: {
createWorkspace,
},
}));
vi.doMock('@relaycast/sdk/internal', () => ({ createInternalRelayCast, createInternalWsClient }));
vi.doMock('@relaycast/mcp', () => ({ MCP_VERSION: 'test-mcp-version' }));
vi.doMock('@relaycast/mcp/dist/piggyback.js', () => ({ enablePiggyback }));
Expand Down Expand Up @@ -189,6 +199,7 @@ async function loadRelaycastMcpModule(options: LoadOptions = {}) {
channelToolGetters,
resourceGetters,
telemetry,
createWorkspace,
createInternalRelayCast,
createInternalWsClient,
enablePiggyback,
Expand Down Expand Up @@ -239,16 +250,6 @@ describe('relaycast-mcp startup helpers', () => {
describe('createPatchedRelayMcpServer', () => {
it('registers startup tools, prompt text, and strips execution metadata from tools/list', async () => {
const { mod, mocks } = await loadRelaycastMcpModule();
vi.stubGlobal(
'fetch',
vi.fn(async () => ({
json: async () => ({
ok: true,
data: { api_key: 'rk_live_created', workspace_name: 'Test Workspace' },
}),
}))
);

mod.createPatchedRelayMcpServer({ baseUrl: 'https://api.relaycast.dev/' });
const server = mocks.serverInstances[0];
const registerTool = server.tools.get('register');
Expand All @@ -275,13 +276,10 @@ describe('createPatchedRelayMcpServer', () => {
);

const workspaceResult = await createWorkspaceTool?.handler({ name: 'Coverage Workspace' });
expect(fetch).toHaveBeenCalledWith(
'https://api.relaycast.dev/v1/workspaces',
expect.objectContaining({ method: 'POST' })
);
expect(mocks.createWorkspace).toHaveBeenCalledWith('Coverage Workspace', 'https://api.relaycast.dev');
expect(workspaceResult.structuredContent).toEqual({
api_key: 'rk_live_created',
workspace_name: 'Test Workspace',
apiKey: 'rk_live_created',
workspaceName: 'Coverage Workspace',
});

const registerResult = await registerTool?.handler({
Expand Down
21 changes: 2 additions & 19 deletions src/cli/relaycast-mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { fileURLToPath } from 'node:url';
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import { RelayCast } from '@relaycast/sdk';
import { createInternalRelayCast, createInternalWsClient } from '@relaycast/sdk/internal';
import { MCP_VERSION } from '@relaycast/mcp';
import { enablePiggyback } from '@relaycast/mcp/dist/piggyback.js';
Expand Down Expand Up @@ -115,25 +116,7 @@ export function normalizeAgentType(value: string | undefined): AgentType | undef
}

async function createWorkspace(name: string, baseUrl?: string): Promise<Record<string, unknown>> {
const response = await fetch(`${normalizeBaseUrl(baseUrl)}/v1/workspaces`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name }),
});
const payload = (await response.json()) as {
ok?: boolean;
data?: Record<string, unknown>;
error?: { message?: string };
} | null;

if (!payload || typeof payload !== 'object' || typeof payload.ok !== 'boolean') {
throw new Error('Invalid response while creating workspace');
}
if (!payload.ok) {
throw new Error(payload.error?.message ?? 'Failed to create workspace');
}

return payload.data ?? {};
return await RelayCast.createWorkspace(name, normalizeBaseUrl(baseUrl));
}

function requireWorkspaceKey(session: RegistrationSession): void {
Expand Down
Loading