Skip to content

Add a client organizationId for MCP tool calls - #115

Open
sohaibahsan007 wants to merge 2 commits into
prooflinedev:mainfrom
sohaibahsan007:feat/client-organization-id
Open

sohaibahsan007 wants to merge 2 commits into
prooflinedev:mainfrom
sohaibahsan007:feat/client-organization-id

Conversation

@sohaibahsan007

Copy link
Copy Markdown

Who this helps

Anyone using the knowledge and fixes helpers with a credential that works in more than one organization, such as an MCP OAuth credential approved for several organizations. Today every one of those 11 calls has to repeat the same organization_id. A call that misses it gets ORGANIZATION_REQUIRED at run time, often deep in a script after earlier calls succeeded. The CLI solves this once with --org; the SDK had no equivalent.

What it does

new ProoflineClient({ organizationId }) sets the organization that knowledge.* and fixes.* tool calls target when the call passes no organization_id of its own.

const client = new ProoflineClient({
  organizationId: process.env.PROOFLINE_ORGANIZATION_ID || undefined,
});
const context = await client.fixes.getFixContext(findingId);

Decisions

  • A call's own organization_id always wins. Existing per-call targeting, including concurrent calls on one client, works exactly as before.
  • No environment read. I first planned to read PROOFLINE_ORGANIZATION_ID like PROOFLINE_BASE_URL. I dropped it: a wrong base URL fails loudly, but a stray organization variable could silently retarget writes such as requestReverification or startPlanImplementation where today the same mistake returns ORGANIZATION_REQUIRED. The caller passes the value explicitly, so "the SDK chooses no default" in the README stays true.
  • MCP tool calls only. mcp.listOrganizations() stays untargeted so discovery works before a target is known, and REST methods keep org_id in their path. The README says so, since the CLI's --org also covers REST.
  • Validated up front. The value must be a hyphenated UUID (either case) and is sent lowercase. Anything else throws a TypeError in the constructor, before any request. organizationId: undefined is the same as leaving it out.
  • No change to refusals or retries. A configured organization the server refuses still returns isError with NOT_AUTHORIZED, after one tool call.
  • Hand-written code only: src/transport.ts, src/mcp.ts, src/index.ts, README and tests. Nothing generated changes.

How I verified it

All CI steps locally on Node 22: pnpm install --frozen-lockfile, pnpm generate && git diff --exit-code (no drift), pnpm lint, pnpm typecheck, node check-claims.mjs, pnpm build, pnpm test: 111 of 111 pass (106 before, 5 new tests).

The new tests in tests/http.test.mjs run against the same local MCP stand-in as the existing organization tests:

  1. With organizationId set, all 11 targeted helpers send it when the call has no target and when the call passes organization_id: undefined; a per-call target wins for every helper; listOrganizations() still sends {}; three concurrent calls on one client keep their own targets; every tool call is one initialize, one notification and one call.
  2. REST getReview still requests the path's own org_id.
  3. Without the option (omitted or undefined), no organization_id key is sent and ORGANIZATION_REQUIRED is kept.
  4. A refused configured organization keeps NOT_AUTHORIZED and isError after exactly one tool call.
  5. Empty, malformed, padded, unhyphenated, braced, numeric and null values throw TypeError with no request; an uppercase UUID is sent lowercase.

The public type check now also compiles { organizationId } as constructor options under --strict --exactOptionalPropertyTypes.

To check the tests catch real breaks, I broke the code four ways and ran the suite each time: ignoring an own-key undefined (2 tests fail), letting the client target override the call's (5 fail), targeting listOrganizations (1 fails), and skipping the lowercase step (1 fails).

With a credential that works in several organizations, every knowledge
and fixes call has to repeat the same organization_id, and a call that
misses it gets ORGANIZATION_REQUIRED at run time.

ProoflineClient now accepts organizationId. Knowledge and fixes calls
without their own organization_id send it; a call's own target still
wins. listOrganizations stays untargeted and REST paths keep their
org_id. The value must be a UUID, is sent lowercase, and is never read
from the environment, so the SDK still chooses no default itself.
The README code block closed with trailing text, so the next section
rendered as code. organizationId is now typed string | undefined so the
README example compiles under exactOptionalPropertyTypes. New tests
prove the environment is never read and that a per-call null or empty
organization_id is forwarded unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant