@airctrl/mcp 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js ADDED
@@ -0,0 +1,78 @@
1
+ const present = (value) => value !== undefined && value.trim() !== '';
2
+ const defined = (value) => value !== undefined;
3
+ function isCanonicalB64(value, expectedBytes) {
4
+ if (!/^[A-Za-z0-9+/]+={0,2}$/.test(value))
5
+ return false;
6
+ const decoded = Buffer.from(value, 'base64');
7
+ return decoded.length === expectedBytes && decoded.toString('base64') === value;
8
+ }
9
+ /**
10
+ * Resuelve exactamente un principal MCP. Cualquier intento parcial de bundle SA
11
+ * falla cerrado y nunca degrada silenciosamente a una PAT humana.
12
+ */
13
+ export function loadConfig(env = process.env) {
14
+ const rawApiUrl = env.AIRCTRL_MCP_API_URL;
15
+ const token = env.AIRCTRL_MCP_API_TOKEN;
16
+ const vaultPassword = env.AIRCTRL_MCP_VAULT_PASSWORD;
17
+ const credentialId = env.AIRCTRL_MCP_SA_CREDENTIAL_ID;
18
+ const capPrivateKeyB64 = env.AIRCTRL_MCP_SA_CAP_PRIVATE_KEY_B64;
19
+ const serviceAccountId = env.AIRCTRL_MCP_SA_SERVICE_ACCOUNT_ID;
20
+ const hasToken = present(token);
21
+ const hasCredentialId = present(credentialId);
22
+ const hasCapPrivate = present(capPrivateKeyB64);
23
+ const hasServiceAccountId = present(serviceAccountId);
24
+ const hasSaToken = hasToken && token.trim().startsWith('sk-actrl-sa-');
25
+ const hasSaSignal = hasSaToken || defined(credentialId) || defined(capPrivateKeyB64) || defined(serviceAccountId);
26
+ const apiUrl = (rawApiUrl ?? 'http://localhost:15430').trim().replace(/\/+$/, '');
27
+ if (!apiUrl)
28
+ throw new Error('mcp_api_url_invalid');
29
+ if (hasSaSignal) {
30
+ if (!hasToken || !hasCredentialId || !hasCapPrivate) {
31
+ throw new Error('mcp_sa_bundle_incomplete');
32
+ }
33
+ if (!present(rawApiUrl))
34
+ throw new Error('mcp_sa_api_url_missing');
35
+ if (defined(serviceAccountId) && !hasServiceAccountId) {
36
+ throw new Error('mcp_sa_service_account_id_invalid');
37
+ }
38
+ if (!isCanonicalB64(capPrivateKeyB64.trim(), 32)) {
39
+ throw new Error('mcp_sa_cap_private_invalid');
40
+ }
41
+ if (present(vaultPassword))
42
+ throw new Error('mcp_principal_conflict');
43
+ return {
44
+ apiUrl,
45
+ apiToken: token.trim(),
46
+ vaultPassword: '',
47
+ principalType: 'service_account',
48
+ serviceAccountCredential: {
49
+ credentialId: credentialId.trim(),
50
+ capPrivateKeyB64: capPrivateKeyB64.trim(),
51
+ },
52
+ ...(hasServiceAccountId ? { serviceAccountId: serviceAccountId.trim() } : {}),
53
+ };
54
+ }
55
+ return {
56
+ apiUrl,
57
+ apiToken: hasToken ? token.trim() : '',
58
+ vaultPassword: vaultPassword ?? '',
59
+ principalType: hasToken ? 'human' : 'none',
60
+ };
61
+ }
62
+ /** Construye el mismo ClientOptions que usa directamente el SDK. */
63
+ export function createMcpClientOptions(config) {
64
+ return {
65
+ baseUrl: config.apiUrl,
66
+ auth: config.apiToken,
67
+ ...(config.serviceAccountCredential ? { credential: config.serviceAccountCredential } : {}),
68
+ };
69
+ }
70
+ export function mcpStatus(config) {
71
+ return {
72
+ apiUrl: config.apiUrl,
73
+ principalType: config.principalType,
74
+ tokenConfigured: config.apiToken.length > 0,
75
+ patConfigured: config.principalType === 'human',
76
+ serviceAccountCredentialConfigured: config.serviceAccountCredential !== undefined,
77
+ };
78
+ }
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { createClient } from '@airctrl/sdk';
5
+ import { createMcpClientOptions, loadConfig, mcpStatus } from './config.js';
6
+ import { registerTools } from './tools.js';
7
+ /**
8
+ * AIRCTRL MCP server (Fase 2, P2-1). Expone el gateway a agentes MCP-compatibles
9
+ * (Claude Code, Cursor, …) sobre **stdio**. Corre **local/self-hosted** (D-P2.3):
10
+ * lee una credencial humana o de Service Account del entorno y llama al control plane; **nunca** hostea
11
+ * secretos. Provider keys y material de desbloqueo no se devuelven; los tools explícitos de lectura sí
12
+ * entregan el plaintext descifrado al caller. Los tools de gestión (create_gateway, add_provider_key, …)
13
+ * se registran en S2.3 sobre el HTTP client (S2.2).
14
+ */
15
+ const config = loadConfig();
16
+ const client = createClient(createMcpClientOptions(config));
17
+ const server = new McpServer({ name: 'airctrl', version: '0.2.0' });
18
+ registerTools(server, client, config);
19
+ server.registerTool('airctrl_status', {
20
+ title: 'AIRCTRL MCP status',
21
+ description: 'Report the AIRCTRL API URL and whether MCP runs as a human or Service Account. Never returns credential values.',
22
+ inputSchema: {},
23
+ }, () => ({
24
+ content: [
25
+ {
26
+ type: 'text',
27
+ text: JSON.stringify(mcpStatus(config), null, 2),
28
+ },
29
+ ],
30
+ }));
31
+ const transport = new StdioServerTransport();
32
+ await server.connect(transport);