@ultimat3/mcp 29.3.2 → 30.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CLAUDE.md +54 -59
  2. package/README.md +259 -2
  3. package/package.json +21 -10
  4. package/src/app-catalog.ts +84 -0
  5. package/src/app-tool.ts +6 -2
  6. package/src/app-tools.ts +80 -5
  7. package/src/audit-hook.ts +7 -1
  8. package/src/audit.ts +12 -1
  9. package/src/catalog-errors.ts +97 -0
  10. package/src/confirmation-approvers.ts +85 -0
  11. package/src/confirmation-decide.ts +78 -8
  12. package/src/confirmation-evidence.ts +118 -0
  13. package/src/confirmation-gate.ts +147 -44
  14. package/src/confirmation-postgres.ts +88 -7
  15. package/src/confirmation-quorum-errors.ts +102 -0
  16. package/src/confirmation-schema.ts +13 -2
  17. package/src/confirmation-store.ts +54 -19
  18. package/src/confirmations.ts +77 -8
  19. package/src/dev-graph-tool.ts +62 -0
  20. package/src/dev-server.ts +10 -2
  21. package/src/errors-transport.ts +84 -3
  22. package/src/errors.ts +46 -0
  23. package/src/exposed.ts +13 -3
  24. package/src/framework-error.ts +8 -1
  25. package/src/from-action.ts +2 -3
  26. package/src/index.ts +102 -1
  27. package/src/job-status-tool.ts +66 -0
  28. package/src/job-tool-errors.ts +15 -0
  29. package/src/job-tool.ts +167 -0
  30. package/src/oauth-metadata.ts +2 -2
  31. package/src/oauth-server.ts +80 -0
  32. package/src/projectable.ts +15 -10
  33. package/src/protocol-era.ts +270 -0
  34. package/src/recipe-errors.ts +75 -0
  35. package/src/recipe-links.ts +49 -0
  36. package/src/recipe-markdown.ts +143 -0
  37. package/src/recipe-replay.ts +101 -0
  38. package/src/recipe-search.ts +82 -0
  39. package/src/recipes-surface.ts +55 -0
  40. package/src/recipes-tool.ts +123 -0
  41. package/src/recipes.ts +167 -0
  42. package/src/registry.ts +5 -0
  43. package/src/remote-client.ts +378 -0
  44. package/src/remote-errors.ts +76 -0
  45. package/src/remote-listen.ts +108 -0
  46. package/src/remote-lock.ts +139 -0
  47. package/src/remote-oauth.ts +258 -0
  48. package/src/remote-schema.ts +51 -0
  49. package/src/remote-tools.ts +157 -0
  50. package/src/remote-wire.ts +121 -0
  51. package/src/resources.ts +84 -13
  52. package/src/runtime-schema.ts +132 -0
  53. package/src/runtime-tool.ts +115 -0
  54. package/src/scopes.ts +8 -1
  55. package/src/server-catalog.ts +200 -0
  56. package/src/server-resources.ts +117 -0
  57. package/src/server-voice.ts +10 -5
  58. package/src/server.ts +149 -168
  59. package/src/tenant.ts +189 -0
  60. package/src/transport-http-answers.ts +124 -0
  61. package/src/transport-http.ts +50 -94
  62. package/src/wire.ts +18 -4
  63. package/src/caller-context.ts +0 -22
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `docs({ q })`'s ranking, stated so it can be argued with: a recipe scores the query words it
3
+ * contains — 3 for one in its name or title, 2 in its description, 1 in its body — each word once.
4
+ * The best positive score is the hit. With none, the nearest names by edit distance are offered,
5
+ * so a miss is never an empty answer while any recipe exists.
6
+ */
7
+
8
+ import type { McpRecipe } from './recipes';
9
+ import { renderRecipe } from './recipes';
10
+
11
+ const NEAREST = 3;
12
+
13
+ const words = (text: string): ReadonlySet<string> =>
14
+ new Set(
15
+ text
16
+ .toLowerCase()
17
+ .split(/[^a-z0-9]+/)
18
+ .filter((word) => word.length >= 2),
19
+ );
20
+
21
+ export interface RecipeRanking {
22
+ /** Positive scores, best first, ties by name. Empty is a miss. */
23
+ readonly matches: readonly McpRecipe[];
24
+ /** On a miss: the closest names. Empty only when there are no recipes at all. */
25
+ readonly nearest: readonly McpRecipe[];
26
+ }
27
+
28
+ export function rankRecipes(recipes: readonly McpRecipe[], q: string): RecipeRanking {
29
+ const asked = [...words(q)];
30
+ const scored = recipes
31
+ .map((recipe) => ({ recipe, score: scoreOf(recipe, asked) }))
32
+ .filter((entry) => entry.score > 0)
33
+ .sort((a, b) => b.score - a.score || a.recipe.name.localeCompare(b.recipe.name));
34
+ if (scored.length > 0) return { matches: scored.map((entry) => entry.recipe), nearest: [] };
35
+ const target = q.toLowerCase().trim();
36
+ const nearest = recipes
37
+ .map((recipe) => ({ recipe, distance: closeness(recipe, target, asked) }))
38
+ .sort((a, b) => a.distance - b.distance || a.recipe.name.localeCompare(b.recipe.name))
39
+ .slice(0, NEAREST)
40
+ .map((entry) => entry.recipe);
41
+ return { matches: [], nearest };
42
+ }
43
+
44
+ function scoreOf(recipe: McpRecipe, asked: readonly string[]): number {
45
+ const named = words(`${recipe.name} ${recipe.title}`);
46
+ const described = words(recipe.description);
47
+ const body = words(renderRecipe(recipe));
48
+ let score = 0;
49
+ for (const word of asked) {
50
+ if (named.has(word)) score += 3;
51
+ else if (described.has(word)) score += 2;
52
+ else if (body.has(word)) score += 1;
53
+ }
54
+ return score;
55
+ }
56
+
57
+ /** The smallest edit distance from the query, or any of its words, to the name or a title word. */
58
+ function closeness(recipe: McpRecipe, target: string, asked: readonly string[]): number {
59
+ const candidates = [recipe.name, ...words(recipe.title)];
60
+ const probes = [target, ...asked];
61
+ let best = Number.POSITIVE_INFINITY;
62
+ for (const probe of probes) {
63
+ for (const candidate of candidates) best = Math.min(best, distance(probe, candidate));
64
+ }
65
+ return best;
66
+ }
67
+
68
+ /** Levenshtein, two rows. */
69
+ function distance(a: string, b: string): number {
70
+ let previous = Array.from({ length: b.length + 1 }, (_, index) => index);
71
+ for (let i = 1; i <= a.length; i += 1) {
72
+ const current = [i];
73
+ for (let j = 1; j <= b.length; j += 1) {
74
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
75
+ current.push(
76
+ Math.min((previous[j] ?? 0) + 1, (current[j - 1] ?? 0) + 1, (previous[j - 1] ?? 0) + cost),
77
+ );
78
+ }
79
+ previous = current;
80
+ }
81
+ return previous[b.length] ?? 0;
82
+ }
@@ -0,0 +1,55 @@
1
+ /**
2
+ * What `recipes:` and `extraRecipes:` add to a `defineAppMcp` server, after the boot checks: the
3
+ * `docs` tool, one `docs://recipes/<name>` resource per recipe, and — for a caller's own — a
4
+ * per-caller resource source. Nothing at all without either option.
5
+ */
6
+
7
+ import { McpToolDuplicateError } from './errors';
8
+ import { noteServedRecipes } from './recipe-links';
9
+ import type { McpRecipe } from './recipes';
10
+ import { assertNoRecipeResources, checkRecipes, recipeResources } from './recipes';
11
+ import type { ExtraRecipes } from './recipes-tool';
12
+ import { DOCS_TOOL, recipesFor, recipesTool } from './recipes-tool';
13
+ import type { AnyMcpTool } from './registry';
14
+ import type { McpResource, McpResourceSource } from './resources';
15
+
16
+ export interface RecipeSurface {
17
+ readonly tools: readonly AnyMcpTool[];
18
+ readonly resources: readonly McpResource[];
19
+ readonly resourceSources: readonly McpResourceSource[];
20
+ }
21
+
22
+ export function withRecipes(
23
+ tools: readonly AnyMcpTool[],
24
+ resources: readonly McpResource[],
25
+ recipes: readonly McpRecipe[] | undefined,
26
+ extra: ExtraRecipes | undefined,
27
+ ): RecipeSurface {
28
+ const declared = recipes ?? [];
29
+ if (declared.length === 0 && extra === undefined) {
30
+ return { tools, resources, resourceSources: [] };
31
+ }
32
+ assertNoRecipeResources(resources);
33
+ checkRecipes(declared, tools);
34
+ // The one name this adds; an app tool already called `docs` is a duplicate, never a shadow.
35
+ if (tools.some((tool) => tool.name === DOCS_TOOL)) {
36
+ throw new McpToolDuplicateError({ name: DOCS_TOOL, declaredBy: ['tools:', 'recipes:'] });
37
+ }
38
+ const final: readonly AnyMcpTool[] = [...tools, recipesTool(declared, () => final, extra)];
39
+ noteServedRecipes(declared.map((recipe) => recipe.name));
40
+ const source: McpResourceSource | undefined =
41
+ extra === undefined
42
+ ? undefined
43
+ : {
44
+ list: async (caller) =>
45
+ recipeResources(
46
+ (await recipesFor([], extra, final, caller)).map((entry) => entry.recipe),
47
+ final,
48
+ ),
49
+ };
50
+ return {
51
+ tools: final,
52
+ resources: [...resources, ...recipeResources(declared, final)],
53
+ resourceSources: source === undefined ? [] : [source],
54
+ };
55
+ }
@@ -0,0 +1,123 @@
1
+ /**
2
+ * `docs` — recipes for clients that ignore resources: `{}` lists, `{ name }` / `{ uri }` reads one,
3
+ * `{ q }` inlines the best match or names the nearest. Gated per recipe by the tools it names, so
4
+ * hidden and unknown are one not-found; a caller's own recipes are marked `source: 'caller'`.
5
+ */
6
+
7
+ import { renderCauseValue, UltimateError } from '@ultimat3/core';
8
+ import { rankRecipes } from './recipe-search';
9
+ import type { McpRecipe } from './recipes';
10
+ import { recipeNameOf, recipeUri, recipeVisible, renderRecipe } from './recipes';
11
+ import type { AnyMcpTool, McpCaller, McpToolResult } from './registry';
12
+
13
+ export const DOCS_TOOL = 'docs';
14
+
15
+ /** A caller's own recipes, asked per call — a tenant's runbooks beside the app's. */
16
+ export type ExtraRecipes = (
17
+ caller: McpCaller,
18
+ ) => Promise<readonly McpRecipe[]> | readonly McpRecipe[];
19
+
20
+ /** One recipe this caller may follow, and where it came from. */
21
+ export interface SourcedRecipe {
22
+ readonly recipe: McpRecipe;
23
+ readonly source: 'app' | 'caller';
24
+ }
25
+
26
+ /** The app's recipes, then the caller's (a name the app holds is never shadowed), all gated. */
27
+ export async function recipesFor(
28
+ recipes: readonly McpRecipe[],
29
+ extra: ExtraRecipes | undefined,
30
+ catalog: readonly AnyMcpTool[],
31
+ caller: McpCaller,
32
+ ): Promise<readonly SourcedRecipe[]> {
33
+ const tools = new Map(catalog.map((tool) => [tool.name, tool]));
34
+ const taken = new Set(recipes.map((recipe) => recipe.name));
35
+ const own = extra === undefined ? [] : await extra(caller);
36
+ return [
37
+ ...recipes.map((recipe) => ({ recipe, source: 'app' as const })),
38
+ ...own
39
+ .filter((recipe) => !taken.has(recipe.name))
40
+ .map((recipe) => ({ recipe, source: 'caller' as const })),
41
+ ].filter((entry) => recipeVisible(entry.recipe, tools, caller));
42
+ }
43
+
44
+ export function recipesTool(
45
+ recipes: readonly McpRecipe[],
46
+ catalog: () => readonly AnyMcpTool[],
47
+ extra?: ExtraRecipes,
48
+ ): AnyMcpTool {
49
+ return {
50
+ name: DOCS_TOOL,
51
+ description:
52
+ 'How-to recipes for this server. docs({}) lists the ones you can follow; docs({ q }) finds one by words and reads it; docs({ name }) or docs({ uri }) reads one: which tools to call, in order, with example arguments.',
53
+ inputSchema: {
54
+ type: 'object',
55
+ properties: {
56
+ name: { type: 'string', description: 'A recipe name from docs({}).' },
57
+ uri: { type: 'string', description: 'A docs://recipes/ URI, as an error links one.' },
58
+ q: { type: 'string', description: 'Words describing the task.' },
59
+ },
60
+ additionalProperties: false,
61
+ },
62
+ annotations: { readOnlyHint: true },
63
+ destructive: false,
64
+ async handle(args, caller: McpCaller): Promise<McpToolResult> {
65
+ const visible = await recipesFor(recipes, extra, catalog(), caller);
66
+ const named =
67
+ typeof args['name'] === 'string'
68
+ ? args['name']
69
+ : typeof args['uri'] === 'string'
70
+ ? (recipeNameOf(args['uri']) ?? args['uri'])
71
+ : undefined;
72
+ if (named !== undefined) {
73
+ const found = visible.find((entry) => entry.recipe.name === named);
74
+ if (found === undefined) throw notFound(named);
75
+ return text(renderRecipe(found.recipe));
76
+ }
77
+ if (typeof args['q'] === 'string' && args['q'].trim() !== '') {
78
+ return text(answerQuery(visible, args['q']));
79
+ }
80
+ return text(JSON.stringify({ recipes: visible.map(row) }));
81
+ },
82
+ };
83
+ }
84
+
85
+ const row = (entry: SourcedRecipe) => ({
86
+ name: entry.recipe.name,
87
+ title: entry.recipe.title,
88
+ description: entry.recipe.description,
89
+ uri: recipeUri(entry.recipe.name),
90
+ source: entry.source,
91
+ });
92
+
93
+ /** The best match inlined, with the runners-up named; a miss names the nearest instead. */
94
+ function answerQuery(visible: readonly SourcedRecipe[], q: string): string {
95
+ const sources = new Map(visible.map((entry) => [entry.recipe.name, entry.source]));
96
+ const { matches, nearest } = rankRecipes(
97
+ visible.map((entry) => entry.recipe),
98
+ q,
99
+ );
100
+ const line = (recipe: McpRecipe) =>
101
+ `- docs({ name: '${recipe.name}' }) — ${recipe.title}${sources.get(recipe.name) === 'caller' ? ' (yours)' : ''}`;
102
+ const [best, ...rest] = matches;
103
+ if (best !== undefined) {
104
+ const related = rest.slice(0, 4);
105
+ return related.length === 0
106
+ ? renderRecipe(best)
107
+ : `${renderRecipe(best)}\n---\nAlso matching:\n${related.map(line).join('\n')}\n`;
108
+ }
109
+ if (nearest.length === 0) return 'No recipes are available to this caller.\n';
110
+ return `No recipe matches ${JSON.stringify(q)}. Nearest:\n${nearest.map(line).join('\n')}\n`;
111
+ }
112
+
113
+ const text = (body: string): McpToolResult => ({ content: [{ type: 'text', text: body }] });
114
+
115
+ /** One answer for hidden and unknown, so a name cannot be probed into existence. */
116
+ function notFound(name: string): UltimateError {
117
+ return new UltimateError({
118
+ code: 'X_MCP_TOOL_UNKNOWN',
119
+ cause: `no recipe named ${renderCauseValue(name)} for this caller`,
120
+ fix: 'docs({}) # lists the recipes this caller can follow',
121
+ callerFix: 'docs({}) # lists the recipes this caller can follow',
122
+ });
123
+ }
package/src/recipes.ts ADDED
@@ -0,0 +1,167 @@
1
+ /**
2
+ * MCP recipes — "how do I do X here" as structure the boot checks: every step names a projected
3
+ * tool and its example must pass that tool's input. Served as `docs://recipes/<name>` and through
4
+ * `docs`, only to a caller who can see and call every tool a recipe names.
5
+ */
6
+
7
+ import {
8
+ McpRecipeExampleInvalidError,
9
+ McpRecipeLinkDanglingError,
10
+ McpRecipeToolUnknownError,
11
+ McpRecipeUriReservedError,
12
+ } from './recipe-errors';
13
+ import { placeholderPaths } from './recipe-markdown';
14
+ import type { AnyMcpTool, McpCaller } from './registry';
15
+ import { visibleToCaller } from './registry';
16
+ import type { McpResource } from './resources';
17
+ import { validateArgs } from './validate-args';
18
+
19
+ export const RECIPE_URI_PREFIX = 'docs://recipes/';
20
+ const NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
21
+
22
+ export interface McpRecipeStep {
23
+ /** A tool THIS server projects, by name. Checked at boot. */
24
+ readonly tool: string;
25
+ /** Why this step, in the reader's words. */
26
+ readonly why: string;
27
+ /** Arguments for the tool, checked against its input schema at boot. */
28
+ readonly example?: Readonly<Record<string, unknown>>;
29
+ }
30
+
31
+ export interface McpRecipe {
32
+ /** `[a-z0-9-]+`; the URI is `docs://recipes/<name>`. */
33
+ readonly name: string;
34
+ readonly title: string;
35
+ readonly description: string;
36
+ readonly steps: readonly McpRecipeStep[];
37
+ /** Free text, unchecked: where a tool is named, it is a step. */
38
+ readonly notes?: string;
39
+ /**
40
+ * Markdown served VERBATIM in place of the rendered steps — what `markdownRecipes({ dir })`
41
+ * builds from a file, its ```call fences becoming `steps`, so they are checked all the same.
42
+ */
43
+ readonly body?: string;
44
+ }
45
+
46
+ export const recipeUri = (name: string): string => `${RECIPE_URI_PREFIX}${name}`;
47
+
48
+ /** The recipe a `docs://recipes/<name>` names, or `undefined` for any other URI. */
49
+ export const recipeNameOf = (uri: string): string | undefined =>
50
+ uri.startsWith(RECIPE_URI_PREFIX) ? uri.slice(RECIPE_URI_PREFIX.length) : undefined;
51
+
52
+ /**
53
+ * Every boot refusal at once: names, then unknown tools, then examples — each kind collects all
54
+ * offenders, so one boot names every stale recipe. `catalog` is the FINAL projected tool list.
55
+ */
56
+ export function checkRecipes(recipes: readonly McpRecipe[], catalog: readonly AnyMcpTool[]): void {
57
+ const seen = new Set<string>();
58
+ for (const recipe of recipes) {
59
+ const uri = recipeUri(recipe.name);
60
+ if (!NAME.test(recipe.name)) throw new McpRecipeUriReservedError({ uri, reason: 'name' });
61
+ if (seen.has(recipe.name)) throw new McpRecipeUriReservedError({ uri, reason: 'duplicate' });
62
+ seen.add(recipe.name);
63
+ }
64
+ const tools = new Map(catalog.map((tool) => [tool.name, tool]));
65
+ const unknown: string[] = [];
66
+ const invalid: string[] = [];
67
+ for (const recipe of recipes) {
68
+ recipe.steps.forEach((step, index) => {
69
+ const tool = tools.get(step.tool);
70
+ const at = `recipe "${recipe.name}" step ${String(index + 1)}`;
71
+ if (tool === undefined) {
72
+ unknown.push(`${at} names "${step.tool}"`);
73
+ return;
74
+ }
75
+ if (step.example === undefined) return;
76
+ const checked = validateArgs(tool.inputSchema, step.example);
77
+ // A whole `"<name>"` value stands for any value of its field: `replay` fills it.
78
+ const open = new Set(placeholderPaths(step.example));
79
+ const issues = checked.ok ? [] : checked.issues.filter((issue) => !open.has(issue.path));
80
+ if (issues.length > 0) {
81
+ const lines = issues.map((issue) => `${issue.path || '(root)'}: ${issue.message}`);
82
+ invalid.push(`${at} (${step.tool}): ${lines.join(', ')}`);
83
+ }
84
+ });
85
+ }
86
+ if (unknown.length > 0) {
87
+ throw new McpRecipeToolUnknownError({ offenders: unknown, catalog: [...tools.keys()].sort() });
88
+ }
89
+ if (invalid.length > 0) throw new McpRecipeExampleInvalidError({ offenders: invalid });
90
+ assertRecipeBodyLinks(recipes);
91
+ }
92
+
93
+ /** Every `docs://recipes/<name>` a recipe's text names, as written. */
94
+ export function recipeLinks(recipe: McpRecipe): readonly string[] {
95
+ const text = `${recipe.body ?? ''}\n${recipe.notes ?? ''}`;
96
+ return [...text.matchAll(/docs:\/\/recipes\/([a-z0-9]+(?:-[a-z0-9]+)*)/g)].map(
97
+ (match) => match[1] as string,
98
+ );
99
+ }
100
+
101
+ /** A recipe pointing at one that does not exist is the stale link this whole file refuses. */
102
+ function assertRecipeBodyLinks(recipes: readonly McpRecipe[]): void {
103
+ const names = new Set(recipes.map((recipe) => recipe.name));
104
+ const offenders = recipes.flatMap((recipe) =>
105
+ recipeLinks(recipe)
106
+ .filter((name) => !names.has(name))
107
+ .map((name) => `recipe "${recipe.name}" links to ${recipeUri(name)}`),
108
+ );
109
+ if (offenders.length > 0) {
110
+ throw new McpRecipeLinkDanglingError({ offenders, recipes: [...names].sort() });
111
+ }
112
+ }
113
+
114
+ /** A hand-written resource may not take the prefix `recipes:` owns on the same server. */
115
+ export function assertNoRecipeResources(resources: readonly McpResource[]): void {
116
+ const taken = resources.find((resource) => resource.uri.startsWith(RECIPE_URI_PREFIX));
117
+ if (taken !== undefined)
118
+ throw new McpRecipeUriReservedError({ uri: taken.uri, reason: 'resource' });
119
+ }
120
+
121
+ /**
122
+ * Visible only when every step's tool is visible to this caller AND its scope is on the token —
123
+ * a staff workflow stays off a customer's list, and hidden reads exactly as unknown.
124
+ */
125
+ export function recipeVisible(
126
+ recipe: McpRecipe,
127
+ tools: ReadonlyMap<string, AnyMcpTool>,
128
+ caller: McpCaller,
129
+ ): boolean {
130
+ return recipe.steps.every((step) => {
131
+ const tool = tools.get(step.tool);
132
+ if (tool === undefined || !visibleToCaller(tool, caller)) return false;
133
+ return tool.scope === undefined || caller.scopes.has(tool.scope);
134
+ });
135
+ }
136
+
137
+ /** Markdown, from the structure alone: the same recipe is the same bytes. */
138
+ export function renderRecipe(recipe: McpRecipe): string {
139
+ if (recipe.body !== undefined) return recipe.body;
140
+ const lines = [`# ${recipe.title}`, '', recipe.description, '', '## Steps', ''];
141
+ recipe.steps.forEach((step, index) => {
142
+ lines.push(`${String(index + 1)}. \`${step.tool}\` — ${step.why}`);
143
+ if (step.example !== undefined) {
144
+ lines.push('', ' ```json', ` ${JSON.stringify(step.example)}`, ' ```', '');
145
+ }
146
+ });
147
+ if (recipe.notes !== undefined && recipe.notes.trim() !== '') {
148
+ lines.push('', '## Notes', '', recipe.notes.trim());
149
+ }
150
+ return `${lines.join('\n').trimEnd()}\n`;
151
+ }
152
+
153
+ /** Each recipe as an `McpResource`, gated per caller by the tools it names. */
154
+ export function recipeResources(
155
+ recipes: readonly McpRecipe[],
156
+ catalog: readonly AnyMcpTool[],
157
+ ): readonly McpResource[] {
158
+ const tools = new Map(catalog.map((tool) => [tool.name, tool]));
159
+ return recipes.map((recipe) => ({
160
+ uri: recipeUri(recipe.name),
161
+ name: recipe.title,
162
+ description: recipe.description,
163
+ mimeType: 'text/markdown',
164
+ visibleTo: (caller: McpCaller) => recipeVisible(recipe, tools, caller),
165
+ read: () => renderRecipe(recipe),
166
+ }));
167
+ }
package/src/registry.ts CHANGED
@@ -39,6 +39,11 @@ export interface McpCaller {
39
39
  readonly scopes: ReadonlySet<string>;
40
40
  /** Absent = no role filter applies (the caller sees every unrestricted tool). */
41
41
  readonly role?: McpRole;
42
+ /**
43
+ * The tenant THIS call acts in, on a `defineAppMcp({ tenant })` server — set by `tenant.ts` for
44
+ * one call, with `actor` the tenant's. Absent for the connection's own caller. Audited.
45
+ */
46
+ readonly tenant?: string;
42
47
  }
43
48
 
44
49
  /**