Skip to content

AI-native design editor. Open-source Figma alternative.

1.6 KB
Raw Blame
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'

import { MCP_AGENT_HEADER } from '@open-pencil/core/constants'

import { replaceMCPConnectionSettings, setMCPConnectionCredential } from '@/app/integrations/mcp'
import { buildPiMCPServers } from '@/app/integrations/mcp/pi'

import { clearTauriMocks, installTauriMockWindow } from '#tests/helpers/tauri/mocks'

beforeEach(installTauriMockWindow)
afterEach(clearTauriMocks)

describe('Pi MCP configuration', () => {
  test('adapts the built-in and external MCP servers to Pi native configuration', async () => {
    replaceMCPConnectionSettings({
      version: 1,
      connections: [
        {
          id: 'mcp-example',
          name: 'example',
          enabled: true,
          transport: { type: 'streamable-http', url: 'https://example.com/mcp' },
          authentication: {
            type: 'bearer',
            credentialRef: {
              integrationId: 'mcp',
              profileId: 'mcp-example',
              field: 'bearer-token'
            }
          }
        }
      ]
    })
    await setMCPConnectionCredential('mcp-example', 'external-token')

    const servers = await buildPiMCPServers({ authorizationToken: 'built-in-token' })
    expect(servers.example).toEqual({
      url: 'https://example.com/mcp',
      headers: { Authorization: 'Bearer external-token' },
      auth: false
    })
    expect(servers['open-pencil']).toEqual({
      url: expect.stringContaining('/mcp'),
      headers: { [MCP_AGENT_HEADER]: 'harness', Authorization: 'Bearer built-in-token' },
      auth: false
    })
  })
})