File size: 3,348 Bytes
4e7644b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { request } from "../request";
import type {
  MCPClientInfo,
  MCPClientCreateRequest,
  MCPClientUpdateRequest,
  MCPToolInfo,
  MCPAccessPrincipalOption,
  MCPAccessPolicy,
  MCPOAuthStartRequest,
  MCPOAuthStartResponse,
  MCPOAuthStatusResponse,
} from "../types";

export const mcpApi = {
  /**
   * List all MCP clients
   */
  listMCPClients: () => request<MCPClientInfo[]>("/mcp"),

  /**
   * Get details of a specific MCP client
   */
  getMCPClient: (clientKey: string) =>
    request<MCPClientInfo>(`/mcp/${encodeURIComponent(clientKey)}`),

  /**
   * Create a new MCP client
   */
  createMCPClient: (body: MCPClientCreateRequest) =>
    request<MCPClientInfo>("/mcp", {
      method: "POST",
      body: JSON.stringify(body),
    }),

  /**
   * Update an existing MCP client
   */
  updateMCPClient: (clientKey: string, body: MCPClientUpdateRequest) =>
    request<MCPClientInfo>(`/mcp/${encodeURIComponent(clientKey)}`, {
      method: "PUT",
      body: JSON.stringify(body),
    }),

  /**
   * Toggle MCP client enabled status
   */
  toggleMCPClient: (clientKey: string) =>
    request<MCPClientInfo>(`/mcp/toggle/${encodeURIComponent(clientKey)}`, {
      method: "PATCH",
    }),

  /**
   * Delete an MCP client
   */
  deleteMCPClient: (clientKey: string) =>
    request<{ message: string }>(`/mcp/${encodeURIComponent(clientKey)}`, {
      method: "DELETE",
    }),

  /**
   * List tools from a connected MCP server
   */
  listMCPTools: (clientKey: string) =>
    request<MCPToolInfo[]>(`/mcp/tools/${encodeURIComponent(clientKey)}`),

  /**
   * List recent source-scoped principals for MCP access rules.
   */
  listMCPAccessPrincipals: () =>
    request<MCPAccessPrincipalOption[]>("/mcp/access-principals"),

  /**
   * Get saved MCP access policy. Does not require the MCP server to be online.
   */
  getMCPPolicy: (clientKey: string) =>
    request<MCPAccessPolicy>(`/mcp/policy/${encodeURIComponent(clientKey)}`),

  /**
   * Update saved MCP access policy. Does not require the MCP server to be online.
   */
  updateMCPPolicy: (clientKey: string, body: MCPAccessPolicy) =>
    request<MCPAccessPolicy>(`/mcp/policy/${encodeURIComponent(clientKey)}`, {
      method: "PUT",
      body: JSON.stringify(body),
    }),

  /**
   * Update tool whitelist for an MCP client
   */
  updateMCPToolWhitelist: (clientKey: string, tools: string[] | null) =>
    request<MCPToolInfo[]>(`/mcp/tools/${encodeURIComponent(clientKey)}`, {
      method: "PUT",
      body: JSON.stringify({ tools }),
    }),

  /**
   * Start an OAuth 2.1 PKCE flow for a remote MCP client.
   * Returns the authorization URL to open in a popup.
   */
  startOAuth: (clientKey: string, body: MCPOAuthStartRequest) =>
    request<MCPOAuthStartResponse>(
      `/mcp/oauth/start/${encodeURIComponent(clientKey)}`,
      {
        method: "POST",
        body: JSON.stringify(body),
      },
    ),

  /**
   * Get current OAuth token status for an MCP client.
   */
  getOAuthStatus: (clientKey: string) =>
    request<MCPOAuthStatusResponse>(
      `/mcp/oauth/status/${encodeURIComponent(clientKey)}`,
    ),

  /**
   * Revoke / clear OAuth tokens for an MCP client.
   */
  revokeOAuth: (clientKey: string) =>
    request<{ message: string }>(
      `/mcp/oauth/${encodeURIComponent(clientKey)}`,
      { method: "DELETE" },
    ),
};