Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(ci): limit mcp agent api diff fetches (#127696)

posthog[bot]6e9aaaa22646
diff --git a/.github/workflows/ci-mcp-agent-api-diff.yml b/.github/workflows/ci-mcp-agent-api-diff.yml
index f68934ceada4..55813b731882 100644
--- a/.github/workflows/ci-mcp-agent-api-diff.yml
+++ b/.github/workflows/ci-mcp-agent-api-diff.yml
@@ -47,6 +47,13 @@ jobs:
uses: actions/[email protected]
with:
fetch-depth: 2
+ sparse-checkout: |
+ /.nvmrc
+ /services/mcp/scripts/agent-api-diff.ts
+ /services/mcp/scripts/lib/agent-api-diff.ts
+ /services/mcp/schema/
+ /services/mcp/tests/unit/__snapshots__/tool-schemas/
+ sparse-checkout-cone-mode: false
persist-credentials: false
- name: Set up Node.js
diff --git a/services/mcp/scripts/agent-api-diff.ts b/services/mcp/scripts/agent-api-diff.ts
index 02f64665b88f..9e6de1f8d0f0 100644
--- a/services/mcp/scripts/agent-api-diff.ts
+++ b/services/mcp/scripts/agent-api-diff.ts
@@ -27,18 +27,21 @@ const TRACKED_PATHS = ['services/mcp/schema', 'services/mcp/tests/unit/__snapsho
const EXIT_UNAVAILABLE = 3
function extractBaseRef(baseRef: string, target: string): string | null {
- const archive = spawnSync('git', ['archive', baseRef, '--', ...TRACKED_PATHS], {
- cwd: REPO_ROOT,
- maxBuffer: 256 * 1024 * 1024,
- })
- if (archive.status !== 0) {
- console.warn(`Could not read ${baseRef}: ${archive.stderr?.toString().trim()}`)
- return null
- }
- const untar = spawnSync('tar', ['-x', '-C', target], { input: archive.stdout })
- if (untar.status !== 0) {
- console.warn(`Could not unpack ${baseRef}: ${untar.stderr?.toString().trim()}`)
- return null
+ // A commit-root archive prefetches unrelated blobs in a partial clone, even with a path filter.
+ for (const trackedPath of TRACKED_PATHS) {
+ const archive = spawnSync('git', ['archive', `--prefix=${trackedPath}/`, `${baseRef}:${trackedPath}`], {
+ cwd: REPO_ROOT,
+ maxBuffer: 256 * 1024 * 1024,
+ })
+ if (archive.status !== 0) {
+ console.warn(`Could not read ${baseRef}: ${archive.stderr?.toString().trim()}`)
+ return null
+ }
+ const untar = spawnSync('tar', ['-x', '-C', target], { input: archive.stdout })
+ if (untar.status !== 0) {
+ console.warn(`Could not unpack ${baseRef}: ${untar.stderr?.toString().trim()}`)
+ return null
+ }
}
return target
}
diff --git a/services/mcp/tests/unit/agent-api-diff.test.ts b/services/mcp/tests/unit/agent-api-diff.test.ts
index 51e18dce5ea4..c9877b3f1f05 100644
--- a/services/mcp/tests/unit/agent-api-diff.test.ts
+++ b/services/mcp/tests/unit/agent-api-diff.test.ts
@@ -1,4 +1,6 @@
import { spawnSync } from 'node:child_process'
+import * as fs from 'node:fs'
+import * as os from 'node:os'
import * as path from 'node:path'
import { describe, expect, it } from 'vitest'
@@ -24,15 +26,47 @@ function surface(
}
describe('agent API diff', () => {
- it('runs the CLI with native Node.js without a TypeScript loader', () => {
- const root = path.resolve(import.meta.dirname, '../../../..')
- const result = spawnSync(
- process.execPath,
- [path.join(root, 'services/mcp/scripts/agent-api-diff.ts'), '--base-dir', root],
- { encoding: 'utf-8' }
- )
+ it.each(['directory', 'git ref'])('runs the CLI with native Node.js using a base %s', (baseSource) => {
+ const sourceRoot = path.resolve(import.meta.dirname, '../../../..')
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'agent-api-cli-'))
+ try {
+ for (const file of ['scripts/agent-api-diff.ts', 'scripts/lib/agent-api-diff.ts']) {
+ const target = path.join(root, 'services/mcp', file)
+ fs.mkdirSync(path.dirname(target), { recursive: true })
+ fs.copyFileSync(path.join(sourceRoot, 'services/mcp', file), target)
+ }
+ const schemaDir = path.join(root, 'services/mcp/schema')
+ const snapshotDir = path.join(root, 'services/mcp/tests/unit/__snapshots__/tool-schemas')
+ fs.mkdirSync(schemaDir, { recursive: true })
+ fs.mkdirSync(snapshotDir, { recursive: true })
+ fs.writeFileSync(path.join(schemaDir, 'tool-definitions.json'), JSON.stringify({ 'example-tool': {} }))
+ fs.writeFileSync(path.join(schemaDir, 'generated-tool-definitions.json'), '{}')
+ fs.writeFileSync(path.join(snapshotDir, 'example-tool.json'), JSON.stringify({ properties: {} }))
+ for (const args of [
+ ['init', '-q'],
+ ['add', '.'],
+ ]) {
+ expect(spawnSync('git', args, { cwd: root }).status).toBe(0)
+ }
+ const tree = spawnSync('git', ['write-tree'], { cwd: root, encoding: 'utf-8' })
+ expect(tree.status).toBe(0)
+ const result = spawnSync(
+ process.execPath,
+ [
+ path.join(root, 'services/mcp/scripts/agent-api-diff.ts'),
+ ...(baseSource === 'directory' ? ['--base-dir', root] : ['--base-ref', tree.stdout.trim()]),
+ ],
+ { encoding: 'utf-8' }
+ )
- expect({ status: result.status, stdout: result.stdout }).toEqual({ status: 0, stdout: '' })
+ expect({ status: result.status, stdout: result.stdout, stderr: result.stderr }).toEqual({
+ status: 0,
+ stdout: '',
+ stderr: '',
+ })
+ } finally {
+ fs.rmSync(root, { recursive: true, force: true })
+ }
})
it('renders nothing when the tool surface is unchanged', () => {