Skip to content

Every analytics tool wants a subscription. And your data. I built Twiligent instead. YouTube stats. Instagram stats. One dashboard. Runs locally on your machine.

feat(mcp): add the access api methods and the client approval type

spacesdrive6d5e79869acd
diff --git a/backend/validators/mcpValidators.ts b/backend/validators/mcpValidators.ts
index f1f9ebf..aeb00e8 100644
--- a/backend/validators/mcpValidators.ts
+++ b/backend/validators/mcpValidators.ts
@@ -1,7 +1,7 @@
import { ValidationError } from '../lib/errors.ts';
import { optionalNumber, requiredString } from './fields.ts';
import type { Fields } from './fields.ts';
-import type { McpAccessTokenCreateRequest, McpPermission } from '../../shared/types/mcp.ts';
+import type { McpAccessTokenCreateRequest, McpClientApprovalRequest, McpPermission } from '../../shared/types/mcp.ts';
const MAX_LABEL_LENGTH = 80;
// a year at most, so a forgotten token stops working on its own
@@ -22,16 +22,10 @@ export function parseAccessTokenCreate(body: Fields): McpAccessTokenCreateReques
return { label, permission: parsePermission(body.permission), expiresInDays };
}
-export interface ClientApprovalInput {
- clientId: string;
- clientName: string;
- permission: McpPermission;
-}
-
const MAX_CLIENT_NAME_LENGTH = 200;
// the consent page sends what Supabase Auth told it about the client; the approval only ever applies to the caller
-export function parseClientApproval(body: Fields): ClientApprovalInput {
+export function parseClientApproval(body: Fields): McpClientApprovalRequest {
const clientId = requiredString(body, 'clientId', 'clientId is required').trim();
if (clientId.length === 0 || clientId.length > 200) throw new ValidationError('clientId must be 1 to 200 characters');
const clientName = requiredString(body, 'clientName', 'clientName is required').trim().slice(0, MAX_CLIENT_NAME_LENGTH) || 'Claude';
diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts
index 9efbf87..8852a3f4 100644
--- a/frontend/src/services/api.ts
+++ b/frontend/src/services/api.ts
@@ -20,6 +20,10 @@ import type {
import type {
ResolveChannelResponse, YouTubeAnalyticsPayload, YouTubeComparisonResponse, YouTubeVideosResponse,
} from '@shared/types/youtube.ts';
+import type {
+ McpAccessTokenCreateRequest, McpAccessTokenCreateResponse, McpAccessTokenListResponse, McpClientApprovalRequest,
+ McpClientGrantListResponse, McpServerInfoResponse,
+} from '@shared/types/mcp.ts';
const API = import.meta.env.VITE_API_URL || 'http://localhost:8787/api';
@@ -184,4 +188,13 @@ export const api = {
getAutomationStats: (query: URLSearchParams) => request<AutomationStatsResponse>(`/automations/stats?${query}`),
setAutomationAccountPaused: (accountId: string, paused: boolean) => request<AutomationAccountResponse>(`/automations/accounts/${accountId}`, { method: 'PUT', body: JSON.stringify({ paused }) }),
subscribeAutomationAccount: (accountId: string) => request<AutomationAccountResponse>(`/automations/accounts/${accountId}/subscribe`, { method: 'POST' }),
+
+ // how Claude clients reach this account: the server address, personal access tokens and approved OAuth clients
+ getMcpInfo: () => request<McpServerInfoResponse>('/mcp/info'),
+ getMcpTokens: () => request<McpAccessTokenListResponse>('/mcp/tokens'),
+ createMcpToken: (data: McpAccessTokenCreateRequest) => request<McpAccessTokenCreateResponse>('/mcp/tokens', { method: 'POST', body: JSON.stringify(data) }),
+ revokeMcpToken: (id: string) => request<SuccessResponse>(`/mcp/tokens/${id}`, { method: 'DELETE' }),
+ getMcpClients: () => request<McpClientGrantListResponse>('/mcp/clients'),
+ approveMcpClient: (data: McpClientApprovalRequest) => request<SuccessResponse>('/mcp/clients', { method: 'POST', body: JSON.stringify(data) }),
+ revokeMcpClient: (id: string) => request<SuccessResponse>(`/mcp/clients/${id}`, { method: 'DELETE' }),
};
diff --git a/shared/types/mcp.ts b/shared/types/mcp.ts
index 887cd35..39674e7 100644
--- a/shared/types/mcp.ts
+++ b/shared/types/mcp.ts
@@ -43,6 +43,13 @@ export interface McpAccessTokenCreateResponse {
summary: McpAccessTokenSummary;
}
+// body of POST /api/mcp/clients, sent by the consent page before it approves the client with Supabase Auth
+export interface McpClientApprovalRequest {
+ clientId: string;
+ clientName: string;
+ permission: McpPermission;
+}
+
// GET /api/mcp/clients
export interface McpClientGrantListResponse {
success: true;