feat: Auto-connect WebMCP without agent intervention
- Add requestToken() and autoConnect() functions to request tokens directly from WebMCP server - Add /api/webmcp-request-token endpoint to proxy token requests (for HTTPS/Traefik) - Add webmcpHttp endpoint configuration for direct WebMCP HTTP API access - Update App.vue to auto-connect on load with polling fallback - Add kill-ports script to clear ports 4101, 4102, 4103, 4105 before starting
This commit is contained in:
@@ -1,8 +1,41 @@
|
||||
import { jsonResponse, errorResponse } from '../utils/cors'
|
||||
|
||||
// WebMCP server URL (localhost since they run on same machine)
|
||||
const WEBMCP_URL = 'http://localhost:4102'
|
||||
|
||||
// WebMCP token storage (in-memory)
|
||||
let pendingWebMCPToken: { token: string; createdAt: Date } | null = null
|
||||
|
||||
// Request token directly from WebMCP server
|
||||
export async function handleWebMCPRequestToken(req: Request) {
|
||||
if (req.method !== 'POST') {
|
||||
return errorResponse('Method not allowed', 405)
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(`${WEBMCP_URL}/token`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
})
|
||||
|
||||
if (!res.ok) {
|
||||
console.error('[WebMCP] Failed to request token from server:', res.status)
|
||||
return errorResponse('Failed to request token', res.status)
|
||||
}
|
||||
|
||||
const data = await res.json()
|
||||
if (data.success && data.token) {
|
||||
console.log('[WebMCP] Token obtained from server')
|
||||
return jsonResponse({ success: true, token: data.token })
|
||||
}
|
||||
|
||||
return errorResponse('Invalid response from WebMCP', 500)
|
||||
} catch (e) {
|
||||
console.error('[WebMCP] Error requesting token:', e)
|
||||
return errorResponse('WebMCP server not available', 503)
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleWebMCPToken(req: Request) {
|
||||
if (req.method === 'GET') {
|
||||
if (pendingWebMCPToken) {
|
||||
|
||||
Reference in New Issue
Block a user