Skip to content

Commit bdce014

Browse files
committed
Merge remote-tracking branch 'origin/main' into claude/issue-22455-attachment-gate-master-write
2 parents b7d7893 + 446c8b2 commit bdce014

15 files changed

Lines changed: 946 additions & 137 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
"@objectstack/connector-mcp": minor
3+
---
4+
5+
feat(connector-mcp): a declarative stdio MCP transport runs in the declaring app's root, so its relative command and args resolve there wherever the server was started
6+
7+
Clause-②: yes (widening)
8+
9+
- **What changes.** For a declarative `provider: 'mcp'` connector with a stdio transport, the `mcp` provider factory now sets the child process's working directory to the app's root. It reads that root from the host through `ConnectorProviderContext.resolvePackagePath('.')`. Relative paths in the entry now resolve against the same root as the app's other relative refs, such as the `openapi` provider's `providerConfig.spec`. That covers a relative `command` path (`./bin/server`) and a script the launched program opens itself (`args: ['./scripts/server.mjs']` with `command: 'node'`). Before this change they resolved against the directory the server was started from. A boot from any other directory, such as `os verify --app examples/app-showcase/objectstack.config.ts` from the repository root, therefore registered the connector degraded, with no actions.
10+
- **What does not change.** A bare executable (`node`, `npx`) is still looked up on `PATH`, and an absolute command or argument resolves as before. The `declarativeStdio` policy judges the `command` string exactly as written, and it runs before the root is resolved. `providerConfig.transport` gains no key: the working directory comes from the host, and an authored `cwd` there is not used. A host that does not provide `resolvePackagePath` starts the child exactly as before, in the host's current directory. A server that opens relative files of its own now opens them under the app's root.
11+
- **New on the exported type.** The stdio variant of `McpTransport` gains an optional `cwd`, which the default client passes to the MCP SDK's `StdioClientTransport`. A hand-wired transport (`new ConnectorMcpPlugin({ transport })` or `createMcpConnector`) may set it. Left out, the child inherits the host's current directory, as before.
12+
- **Nothing to migrate.** An app that started its server from its own directory sees no difference, because both anchors were the same directory.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
"@objectstack/formula": minor
3+
---
4+
5+
fix(formula)!: the unknown-field check judges every spelling of a `record` / `previous` member, not only the dot, so `os build` and the object save door refuse `record['typo']`, `previous['typo']`, `record.?typo` and `record[?'typo']` (#22428)
6+
7+
Clause-②: yes (narrowing)
8+
9+
<!-- adr-0087: not-required (no-migration-prescription) A refusal at `os build` and at the object save door of an expression that names an undeclared field in a non-dot member spelling: no authorable key, spelling, export or stored shape moves, and no stored row is read, rewritten or converted. A stored object whose expression is refused keeps loading until it is next saved, and the repair is the author's own (declare the field or fix the typo), which no ledger entry can derive. The other categories are closed on facts: the package publishes (not unpublished); no ADR-0087 id covers this verdict and this diff adds none (not registered / already-registered); and no exported TypeScript declaration changes (not runtime-interface-only / type-surface-only). -->
10+
11+
**BREAKING**: an accept-set change, in both directions, of the `os build`, `os validate` and `os lint` verdicts and of the object save door, shipped as `minor` under the launch-window convention for accept-set narrowings. It narrows: an expression that names an undeclared field of its object in a non-dot member spelling (`record['FIELD']`, `record["FIELD"]`, `record.?FIELD`, `record[?'FIELD']`, or any of those on `previous`), or an undeclared leaf of a declared read attachment in such a spelling, is now refused where it was accepted. It widens: three shapes the dot-only regex misread as a member of the root, and refused as unknown fields, are now accepted, because none of them names a member. They are text inside a string literal (`record.name == 'record.typo'`), a root name after another root (`vars.record.x`), and a method call on the root itself (`record.size()`). No refusal code is added.
12+
13+
`validateExpression`'s field-existence pass judges each member an expression reads on `record` or `previous` against the object's fields, and refuses an undeclared one with the `unknown-field` code. It found those members with a regex over the dot spelling, so it judged `record.typo` and `has(record.typo)` and nothing else. `record['typo']`, `record["typo"]`, `previous['typo']`, `record.?typo` and `record[?'typo']` name the same column, and they reached the evaluator with no verdict at every slot the pass judges, among them a select option's `visibleWhen`, a field's `requiredWhen` and a validation rule's condition. There the expression faults on a key the record never carries, or reads a value that never exists.
14+
15+
The pass now reads members through the same AST member reader the relationship-traversal analysis is built on, so every spelling gets the dot spelling's verdict, did-you-mean included:
16+
17+
- `os build`, `os validate` and `os lint` refuse an expression that names an undeclared field of its object as `record['FIELD']`, `record["FIELD"]`, `record.?FIELD`, `record[?'FIELD']` or any of those on `previous`, at `error`, with the message they already give for `record.FIELD`.
18+
- The object save door runs the same pass, so an object write in publish mode that carries such an expression is now refused with an `expression-invalid` issue located at the slot, the build's own finding.
19+
- A declared read attachment's leaf (`ObjectSchema.attachedOnRead`) is judged in the same spellings: `record.viewer['can_actt']` and `record.viewer.?can_actt` are refused like `record.viewer.can_actt`. An earlier entry in this release says index access on a read attachment stays unjudged; that describes the check before this change.
20+
21+
**Remedy.** Declare the field on the object, or fix the typo to the field the message suggests. The spelling itself is not the defect: `record['status']`, `record.?status` and `record[?'status']` on a declared `status` are accepted, as before.
22+
23+
**Unchanged.**
24+
25+
- A computed key (`record[record.kind]`, `record[someVar]`) names no member before evaluation, so it is not judged.
26+
- A method call on a member (`record.name.startsWith('A')`) still judges the member (`name`).
27+
- Stored rows are not migrated or refused on read; an object stored before this change keeps loading until it is next saved, and that save is judged. Drafts are not gated.
28+
- Measured before crossing: the stacks this repository ships give the same expression findings before and after the change. That covers `examples/app-todo`, `examples/app-crm`, both `examples/app-multi-package` sub-stacks, the objects, actions, flows, views and pages of `examples/app-showcase`, the 51 objects `@objectstack/platform-objects` exports, and `plugin-approvals`' `sys_approval_request`, whose eight action predicates read the leaves of its declared `viewer` read attachment and pass. No in-repo producer writes a non-dot spelling of an undeclared field.
29+
- No public export or signature moves; only the doc comments of `ExprSchemaHint.fields` and `ExprSchemaHint.attachedOnRead` change. `analyzeRelationshipTraversals` answers exactly what it answered before: measured identical, set order included, on 4,528 analyses of the 2,264 `record` / `previous` expressions in this repository's TypeScript sources.

‎.github/workflows/ci.yml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,9 @@ jobs:
14601460
# held by every later refresh; it rises only by a ruled entry in the
14611461
# script's RULED_CEILING_RAISES. A `provisional` package prints "no
14621462
# ceiling: provisional" and is not red; a package absent from the dataset
1463-
# is red (the new-package shape). See the script header for the ruling.
1463+
# prints "no ceiling: new package" and is not red until the first refresh
1464+
# after it lands gives it a ceiling, while a package the dataset knows
1465+
# that lost its row is refused, red. See the script header for the ruling.
14641466
#
14651467
# HERE, in the aggregator, rather than in each shard, because the CLI's
14661468
# file-level slices land on three shards: the three windows are SUMMED

‎content/docs/permissions/sso.mdx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,10 @@ after DNS propagates.
279279
<Callout type="info">
280280
**The mounts are unconditional; the switch controls the endpoint behind them.**
281281
Both routes exist whether or not `OS_SSO_DOMAIN_VERIFICATION` is set — and with
282-
it unset the two halves report that differently, so match on the code rather than
283-
the status: step 1 answers **400 `DOMAIN_VERIFICATION_DISABLED`**, step 2 passes
284-
the inner **404** through with an explanatory message. Either way an anonymous
282+
it unset there is no endpoint behind them, so both steps answer **400
283+
`DOMAIN_VERIFICATION_DISABLED`**. With it on, either step answers an unknown
284+
`providerId` with **404 `RESOURCE_NOT_FOUND`**; step 2's `NO_PENDING_VERIFICATION`
285+
is a 404 too, so match on the code rather than the status. Either way an anonymous
285286
caller gets **401 `UNAUTHENTICATED`** and a signed-in non-platform-admin **403
286287
`PERMISSION_DENIED`** — identity is answered before capability, so a stranger
287288
cannot use these routes to probe which features an environment has enabled.

‎packages/connectors/connector-mcp/src/mcp-connector.ts‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ export type McpTransport =
3939
args?: string[];
4040
/** Environment variables for the child process — carries credentials. */
4141
env?: Record<string, string>;
42+
/**
43+
* Working directory of the child process. A relative `command` path
44+
* (one with a path separator, e.g. `./bin/server`) resolves against
45+
* it, and so does a relative path the launched program resolves
46+
* itself, such as the script in `node ./server.mjs`. A bare
47+
* executable name (`node`, `npx`) is still looked up on `PATH`, and an
48+
* absolute path is unaffected. Omitted, the child inherits the host
49+
* process's current directory.
50+
*
51+
* The `mcp` provider factory sets it for a **declarative** instance to
52+
* the root of the app that declared it (ADR-0097), so one app's
53+
* relative paths resolve against one anchor wherever the server was
54+
* started. A hand-wired transport keeps whatever its author passes.
55+
*/
56+
cwd?: string;
4257
}
4358
| {
4459
kind: 'http';
@@ -174,6 +189,8 @@ async function defaultClientFactory(
174189
command: transport.command,
175190
args: transport.args,
176191
env: transport.env,
192+
// `undefined` inherits the host's current directory, as before.
193+
cwd: transport.cwd,
177194
}),
178195
);
179196
} else {

‎packages/connectors/connector-mcp/src/mcp-provider.test.ts‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,110 @@ describe('mcp provider declarative stdio policy (#3055)', () => {
191191
expect(mat.def.name).toBe('github');
192192
});
193193
});
194+
195+
// ── #22423 — a declarative stdio transport runs in the declaring app's root ──
196+
//
197+
// One anchor for an app's relative paths: the host's
198+
// `ConnectorProviderContext.resolvePackagePath('.')` (the same root the
199+
// `openapi` provider's `providerConfig.spec` is read under) becomes the stdio
200+
// child's working directory. The anchor is the host's alone; an authored
201+
// `providerConfig.transport.cwd` never reaches the transport. A host without
202+
// the member gets the transport exactly as before: no `cwd` key at all.
203+
204+
describe('mcp provider: declarative stdio working directory (#22423)', () => {
205+
const ROOT = '/srv/apps/my-app';
206+
const stdioCfg = { transport: { kind: 'stdio', command: 'node', args: ['./scripts/server.mjs'] } };
207+
208+
function recordingResolver(answer = ROOT) {
209+
const asked: string[] = [];
210+
const resolvePackagePath = async (relativePath: string) => {
211+
asked.push(relativePath);
212+
return answer;
213+
};
214+
return { resolvePackagePath, asked };
215+
}
216+
217+
it("sets the stdio cwd to the host's resolvePackagePath('.'), leaving command and args as written", async () => {
218+
const { factory: clientFactory, seen } = fakeClientFactory();
219+
const { resolvePackagePath, asked } = recordingResolver();
220+
const factory = createMcpProviderFactory({ clientFactory, declarativeStdio: ['node'] });
221+
222+
await factory(ctx({ providerConfig: stdioCfg, resolvePackagePath }));
223+
224+
expect(asked).toEqual(['.']);
225+
const t = seen.transport;
226+
expect(t?.kind).toBe('stdio');
227+
if (t?.kind !== 'stdio') return;
228+
expect(t.cwd).toBe(ROOT);
229+
expect(t.command).toBe('node');
230+
expect(t.args).toEqual(['./scripts/server.mjs']);
231+
});
232+
233+
it('keeps the transport exactly as before when the host provides no resolvePackagePath', async () => {
234+
const { factory: clientFactory, seen } = fakeClientFactory();
235+
const factory = createMcpProviderFactory({ clientFactory, declarativeStdio: ['node'] });
236+
237+
await factory(ctx({ providerConfig: stdioCfg }));
238+
239+
expect(seen.transport?.kind).toBe('stdio');
240+
expect(Object.keys(seen.transport ?? {})).not.toContain('cwd');
241+
});
242+
243+
it('never honours an authored providerConfig.transport.cwd: the anchor is the host\'s', async () => {
244+
const authored = { transport: { ...stdioCfg.transport, cwd: '/somewhere/else' } };
245+
246+
const withHost = fakeClientFactory();
247+
const { resolvePackagePath } = recordingResolver();
248+
await createMcpProviderFactory({ clientFactory: withHost.factory, declarativeStdio: ['node'] })(
249+
ctx({ providerConfig: authored, resolvePackagePath }),
250+
);
251+
expect(withHost.seen.transport?.kind === 'stdio' && withHost.seen.transport.cwd).toBe(ROOT);
252+
253+
const withoutHost = fakeClientFactory();
254+
await createMcpProviderFactory({ clientFactory: withoutHost.factory, declarativeStdio: ['node'] })(
255+
ctx({ providerConfig: authored }),
256+
);
257+
expect(Object.keys(withoutHost.seen.transport ?? {})).not.toContain('cwd');
258+
});
259+
260+
it('does not consult the resolver for an http transport', async () => {
261+
const { factory: clientFactory, seen } = fakeClientFactory();
262+
const { resolvePackagePath, asked } = recordingResolver();
263+
const factory = createMcpProviderFactory({ clientFactory });
264+
265+
await factory(
266+
ctx({ providerConfig: { transport: { kind: 'http', url: 'https://mcp.example.com' } }, resolvePackagePath }),
267+
);
268+
269+
expect(asked).toEqual([]);
270+
expect(Object.keys(seen.transport ?? {})).not.toContain('cwd');
271+
});
272+
273+
it('judges the declarativeStdio policy first: a denied command never reaches the resolver', async () => {
274+
const { factory: clientFactory, seen } = fakeClientFactory();
275+
const { resolvePackagePath, asked } = recordingResolver();
276+
const factory = createMcpProviderFactory({ clientFactory }); // default deny
277+
278+
await expect(factory(ctx({ providerConfig: stdioCfg, resolvePackagePath }))).rejects.toThrow(
279+
/stdio transports are disabled by default/,
280+
);
281+
expect(asked).toEqual([]);
282+
expect(seen.transport).toBeUndefined();
283+
});
284+
285+
it('treats a resolver failure as a configuration fault (plain, not upstream-unavailable), before any connection', async () => {
286+
const { factory: clientFactory, seen } = fakeClientFactory();
287+
const factory = createMcpProviderFactory({ clientFactory, declarativeStdio: ['node'] });
288+
const resolvePackagePath = async (): Promise<string> => {
289+
throw new Error('host cannot resolve paths here');
290+
};
291+
292+
const err: unknown = await Promise.resolve(factory(ctx({ providerConfig: stdioCfg, resolvePackagePath }))).catch(
293+
(e: unknown) => e,
294+
);
295+
296+
expect(err).toBeInstanceOf(Error);
297+
expect(isConnectorUpstreamUnavailable(err)).toBe(false);
298+
expect(seen.transport).toBeUndefined();
299+
});
300+
});

‎packages/connectors/connector-mcp/src/mcp-provider.ts‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,18 @@ function assertDeclarativeStdioAllowed(
162162
* Stdio transports on declarative instances are policy-gated (default deny) —
163163
* see {@link McpDeclarativeStdioPolicy} (#3055).
164164
*
165+
* A declarative stdio transport runs **in the declaring app's root** (#22423):
166+
* when the host hands `ConnectorProviderContext.resolvePackagePath`, the
167+
* child's working directory is `resolvePackagePath('.')`, so the app's relative
168+
* `command` and `args` resolve against the same anchor as its other relative
169+
* refs (the `openapi` provider's `providerConfig.spec`, read through
170+
* `loadPackageFile`), not against the directory the server was started from.
171+
* The anchor is the host's: `providerConfig.transport` carries no working
172+
* directory, and an author cannot write one. A host without the member keeps
173+
* the previous behaviour — no `cwd`, so the child inherits the host's current
174+
* directory. The policy check runs first and is unchanged: it judges the
175+
* `command` string exactly as written.
176+
*
165177
* The connection is opened at materialization. Faults are classified (#3017):
166178
* an invalid transport shape is a *configuration* fault and throws plain —
167179
* fatal at boot per the ADR-0097 fail-loud contract — while a connect /
@@ -173,9 +185,15 @@ function assertDeclarativeStdioAllowed(
173185
export function createMcpProviderFactory(deps: McpProviderDeps = {}): ConnectorProviderFactory {
174186
return async (ctx) => {
175187
const cfg = (ctx.providerConfig ?? {}) as McpProviderConfig;
176-
const transport = normalizeTransport(cfg.transport, ctx.name, ctx.auth);
188+
let transport = normalizeTransport(cfg.transport, ctx.name, ctx.auth);
177189
if (transport.kind === 'stdio') {
178190
assertDeclarativeStdioAllowed(deps.declarativeStdio, transport.command, ctx.name);
191+
// One anchor for the app's relative paths (#22423). A resolver that
192+
// throws is a host fault: it propagates plain, a configuration error
193+
// (fatal at boot), never upstream-unavailable.
194+
if (ctx.resolvePackagePath) {
195+
transport = { ...transport, cwd: await ctx.resolvePackagePath('.') };
196+
}
179197
}
180198
const includeList = Array.isArray(cfg.include)
181199
? cfg.include.filter((x): x is string => typeof x === 'string')

0 commit comments

Comments
 (0)