: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(mcp): clarify learn file syntax and recovery (#103098)
Jake Ruthfeb09d498a03
diff --git a/services/mcp/src/skills/skill-catalog.ts b/services/mcp/src/skills/skill-catalog.tsindex d8a83276e40e..3f85cdcaf4aa 100644--- a/services/mcp/src/skills/skill-catalog.ts+++ b/services/mcp/src/skills/skill-catalog.ts@@ -307,7 +307,7 @@ export function formatLearnDocument(skillFile: SkillFile,manifestFiles: readonly SkillManifestEntry[]): string {- const manifest = formatManifest(manifestFiles)+ const manifest = `${formatManifest(manifestFiles)}\nRead a file with \`learn ${identifier} <path>\`. Separate the skill name and path with a space; do not use --file.`const full = `Skill: ${identifier}\nDescription: ${description}\n\n${manifest}\n\nSKILL.md content (frontmatter omitted):\n\n${stripFrontmatter(skillFile.content)}`if (full.length <= LEARN_OUTPUT_CHAR_LIMIT) {return fulldiff --git a/services/mcp/src/tools/exec-learn.ts b/services/mcp/src/tools/exec-learn.tsindex 351a5f1fb15f..03b98782f707 100644--- a/services/mcp/src/tools/exec-learn.ts+++ b/services/mcp/src/tools/exec-learn.ts@@ -149,8 +149,14 @@ export class ExecLearnCatalog {if (args.length === 0) {return await this.readSkill(skill)}-const flagIndex = args.findIndex((token) => token === '-s' || token === '--lines')+ const paths = flagIndex === -1 ? args : args.slice(0, flagIndex)+ if (paths.includes('--file')) {+ throw new Error(+ '`learn` does not support --file. Pass the file path directly: `learn <source>:<skill> <path>`.'+ )+ }+if (flagIndex === -1) {if (args.length === 1) {return await this.readSkill(skill, args[0])@@ -158,7 +164,6 @@ export class ExecLearnCatalog {return await this.batchReadFiles(skill, args)}- const paths = args.slice(0, flagIndex)if (paths.length !== 1) {throw new Error(SKILL_READ_USAGE)}@@ -485,6 +490,11 @@ function parseQualifiedSkill(identifier: string): QualifiedSkill {`Unknown guide or unqualified skill: "${identifier}". Use \`learn posthog:<skill>\` or \`learn project:<skill>\`.`)}+ if (skill.name.includes('/')) {+ throw new Error(+ `Invalid skill identifier: "${identifier}". Separate the skill name and file path with a space: \`learn <source>:<skill> <path>\`.`+ )+ }return skill}diff --git a/services/mcp/tests/unit/exec.test.ts b/services/mcp/tests/unit/exec.test.tsindex 089f85e92912..1f1a102118d3 100644--- a/services/mcp/tests/unit/exec.test.ts+++ b/services/mcp/tests/unit/exec.test.ts@@ -247,7 +247,22 @@ describe('exec tool', () => {command: 'learn posthog:bot-traffic SKILL.md -s',hint: 'Usage: learn <source>:<skill> <path> -s "<keywords>"',},- ])('returns recovery guidance for $command without opening the gate', async ({ command, hint }) => {+ {+ command: 'learn posthog:bot-traffic/SKILL.md',+ hint: 'Separate the skill name and file path with a space: `learn <source>:<skill> <path>`.',+ recovery: 'learn posthog:bot-traffic SKILL.md',+ },+ {+ command: 'learn posthog:bot-traffic --file SKILL.md',+ hint: '`learn` does not support --file. Pass the file path directly: `learn <source>:<skill> <path>`.',+ recovery: 'learn posthog:bot-traffic SKILL.md',+ },+ {+ command: 'learn posthog:bot-traffic SKILL.md --file',+ hint: '`learn` does not support --file. Pass the file path directly: `learn <source>:<skill> <path>`.',+ recovery: 'learn posthog:bot-traffic SKILL.md',+ },+ ])('returns recovery guidance for $command without opening the gate', async ({ command, hint, recovery }) => {const exec = createExec(undefined, undefined, {learnCatalog: guideCatalog(false),skillsSession: makeSkillsSession(),@@ -269,7 +284,7 @@ describe('exec tool', () => {await expect(exec.handler(mockContext, { command: 'call mock-tool {}' })).rejects.toMatchObject({reason: 'skills_gate',})- await exec.handler(mockContext, { command: 'learn posthog:bot-traffic' })+ await exec.handler(mockContext, { command: recovery ?? 'learn posthog:bot-traffic' })await expect(exec.handler(mockContext, { command: 'call mock-tool {}' })).resolves.toBeDefined()})diff --git a/services/mcp/tests/unit/skill-catalog.test.ts b/services/mcp/tests/unit/skill-catalog.test.tsindex d17b7b32f35b..41fdbd728890 100644--- a/services/mcp/tests/unit/skill-catalog.test.ts+++ b/services/mcp/tests/unit/skill-catalog.test.ts@@ -92,11 +92,15 @@ describe('SkillCatalog and exec learn', () => {it('returns the rendered skill with a manifest and supports scoped reads', async () => {const catalog = makeCatalog()const learn = new ExecLearnCatalog([], { posthog: catalog })- const result = catalog.read('retention-analysis')+ const result = await learn.execute('posthog:retention-analysis')expect(result).toContain('Files:')expect(result).toContain('- SKILL.md (8 lines,')expect(result).toContain('- references/functions.md (3 lines,')+ expect(result).toContain('Read a file with `learn posthog:retention-analysis <path>`.')+ expect(await learn.execute('posthog:retention-analysis references/functions.md')).toContain(+ '# Available functions'+ )expect(result).toContain('# Retention analysis')expect(result).not.toContain('name: retention-analysis')expect(catalog.searchFile('retention-analysis', 'references/functions.md', 'dateDiff')).toContain(@@ -304,13 +308,19 @@ describe('SkillCatalog and exec learn', () => {expect(results[0]!.score!).toBeGreaterThan(results[1]!.score!)})- it('offers a read and line-range recovery hint when a file search finds nothing', () => {- const output = makeCatalog().searchFile('retention-analysis', 'references/functions.md', 'nonexistentxyz')+ it.each(['nonexistentxyz', '--file'])(+ 'offers a read and line-range recovery hint when a file search for %s finds nothing',+ async (query) => {+ const learn = new ExecLearnCatalog([], { posthog: makeCatalog() })+ const output = await learn.execute(`posthog:retention-analysis references/functions.md -s "${query}"`)- expect(output).toContain('No matches for "nonexistentxyz" in retention-analysis/references/functions.md.')- expect(output).toContain('Read it with `learn retention-analysis references/functions.md` (3 lines,')- expect(output).toContain('--lines <start>:<end>')- })+ expect(output).toContain(`No matches for "${query}" in posthog:retention-analysis/references/functions.md.`)+ expect(output).toContain(+ 'Read it with `learn posthog:retention-analysis references/functions.md` (3 lines,'+ )+ expect(output).toContain('--lines <start>:<end>')+ }+ )it('describes a batch of qualified names, tolerating unknown names without failing the batch', async () => {const learn = new ExecLearnCatalog([], { posthog: makeCatalog(), project: makeProjectSkills() })