Spaces:
Running

File size: 4,016 Bytes
6f5f15e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12bb291
6f5f15e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
export interface ConnectSnippet {
  id: 'fast-agent' | 'uvx' | 'mcp-connect' | 'config-yaml' | 'claude-code' | 'claude-desktop' | 'vscode' | 'curl';
  label: string;
  language: string;
  description: string;
  code: string;
}

/**
 * Construct the MCP endpoint URL, appending `?user=<id>` when `user` is not `'default'`.
 */
export function buildMcpUrl(opts: {
  mcpHost?: string;
  origin?: string;
  mcpPath?: string;
  user?: string;
}): string {
  const base = (opts.mcpHost || opts.origin || 'http://localhost:3334').replace(/\/+$/, '');
  const path = opts.mcpPath || '/mcp';
  const normalizedPath = path.startsWith('/') ? path : `/${path}`;
  const url = `${base}${normalizedPath}`;
  const user = opts.user?.trim();
  if (user && user !== 'default') {
    return `${url}?user=${encodeURIComponent(user)}`;
  }
  return url;
}

/**
 * Build all tabbed connection snippets for the ConnectPanel.
 */
export function buildConnectSnippets(mcpUrl: string): ConnectSnippet[] {
  const discoverBody = JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'server/discover',
    params: {
      _meta: {
        'io.modelcontextprotocol/protocolVersion': '2026-07-28',
        'io.modelcontextprotocol/clientInfo': { name: 'curl', version: '1.0' },
        'io.modelcontextprotocol/clientCapabilities': {},
      },
    },
  });

  return [
    {
      id: 'uvx',
      label: 'fast-agent (uvx)',
      language: 'bash',
      description: 'Run fast-agent directly against this MCP endpoint with modern 2026-07-28 events.',
      code: `uvx fast-agent-mcp@latest go --url ${mcpUrl}`,
    },
    {
      id: 'mcp-connect',
      label: '/mcp connect',
      language: 'text',
      description: 'Inside an active fast-agent session, connect and subscribe to webcam events.',
      code: `/mcp connect ${mcpUrl} --name webcam\n/events subscribe webcam webcam.message`,
    },
    {
      id: 'config-yaml',
      label: 'fastagent.config.yaml',
      language: 'yaml',
      description: 'Declarative fast-agent config that wakes an idle agent when you press Fire.',
      code: [
        'mcp:',
        '  servers:',
        '    webcam:',
        `      url: ${mcpUrl}`,
        '      protocol_mode: modern     # events need 2026-07-28',
        '      events:',
        '        - name: webcam.message',
        '          wake: true            # wake the idle agent when you press Fire',
      ].join('\n'),
    },
    {
      id: 'claude-code',
      label: 'Claude Code (HTTP)',
      language: 'bash',
      description: 'Register this remote/local HTTP MCP endpoint in Claude Code.',
      code: `claude mcp add --transport http webcam ${mcpUrl}`,
    },
    {
      id: 'claude-desktop',
      label: 'Claude Desktop (stdio)',
      language: 'json',
      description: 'Add to claude_desktop_config.json to run mcp-webcam locally over stdio.',
      code: JSON.stringify(
        {
          mcpServers: {
            webcam: {
              command: 'npx',
              args: ['-y', '@llmindset/mcp-webcam'],
            },
          },
        },
        null,
        2,
      ),
    },
    {
      id: 'vscode',
      label: 'VS Code / Cursor',
      language: 'json',
      description: 'Add to .vscode/mcp.json or Cursor MCP settings for HTTP transport.',
      code: JSON.stringify(
        {
          servers: {
            webcam: {
              type: 'http',
              url: mcpUrl,
            },
          },
        },
        null,
        2,
      ),
    },
    {
      id: 'curl',
      label: 'curl (discover)',
      language: 'bash',
      description: 'Probe modern MCP capabilities and events extension with server/discover.',
      code: [
        `curl -sS -X POST '${mcpUrl}' \\`,
        "  -H 'Content-Type: application/json' \\",
        "  -H 'Accept: application/json, text/event-stream' \\",
        "  -H 'MCP-Protocol-Version: 2026-07-28' \\",
        "  -H 'Mcp-Method: server/discover' \\",
        `  -d '${discoverBody}'`,
      ].join('\n'),
    },
  ];
}