Skip to content
24 changes: 24 additions & 0 deletions .changeset/36650-mcp-search-knowledge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
'@objectstack/service-knowledge': patch
'@objectstack/mcp': patch
'@objectstack/runtime': patch
'@objectstack/spec': patch
'@objectstack/lint': patch
---

feat(mcp,service-knowledge): the MCP door serves `search_knowledge`, and a skill MCP withholds is no longer withheld in silence

Clause-②: yes
Metadata-protocol: none

**`search_knowledge` over MCP.** An app that mounts the knowledge service (`KnowledgeServicePlugin`) now has its knowledge sources searchable from any MCP client: `tools/list` lists `search_knowledge` wherever the kernel holds a `knowledge` service and the connection's grant reaches the read family (`data:read`, or an API key or session, which carry no OAuth grant). Before, no MCP connection served a knowledge tool, so a BYO-AI client could not reach an app's knowledge base at all, and every skill whose `tools` named `search_knowledge` was dropped from `prompts/list`.

- **One definition, one executor (ADR-0149 D2).** `@objectstack/service-knowledge` exports the tool's `AIToolDefinition` (`getKnowledgeToolDefinitions`) and its executor (`createKnowledgeTools`, also `KnowledgeService.knowledgeTools()`). The MCP door registers the definition as the service hands it over, on HTTP and on stdio, and holds no copy of its description or argument schema. Arguments: `query` (required), `sourceIds` (at least one id; omit it to search every source, and an empty list is refused `VALIDATION_ERROR` rather than answered with no passage), `topK` (1 to 20, default 5); any other key is refused before the search runs.
- **As the caller.** Each call runs with the caller's execution context, and the knowledge service re-checks every passage indexed from a record against the caller's row-level security; on an OAuth connection that is the delegating person's own reach.
- **Only `aiExposed` sources.** The tool searches only the sources whose `aiExposed` is not `false`, and refuses a `sourceIds` entry naming any other source with `NOT_FOUND` and the sentence an unknown id gets, so an agent never learns a withheld source exists. `IKnowledgeService.search` itself is unchanged: it still searches a source its caller names explicitly, because it also serves platform callers that are not agents.
- `MCP_DOOR_TOOL_NAMES` (`@objectstack/spec/system`) lists `search_knowledge`, so `os lint` resolves it for a skill offered over MCP, as it already did through the platform registry.

**A withheld skill is said, twice.**

- **Authoring time.** The `ai-skill-tool-unresolved` rule gains a verdict for a skill MCP would offer as a prompt (`instructions`, not `mcpPrompt: false`, not `active: false`) whose `tools` names one of the `ask` product's data tools no MCP connection serves (`aggregate_data`, `query_data`, `visualize_data`): the name resolves, but MCP withholds the skill from every `prompts/list`, and the warning names the tool. Fix: bind tools both doors serve, or set `mcpPrompt: false` on a skill written for the in-product agents.
- **Runtime.** On the HTTP door, each `prompts/list` that withholds a skill logs one `debug` line naming the skill and each bound tool the connection does not serve.
9 changes: 6 additions & 3 deletions content/docs/ai/connect-mcp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,9 @@ decision.
## What the agent gets

Thirteen tools, generated from your metadata, two more for files where the
storage service is installed, and two for governed metrics where the analytics
service is installed:
storage service is installed, two for governed metrics where the analytics
service is installed, and one for knowledge search where the knowledge service
is installed:

| Tool | What it does |
|:---|:---|
Expand All @@ -279,6 +280,7 @@ service is installed:
| `create_upload_link` | Hand the user a single-use link that uploads a file onto a record's file field or its attachments (up to 10 files, sent together, for a multi-file field) |
| `list_datasets` | List the governed datasets (business metrics) you may query: their measures and dimensions with business labels, descriptions and synonyms, and which of the question's words each one matches exactly |
| `query_dataset` | Compute a governed metric by the names `list_datasets` gives; the answer carries its provenance (the dataset and measures used) |
| `search_knowledge` | Search the app's knowledge sources by meaning and answer the most relevant passages, each naming its source and, for an indexed record, that record. Only sources whose `aiExposed` is not `false` are searched, and a passage from a record the caller cannot read is dropped (registered with the `data:read` scope) |

### Each X with its latest Y: `latestPer`

Expand Down Expand Up @@ -814,7 +816,8 @@ call '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":

call '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' | grep -o '"name":"[a-z_]*"'
# → the thirteen tools, list_objects … resume_run (plus read_file and create_upload_link where storage is installed,
# and list_datasets and query_dataset where the analytics service is installed)
# list_datasets and query_dataset where the analytics service is installed,
# and search_knowledge where the knowledge service is installed)

call '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"query_records","arguments":{"objectName":"crm_opportunity","limit":3}}}'
# → {"result":{"content":[{"type":"text","text":"{ \"object\": \"crm_opportunity\", \"records\": [ ... ], \"total\": 23, \"hasMore\": true }"}]}}
Expand Down
4 changes: 3 additions & 1 deletion content/docs/ai/knowledge-rag.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ endpoints, and `aiService.chatWithTools` — is provided by the **ObjectOS**
in-product runtime. The
open-source framework has no built-in in-product chat, but everything else here — the Knowledge
Protocol, adapters, embedder, and `KnowledgeService.search` — is open, so you can call
`search` directly from your own code, agent, or MCP tool.
`search` directly from your own code or agent. An MCP client gets it as the
`search_knowledge` tool, which the MCP door serves wherever the knowledge service is
installed ([Connect an MCP Client](/docs/ai/connect-mcp)).
</Callout>

## What you get for free
Expand Down
4 changes: 3 additions & 1 deletion content/docs/protocol/knowledge.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ The Knowledge Protocol contract and the `service-knowledge` orchestrator are ope
framework mechanisms. The AI **consumer** that wires the `search_knowledge` tool
into an in-product chat loop (shown below) ships in
**ObjectOS**. On the open-source framework, reach your data through `@objectstack/mcp`
(BYO-AI) instead.
(BYO-AI) instead: its door serves the same `search_knowledge` tool wherever the
knowledge service is installed, searching only the sources whose `aiExposed` is
not `false`, as the caller.
</Callout>

This document describes the **why**, the **contract**, the **plugin
Expand Down
7 changes: 7 additions & 0 deletions packages/lint/src/rule-explanations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5836,6 +5836,13 @@ const AI_SKILL_TOOL_UNRESOLVED_EXPLANATION: RuleExplanation = {
'it. To run an app action, bind `action_<name>` (or `action_*`) rather than `run_action`: the MCP ' +
'door serves that entry through `run_action`, and the in-product agents call the action tool itself. ' +
'Ignore the warning only if a runtime plugin outside the platform registry provides the name.',
// Held to the rule by its test: the verdict fires for the ask product's tools the door lacks, on a projected skill only.
'A name that resolves can still cost the skill its MCP prompt. The MCP door offers a skill that has ' +
'`instructions` only on a connection that serves every tool its `tools` names, and the `ask` product\'s ' +
'data tools missing from `MCP_DOOR_TOOL_NAMES` (`aggregate_data`, `query_data`, `visualize_data`) are ' +
'served by no MCP connection, so a skill offered over MCP that binds one is withheld from every ' +
'`prompts/list`; that is its own verdict, naming the tool. Bind only tools both doors serve, or set ' +
'`mcpPrompt: false` when the skill is written for the in-product agents.',
'The runtime drops an unresolved name without a word, so the skill\'s instructions promise a ' +
'capability the agent cannot call, and the assistant improvises or fails when asked to use it. ' +
'A warning, not an error (ADR-0078\'s advisory-first ratchet): a runtime plugin outside the ' +
Expand Down
38 changes: 38 additions & 0 deletions packages/lint/src/validate-ai-tool-references.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
MCP_DOOR_TOOL_NAMES,
MCP_FILE_TOOL_NAMES,
PLATFORM_PROVIDED_TOOL_NAMES,
PLATFORM_TOOLS_BY_PACKAGE,
PLATFORM_TOOL_FAMILY_PREFIXES,
} from '@objectstack/spec/system';
import { explainRule } from './rule-explanations.js';
Expand Down Expand Up @@ -363,6 +364,37 @@ describe('validate-ai-tool-references', () => {
* `draft_record`): a skill naming `create_record` / `update_record` resolves;
* a near name nobody registers does not, and neither does the retired name.
*/
/**
* The `ask` product's data tools the MCP door does not register. A skill
* offered over MCP with `instructions` that binds one is withheld from
* every MCP `prompts/list` (`skillBindingServed`, `@objectstack/mcp`), so
* the rule names the tool, though the name resolves.
*/
it('names an ask tool no MCP connection serves, on a skill MCP would project, as the reason it is withheld', () => {
const askOnly = (PLATFORM_TOOLS_BY_PACKAGE['service-ai'] ?? []).filter((n) => !MCP_DOOR_TOOL_NAMES.includes(n));
expect(askOnly.sort()).toEqual(['aggregate_data', 'query_data', 'visualize_data']);
const playbook = { name: 'policy_inquiry', instructions: 'Answer from the policy clauses.' };
const findings = validateAiToolReferences({
skills: [{ ...playbook, tools: ['query_records', 'aggregate_data', 'search_knowledge'] }],
});
expect(findings.map((f) => f.path)).toEqual(['skills[0].tools[1]']);
expect(findings[0].message).toContain('"aggregate_data" is served by the in-product agents but by no MCP connection');
expect(findings[0].hint).toContain('`mcpPrompt: false`');

// The controls: MCP projects none of these skills, so none loses a prompt.
for (const skill of [
{ ...playbook, mcpPrompt: false, tools: ['aggregate_data'] },
{ name: 'no_playbook', tools: ['aggregate_data'] },
{ ...playbook, instructions: ' ', tools: ['aggregate_data'] },
{ ...playbook, active: false, tools: ['aggregate_data'] },
]) {
expect(validateAiToolReferences({ skills: [skill] }), JSON.stringify(skill)).toEqual([]);
}
// The door serves `search_knowledge` and the build product's tools may be
// a host's authoring family, so neither costs a projected skill its prompt.
expect(validateAiToolReferences({ skills: [{ ...playbook, tools: ['search_knowledge', 'verify_build'] }] })).toEqual([]);
});

it('resolves the service-ai-studio record-write pair', () => {
expect(
validateAiToolReferences({ skills: [{ name: 's', tools: ['create_record', 'update_record'] }] }),
Expand Down Expand Up @@ -495,6 +527,7 @@ describe('[#22161] one-line verdicts — ai-skill-tool-unresolved', () => {
'`url`, `modal` or `form` action is UI-only',
'advisory-first ratchet',
'never at the runtime publish gate',
'withheld from every `prompts/list`',
]) {
expect(text, `explanation names ${fact}`).toContain(fact);
}
Expand Down Expand Up @@ -525,6 +558,7 @@ describe('[#22161] one-line verdicts — ai-skill-tool-unresolved', () => {
expect(converted.some((f) => f.message.startsWith('Tool family '))).toBe(true);
expect(converted.some((f) => f.message.includes('does not become an AI tool'))).toBe(true);
expect(converted.some((f) => f.message.includes('resolves to no stack, platform or materialised action tool'))).toBe(true);
expect(converted.some((f) => f.message.includes('is served by the in-product agents but by no MCP connection'))).toBe(true);
for (const f of converted) {
expect(f.message, f.rule).not.toContain('\n');
expect(f.message.length, `${f.rule}: ${f.message}`).toBeLessThanOrEqual(200);
Expand All @@ -542,6 +576,7 @@ describe('[#22161] one-line fixes — ai-skill-tool-unresolved', () => {
expect(converted.some((f) => f.hint.startsWith('Drop `mcpPrompt: false`'))).toBe(true);
expect(converted.some((f) => f.hint.startsWith('Opt "'))).toBe(true);
expect(converted.some((f) => f.hint.startsWith('Back "'))).toBe(true);
expect(converted.some((f) => f.hint.startsWith('Set `mcpPrompt: false`'))).toBe(true);
for (const f of converted) {
expect(f.hint, f.rule).not.toContain('\n');
expect(f.hint.length, `${f.rule}: ${f.hint}`).toBeLessThanOrEqual(200);
Expand All @@ -554,5 +589,8 @@ describe('[#22161] one-line fixes — ai-skill-tool-unresolved', () => {
expect(text).toContain('the ADR-0109 default path');
expect(text).toContain('at least 40 characters');
expect(text).toContain('a runtime plugin outside the platform registry provides the name');
// The ask tools the explanation names are exactly the ones the door lacks.
const askOnly = (PLATFORM_TOOLS_BY_PACKAGE['service-ai'] ?? []).filter((n) => !MCP_DOOR_TOOL_NAMES.includes(n));
expect(text).toContain(`(${askOnly.sort().map((n) => `\`${n}\``).join(', ')})`);
});
});
55 changes: 54 additions & 1 deletion packages/lint/src/validate-ai-tool-references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@
* Trailing-wildcard entries (`action_*`, `foo_*`) resolve when ANY member of
* that universe matches the prefix.
*
* A name that resolves can still cost a skill its MCP prompt. The MCP door
* offers a skill with `instructions` only on a connection that serves every
* tool its binding names (`skillBindingServed`, `@objectstack/mcp`), and the
* `ask` product's data tools the door does not register
* ({@link ASK_TOOLS_THE_MCP_DOOR_LACKS}) are served by no MCP connection. A
* skill offered over MCP that binds one is therefore withheld from every
* connection's `prompts/list` without a word at runtime, so this rule says so
* at authoring time, by a verdict that names the tool.
*
* Severity is **warning** (ADR-0078 advisory-first ratchet), not error,
* because the universe has a known blind spot: a runtime plugin outside the
* registry can legitimately register tools no static analysis can see, and
Expand All @@ -44,6 +53,7 @@
import {
MCP_DOOR_TOOL_NAMES,
PLATFORM_PROVIDED_TOOL_NAMES,
PLATFORM_TOOLS_BY_PACKAGE,
PLATFORM_TOOL_FAMILY_PREFIXES,
} from '@objectstack/spec/system';

Expand Down Expand Up @@ -208,6 +218,29 @@ function offeredOverMcp(skill: AnyRec): boolean {
return skill.mcpPrompt !== false;
}

/**
* The `ask` product's data tools (`PLATFORM_TOOLS_BY_PACKAGE['service-ai']`)
* the MCP door does not register: in-product only. A skill offered over MCP
* whose binding names one is withheld from `prompts/list` on every MCP
* connection. The `build` product's tools are deliberately not here: a host
* may serve them over MCP through its authoring family, under
* `metadata:write`, so a binding naming one is not withheld everywhere.
*/
const ASK_TOOLS_THE_MCP_DOOR_LACKS: ReadonlySet<string> = new Set(
(PLATFORM_TOOLS_BY_PACKAGE['service-ai'] ?? []).filter((name) => !MCP_DOOR_TOOL_NAMES.includes(name)),
);

/**
* Would the MCP door project this skill as a prompt, given a connection that
* served its binding? Only an active skill offered over MCP that carries
* `instructions` is projected (`projectSkillPrompt`, `@objectstack/mcp`); a
* skill that is not projected loses nothing to a binding MCP cannot serve.
*/
function projectedOverMcp(skill: AnyRec): boolean {
if (!offeredOverMcp(skill) || skill.active === false) return false;
return typeof skill.instructions === 'string' && skill.instructions.trim() !== '';
}

/**
* Validate every `skill.tools[]` reference in a stack. Returns findings
* (empty = clean).
Expand Down Expand Up @@ -238,10 +271,30 @@ export function validateAiToolReferences(stack: AnyRec): AiToolRefFinding[] {
const refs = Array.isArray(skill.tools) ? skill.tools : [];
const overMcp = offeredOverMcp(skill);
const universe = overMcp ? withMcpDoorTools : shared;
const projected = projectedOverMcp(skill);

for (let ti = 0; ti < refs.length; ti++) {
const ref = strName(refs[ti]);
if (!ref || resolves(ref, universe)) continue;
if (!ref) continue;
if (resolves(ref, universe)) {
// A name the in-product agents serve and no MCP connection does: the
// skill resolves, and is withheld from every MCP `prompts/list`.
if (projected && ASK_TOOLS_THE_MCP_DOOR_LACKS.has(ref)) {
findings.push({
severity: 'warning',
rule: AI_SKILL_TOOL_UNRESOLVED,
where: `skill "${skillName}" · tools`,
path: `skills[${si}].tools[${ti}]`,
message:
`Tool "${ref}" is served by the in-product agents but by no MCP connection, so MCP withholds ` +
'this skill from `prompts/list` and its instructions never reach an MCP client',
hint:
'Set `mcpPrompt: false` if the skill is for the in-product agents only, or bind a tool the MCP door ' +
`serves in place of "${ref}"`,
});
}
continue;
}

const isPattern = ref.endsWith('*');
// A name (or family) the MCP door serves, on a skill its owner keeps out
Expand Down
4 changes: 4 additions & 0 deletions packages/mcp/src/mcp-file-tools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,10 @@ describe('the tools the door registers are the ones a skill offered over MCP may
],
searchPackageDocs: unused,
readPackageDoc: unused,
searchKnowledge: unused,
knowledgeToolDefinitions: () => [
{ name: 'search_knowledge', description: 'Search the knowledge sources.', parameters: { type: 'object', properties: { query: { type: 'string' } }, required: ['query'] } },
],
});
}
const everyScope = [
Expand Down
Loading
Loading