|
| 1 | +// Types for the team MCP gateway API (`/api/projects/{id}/mcp_gateway/*`). |
| 2 | +// Hand-written mirrors of the Django serializers in |
| 3 | +// products/mcp_store/backend/presentation/gateway_views.py — these endpoints |
| 4 | +// ship behind the `mcp-gateway` flag and are not in the generated OpenAPI |
| 5 | +// client yet. |
| 6 | +import type { Schemas } from "./generated"; |
| 7 | +import type { McpApprovalState, McpAuthType, McpCategory } from "./types"; |
| 8 | + |
| 9 | +export type McpGatewayUser = Schemas.UserBasic; |
| 10 | + |
| 11 | +export type McpGatewayScopeType = "team" | "member" | "agent"; |
| 12 | +export type McpServiceAccountStatus = "active" | "paused"; |
| 13 | +export type McpAuditDecision = "auto" | "approved" | "pending" | "blocked"; |
| 14 | +export type McpAuditQuickFilter = "all" | "agents" | "approvals" | "blocked"; |
| 15 | +export type McpPolicyDecidedBy = |
| 16 | + | "rule" |
| 17 | + | "scope" |
| 18 | + | "team" |
| 19 | + | "preset" |
| 20 | + | "legacy" |
| 21 | + | "default"; |
| 22 | + |
| 23 | +/** One member's connection to a gateway server. */ |
| 24 | +export interface McpGatewayConnection { |
| 25 | + installation_id: string; |
| 26 | + user: McpGatewayUser; |
| 27 | + last_used_at: string | null; |
| 28 | + pending_oauth: boolean; |
| 29 | + needs_reauth: boolean; |
| 30 | +} |
| 31 | + |
| 32 | +/** The requesting user's own connection to a gateway server. */ |
| 33 | +export interface McpGatewayYourConnection { |
| 34 | + installation_id: string; |
| 35 | + /** Per-connection switch — false when self-disabled. */ |
| 36 | + is_enabled: boolean; |
| 37 | + pending_oauth: boolean; |
| 38 | + needs_reauth: boolean; |
| 39 | + last_used_at: string | null; |
| 40 | +} |
| 41 | + |
| 42 | +/** One agent's access to a gateway server. */ |
| 43 | +export interface McpGatewayAgentAccess { |
| 44 | + service_account_id: string; |
| 45 | + name: string; |
| 46 | + /** Agent identity handle, e.g. posthog-support. */ |
| 47 | + handle: string; |
| 48 | + status: McpServiceAccountStatus; |
| 49 | + last_active_at: string | null; |
| 50 | + granted_by: McpGatewayUser | null; |
| 51 | +} |
| 52 | + |
| 53 | +/** A server registered in the team's gateway, with connection summary. */ |
| 54 | +export interface McpGatewayServer { |
| 55 | + id: string; |
| 56 | + name: string; |
| 57 | + url: string; |
| 58 | + description: string; |
| 59 | + category: McpCategory; |
| 60 | + is_team_enabled: boolean; |
| 61 | + icon_key: string; |
| 62 | + docs_url: string; |
| 63 | + template_id: string | null; |
| 64 | + /** |
| 65 | + * Fixed authentication type for catalog templates. Null for custom |
| 66 | + * servers, where each member chooses when connecting. |
| 67 | + */ |
| 68 | + template_auth_type: McpAuthType | null; |
| 69 | + tool_count: number; |
| 70 | + /** Members with a connection to this server. Admin-only; empty for members. */ |
| 71 | + connections: McpGatewayConnection[]; |
| 72 | + your_connection: McpGatewayYourConnection | null; |
| 73 | + agents: McpGatewayAgentAccess[]; |
| 74 | + /** Ids of members whose access an admin has turned off. */ |
| 75 | + revoked_user_ids: number[]; |
| 76 | + is_revoked_for_you: boolean; |
| 77 | + created_by: McpGatewayUser | null; |
| 78 | + created_at: string; |
| 79 | + updated_at: string; |
| 80 | +} |
| 81 | + |
| 82 | +export interface McpGatewayServerUpdate { |
| 83 | + name?: string; |
| 84 | + description?: string; |
| 85 | + category?: McpCategory; |
| 86 | + /** Master switch — off means members and agents can neither see nor call the server. */ |
| 87 | + is_team_enabled?: boolean; |
| 88 | +} |
| 89 | + |
| 90 | +/** Which policy scope a tools query or policy upsert targets. */ |
| 91 | +export interface McpGatewayPolicyScope { |
| 92 | + scope_type?: McpGatewayScopeType; |
| 93 | + /** Member scope target. Defaults to the requesting user. */ |
| 94 | + scope_user_id?: number; |
| 95 | + /** Agent scope target. Required when scope_type is "agent". */ |
| 96 | + scope_service_account_id?: string; |
| 97 | +} |
| 98 | + |
| 99 | +export interface McpToolPolicyEntry { |
| 100 | + tool_name: string; |
| 101 | + policy_state: McpApprovalState; |
| 102 | +} |
| 103 | + |
| 104 | +/** One tool with its effective policy for the requested scope. */ |
| 105 | +export interface McpResolvedToolPolicy { |
| 106 | + tool_name: string; |
| 107 | + description: string; |
| 108 | + input_schema: unknown; |
| 109 | + policy_state: McpApprovalState; |
| 110 | + /** What the team-level chain yields, ignoring the scope. Null when the team imposes nothing. */ |
| 111 | + team_state: McpApprovalState | null; |
| 112 | + /** True when a rule or Blocked team ceiling leaves no editable state. */ |
| 113 | + locked: boolean; |
| 114 | + decided_by: McpPolicyDecidedBy; |
| 115 | + /** Matching org rule name, when decided_by is "rule". */ |
| 116 | + rule_name: string; |
| 117 | + rule_description: string; |
| 118 | +} |
| 119 | + |
| 120 | +export interface McpServiceAccount { |
| 121 | + id: string; |
| 122 | + name: string; |
| 123 | + description: string; |
| 124 | + /** Stable identity handle the agent authenticates as, e.g. posthog-support. */ |
| 125 | + handle: string; |
| 126 | + status: McpServiceAccountStatus; |
| 127 | + /** Masked bearer token; the full token is only shown once. */ |
| 128 | + token_mask: string; |
| 129 | + server_ids: string[]; |
| 130 | + last_active_at: string | null; |
| 131 | + created_at: string; |
| 132 | + updated_at: string; |
| 133 | +} |
| 134 | + |
| 135 | +export interface McpServiceAccountWithToken extends McpServiceAccount { |
| 136 | + /** The full bearer token. Returned exactly once — on creation. */ |
| 137 | + token: string; |
| 138 | +} |
| 139 | + |
| 140 | +export interface McpAuditActorServiceAccount { |
| 141 | + id: string; |
| 142 | + name: string; |
| 143 | + handle: string; |
| 144 | +} |
| 145 | + |
| 146 | +export interface McpAuditEvent { |
| 147 | + id: string; |
| 148 | + created_at: string; |
| 149 | + server_name: string; |
| 150 | + tool_name: string; |
| 151 | + decision: McpAuditDecision; |
| 152 | + actor_user: McpGatewayUser | null; |
| 153 | + actor_service_account: McpAuditActorServiceAccount | null; |
| 154 | + /** Denormalized actor label (email or handle) that survives deletion. */ |
| 155 | + actor_label: string; |
| 156 | +} |
| 157 | + |
| 158 | +export interface McpAuditCounts { |
| 159 | + all: number; |
| 160 | + agents: number; |
| 161 | + approvals: number; |
| 162 | + blocked: number; |
| 163 | +} |
| 164 | + |
| 165 | +export interface McpAuditPage { |
| 166 | + count: number; |
| 167 | + results: McpAuditEvent[]; |
| 168 | +} |
| 169 | + |
| 170 | +export interface TeamMcpGatewayConfig { |
| 171 | + allow_custom_servers: boolean; |
| 172 | + /** Whether members may share MCP connections with agents and manage agent tool policies. */ |
| 173 | + allow_member_agent_access: boolean; |
| 174 | + /** |
| 175 | + * Whether catalog servers the team never touched (no gateway row) are |
| 176 | + * enabled. Covers templates published after the admin last curated. |
| 177 | + */ |
| 178 | + default_servers_enabled: boolean; |
| 179 | + /** Whether the requesting user can administer the gateway. */ |
| 180 | + is_admin: boolean; |
| 181 | +} |
| 182 | + |
| 183 | +export interface TeamMcpGatewayConfigUpdate { |
| 184 | + allow_custom_servers?: boolean; |
| 185 | + allow_member_agent_access?: boolean; |
| 186 | + default_servers_enabled?: boolean; |
| 187 | +} |
| 188 | + |
| 189 | +/** One team member's gateway posture (admin overview). */ |
| 190 | +export interface McpGatewayMemberSummary { |
| 191 | + user: McpGatewayUser; |
| 192 | + is_org_admin: boolean; |
| 193 | + /** Gateway servers the member has a personal connection to. */ |
| 194 | + connected_server_ids: string[]; |
| 195 | + /** Gateway servers an admin turned off for this member. */ |
| 196 | + revoked_server_ids: string[]; |
| 197 | +} |
| 198 | + |
| 199 | +/** |
| 200 | + * Gateway options accepted by install_custom / install_template. Credentials |
| 201 | + * are always personal to the installer; agents reach them through grants. |
| 202 | + */ |
| 203 | +export interface McpGatewayInstallSharingOptions { |
| 204 | + /** Whether the server starts enabled for the whole team. */ |
| 205 | + team_enabled?: boolean; |
| 206 | + /** Service accounts to grant the server to at install time, when team settings allow it. */ |
| 207 | + agent_ids?: string[]; |
| 208 | +} |
0 commit comments