Spaces:
Running
Running
Download src/lib/commands.ts from evalstate/mcp-webcam: direct link, hf CLI and curl.
- Browser
- Download file 4.02 kB
-
https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/lib/commands.ts
- Command line
-
hf download hf://spaces/evalstate/mcp-webcam/src/lib/commands.ts
-
curl -L -o commands.ts https://huggingface.co/spaces/evalstate/mcp-webcam/resolve/main/src/lib/commands.ts
4.02 kB
| 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'), | |
| }, | |
| ]; | |
| } | |