: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
feat(mcp): point agents at business knowledge repo search (#109864)
Alex V8b8912001416
diff --git a/services/mcp/src/hono/instructions.ts b/services/mcp/src/hono/instructions.tsindex b007292b14f2..11265c0eef21 100644--- a/services/mcp/src/hono/instructions.ts+++ b/services/mcp/src/hono/instructions.ts@@ -37,6 +37,7 @@ const NOTEBOOK_ADD_CELL_TOOL = 'notebooks-add-cell'const NOTEBOOK_RUN_TOOL = 'notebooks-run'const DOCS_SEARCH_TOOL = 'docs-search'const BUSINESS_KNOWLEDGE_SEARCH_TOOL = 'business-knowledge-documents-search'+const BUSINESS_KNOWLEDGE_REPO_SEARCH_TOOL = 'business-knowledge-repositories-search'// Human comment, not AI slop. Version 2.0.0 of the PostHog app for ChatGPT and Codex started// requesting `llm_skill:read`, but existing connections never got re-prompted for it, so their@@ -183,10 +184,14 @@ export class InstructionsBuilder {const businessKnowledgeSearchEnabled = state?.allTools.some(({ name }) => name === BUSINESS_KNOWLEDGE_SEARCH_TOOL)+ const businessKnowledgeRepoSearchEnabled = state?.allTools.some(+ ({ name }) => name === BUSINESS_KNOWLEDGE_REPO_SEARCH_TOOL+ )return this.formatter.buildExecToolDescription({skillsEnabled,docsSearchEnabled,businessKnowledgeSearchEnabled,+ businessKnowledgeRepoSearchEnabled,})}diff --git a/services/mcp/src/lib/instructions-formatter.ts b/services/mcp/src/lib/instructions-formatter.tsindex a2bb6740103d..9998553ff0d9 100644--- a/services/mcp/src/lib/instructions-formatter.ts+++ b/services/mcp/src/lib/instructions-formatter.ts@@ -82,6 +82,17 @@ function businessKnowledgeSearchLine(execSyntax: boolean): string {return `- First, ${search} with a short, broad query based on the user's topic. If \`business-knowledge-document-window-retrieve\` is also available, use it when a result needs more context.`}+const BUSINESS_KNOWLEDGE_REPO_SEARCH_TOOL = 'business-knowledge-repositories-search'++/** Knowledge search never reads the team's GitHub repositories, so code questions need the repo tools.+ * The exec line stays short to keep the exec description under Claude Code's 2048-char cap. */+function businessKnowledgeRepoSearchLine(execSyntax: boolean): string {+ if (execSyntax) {+ return `- For this team's code: \`call ${BUSINESS_KNOWLEDGE_REPO_SEARCH_TOOL} <json_input>\`.`+ }+ return `- For a question about this team's code, call \`${BUSINESS_KNOWLEDGE_REPO_SEARCH_TOOL}\` with file names or identifiers, not a sentence. Read a hit with \`business-knowledge-repositories-file-retrieve\` and cite its permalink.`+}+/** Resolve the field, falling back to the advertised tool list for callers that* build a context without it (the CLI's `--agent-help`). */function docsSearchAvailable(ctx: InstructionsContext): boolean {@@ -108,9 +119,13 @@ export class InstructionsFormatter {const businessKnowledgeSearchEnabled = ctx.tools?.some(({ name }) => name === 'business-knowledge-documents-search')+ const businessKnowledgeRepoSearchEnabled = ctx.tools?.some(+ ({ name }) => name === BUSINESS_KNOWLEDGE_REPO_SEARCH_TOOL+ )return this.knowledgeFirstSectionsForCapabilities({docsSearchEnabled: docsSearchAvailable(ctx),businessKnowledgeSearchEnabled,+ businessKnowledgeRepoSearchEnabled,execSyntax: false,})}@@ -121,19 +136,26 @@ export class InstructionsFormatter {private knowledgeFirstSectionsForCapabilities(opts: {docsSearchEnabled?: booleanbusinessKnowledgeSearchEnabled?: boolean+ businessKnowledgeRepoSearchEnabled?: booleanexecSyntax: boolean}): string[] {if (!opts.docsSearchEnabled) {return []}+ const businessKnowledgeLines = opts.businessKnowledgeSearchEnabled+ ? [+ businessKnowledgeSearchLine(opts.execSyntax),+ ...(opts.businessKnowledgeRepoSearchEnabled+ ? [businessKnowledgeRepoSearchLine(opts.execSyntax)]+ : []),+ ]+ : []return [formatPrompt(BUSINESS_KNOWLEDGE_FIRST, {docs_search_call: opts.execSyntax? 'Run `call docs-search <json_input>`': 'Call the `docs-search` tool',- business_knowledge_search: opts.businessKnowledgeSearchEnabled- ? businessKnowledgeSearchLine(opts.execSyntax)- : '',+ business_knowledge_search: businessKnowledgeLines.join('\n'),}),]}@@ -219,6 +241,7 @@ export class InstructionsFormatter {skillsEnabled?: booleandocsSearchEnabled?: booleanbusinessKnowledgeSearchEnabled?: boolean+ businessKnowledgeRepoSearchEnabled?: boolean} = {}): string {const knowledgeSections = this.knowledgeFirstSectionsForCapabilities({ ...opts, execSyntax: true })diff --git a/services/mcp/tests/unit/exec.test.ts b/services/mcp/tests/unit/exec.test.tsindex f1015e7ef38a..01af4e3bbb7d 100644--- a/services/mcp/tests/unit/exec.test.ts+++ b/services/mcp/tests/unit/exec.test.ts@@ -2045,6 +2045,7 @@ describe('exec tool', () => {skillsEnabled: true,docsSearchEnabled: true,businessKnowledgeSearchEnabled: true,+ businessKnowledgeRepoSearchEnabled: true,}),commandReference,undefineddiff --git a/services/mcp/tests/unit/instructions-formatter.test.ts b/services/mcp/tests/unit/instructions-formatter.test.tsindex e429bed679ff..b0e58011aa4f 100644--- a/services/mcp/tests/unit/instructions-formatter.test.ts+++ b/services/mcp/tests/unit/instructions-formatter.test.ts@@ -207,20 +207,42 @@ describe('InstructionsFormatter', () => {expect(result).not.toContain('### PostHog knowledge sources')})- it('loads skills before checking business knowledge and docs', () => {+ it('loads skills before checking business knowledge, repositories, and docs', () => {const formatter = new InstructionsFormatter()const result = formatter.buildExecToolDescription({skillsEnabled: true,docsSearchEnabled: true,businessKnowledgeSearchEnabled: true,+ businessKnowledgeRepoSearchEnabled: true,})expect(result.indexOf('SKILL-FIRST MANDATE')).toBeLessThan(result.indexOf('### PostHog knowledge sources'))- expect(result.indexOf('business-knowledge-documents-search')).toBeLessThan(result.indexOf('docs-search'))+ expect(result.indexOf('business-knowledge-documents-search')).toBeLessThan(+ result.indexOf('`call business-knowledge-repositories-search <json_input>`')+ )+ expect(result.indexOf('business-knowledge-repositories-search')).toBeLessThan(+ result.indexOf('`call docs-search')+ )expect(result.length).toBeLessThanOrEqual(2048)})})+ describe('repository search guidance', () => {+ it.each([+ { name: 'repo search without knowledge search', bk: false, repo: true, expected: false },+ { name: 'knowledge search without repo search', bk: true, repo: false, expected: false },+ { name: 'both', bk: true, repo: true, expected: true },+ ])('names repository search only when both tools are advertised: $name', ({ bk, repo, expected }) => {+ const tools = [+ { name: 'docs-search', category: 'Docs' },+ ...(bk ? [{ name: 'business-knowledge-documents-search', category: 'Business knowledge' }] : []),+ ...(repo ? [{ name: 'business-knowledge-repositories-search', category: 'Business knowledge' }] : []),+ ]+ const result = new InstructionsFormatter().buildToolsInstructions({ ...fullCtx, tools })+ expect(result.includes('`business-knowledge-repositories-search`')).toBe(expected)+ })+ })+describe('buildExecCommandReference', () => {it.each([{ name: 'both lookup tools', tools: ['project-get', 'execute-sql'], project: true, groups: true },