Skip to content

Expose Party Register and Retrieve as MCP tools, with the same policies, idempotency and Problem Details as HTTP (roadmap 1.16) - #136

Merged
KsiProgramming merged 2 commits into
mainfrom
plan/1.16-party-mcp-register-retrieve
Nov 9, 2026
Merged

KsiProgramming merged 2 commits into
mainfrom
plan/1.16-party-mcp-register-retrieve

Conversation

@KsiProgramming

Copy link
Copy Markdown
Owner

Roadmap phase

Phase: 1.16 MCP adapter: Register & Retrieve
Planning package: specs/2026-11-09-party-mcp-register-retrieve/

Closes #41

Summary

AI agents can now register a party and retrieve its directory entry over MCP. They get the same business rules, authorisation, idempotency and errors as HTTP callers (mission principles 6 and 8). These are the first context tools on /mcp.

Tools (CQRS split)

  • party_reference_data_directory_register is a command.
    • It sends the same RegisterParty as POST /PartyReferenceDataDirectory/Register and answers from its acknowledgement.
    • It needs an idempotencyKey. The existing idempotency policy replays the first answer for the same key and arguments, and answers 409 for other arguments.
  • party_reference_data_directory_retrieve is a query (readOnly).
    • It sends the same RetrievePartyReferenceDataDirectoryEntry and reads only the existing inline view.
    • No read model is new or changed.
  • Arguments are camelCase parameters: partyType and idempotencyKey, or partyReferenceDataDirectoryEntryId. BIAN's ignored Register fields are not offered to agents.
  • Results mirror the HTTP bodies, with BIAN property names, plus version: the entry's stream version, which HTTP sends as ETag. 1.17's Update tools need it as expectedVersion.
  • The tools live in the Party folder of RimBank.Mcp (ADR 0025), which now references RimBank.Core and Wolverine for its context folders. .Mcp still never references .Api, so parity tests prove the mirrored results are equal.

Authorisation: a change from the plan

  • ADR 0038 planned [Authorize(Policy = …)] on tools. With MCP SDK 2.3.1 this cannot give Problem Details:
    • the SDK's authorization filter always runs before every other filter, and refuses with a JSON-RPC -32600;
    • without that filter, an [Authorize] tool fails.
  • Tools carry [ToolOperation(OperationId)] instead. It names the same policy and scope as the endpoint's RequireOperation.
  • ToolAuthorizationFilter applies it on two paths:
    • a call without the scope is an isError result with shared.forbidden (403), and nothing is dispatched or stored;
    • tools/list hides the tool from that caller.

Tool catalog guard (pulled forward from 1.17)

  • The tools match the implemented operations of the OperationPolicyCatalog, minus a named list of the 11 operations whose tools 1.17 adds.
  • Each tool is named after its operation (ADR 0021) and has the annotations of its kind.

ADRs and docs

  • New: ADR 0039.
  • Amended: ADR 0021 (input models), ADR 0022 (filters) and ADR 0038 ([ToolOperation] instead of [Authorize]).
  • Updated: tech-stack §3.3, §4 and §6, CONTRIBUTING "MCP" (adding a tool, calling the Party tools from MCP Inspector), and the roadmap tick.

Definition of done

  • Working code that follows tech-stack.md (naming, dependency rules, business-only names in core). There is no business logic in the tools: validation comes from core value parsing (IdempotencyKey.TryCreate, PartyTypes.FromBianName, PartyReferenceDataDirectoryEntryId.TryCreate).
  • Commands and queries kept separate as described in tech-stack.md §8: commands go through decisions and return acknowledgements, queries read only from read models. Register answers from the acknowledgement, and Retrieve from the inline view only.
  • Unit tests for domain and application logic, including a projection test (Given events → Then view) for every new or changed read model, plus integration tests (Testcontainers) for any adapter touched. No domain logic or read model changed. The new MCP adapter is tested end to end through the real host and PostgreSQL (Testcontainers).
  • Every new or changed read model can be rebuilt from the context's own event store. N/A: no read model is new or changed.
  • Contexts stay loosely coupled as described in tech-stack.md §8.4: no shared or cross-context read models, and no cross-context references except .Subscriptions → .PublishedLanguage
  • Architecture tests green. No rule changed: mcp-dependencies, shared-mcp-dependencies and http-and-mcp-adapters-live-in-shared-projects hold with the new folder.
  • Every new error path returns RFC 9457 Problem Details (on both HTTP and MCP). Every tool error is isError with the same Problem Details as HTTP, now including shared.forbidden.
  • Every new BIAN operation exposed over HTTP is also exposed as an MCP tool, with a parity test. Register and Retrieve, see PartyMcpParityTests. The other 11 operations come in 1.17, as listed in the catalog test.
  • GitHub Actions CI green (build, test, format, CodeQL)
  • An ADR in docs/adr/ for any significant or BIAN-interpretation decision (ADR 0039)
  • The roadmap checkbox ticked in the same PR

Validation

  • dotnet restore RimBank.slnx --locked-mode: OK. Lock files are updated for the new references, both runtimes of RimBank.Architecture.Tests included.
  • dotnet build RimBank.slnx -c Release: 0 warnings, 0 errors.
  • dotnet test --solution RimBank.slnx -c Release --no-build: 2104 passed, 0 failed, 0 skipped.
  • dotnet format RimBank.slnx --verify-no-changes: exit 0.

New tests:

  • tests/RimBank.Host.Tests/Mcp/McpToolAuthorizationTests (fake module):
    • the list is filtered by scope;
    • shared.forbidden with instance, traceId and the same JSON as text, in both directions;
    • allowed calls run.
  • tests/RimBank.Mcp.Tests/Party/PartyReferenceDataDirectory/ (Testcontainers):
    • RegisterPartyToolTests:
      • the result and the stored party_registered event;
      • a replay with one stream, and a reused key (409);
      • an empty, invalid or too long key (400);
      • a blank or unknown partyType (400, with field errors);
      • missing arguments (shared.tool-arguments-invalid);
      • the read scope only: hidden from the list, 403, and nothing stored.
    • RetrievePartyReferenceDataDirectoryEntryToolTests:
      • the registered entry and its version;
      • 404 and a malformed id (400);
      • the write scope only: hidden from the list, and 403.
    • PartyToolCatalogTests:
      • the tool list against the catalog minus the 1.17 list;
      • name, policy, description, input schema and annotations of each tool;
      • required arguments.
    • PartyMcpParityTests:
      • Register and Retrieve bodies, with version equal to the ETag;
      • the same Problem Details (type, title, status, detail, errorCode, errors) for an invalid or blank party type, a reused key, a malformed or unknown id, and a missing scope.

Manual MCP Inspector demo (in CONTRIBUTING "MCP"): not run. It was optional and not a merge gate in validation.md.

Review focus

  • [ToolOperation] instead of [Authorize] (ADR 0039). It duplicates the SDK's list filtering in about 30 lines, in exchange for Problem Details on denial. Revisit if a later SDK lets a filter map its denial.
  • Mirrored result records next to the .Api responses, rather than relaxing mcp-dependencies. The parity tests are what stops drift.
  • version in the tool result next to the BIAN fields. There is no 304 on MCP.
  • Tool arguments as flat camelCase parameters, with BIAN's ignored Register fields left out.
  • The 1.17 list in PartyToolCatalogTests. 1.17 should empty it.
  • PostgresqlServer is copied from RimBank.Api.Tests into RimBank.Mcp.Tests. A shared fixture project could replace both later.

🤖 Generated with Claude Code

KsiProgramming and others added 2 commits November 9, 2026 11:37
…rence Data Directory

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…es, idempotency and Problem Details as HTTP (roadmap 1.16)

- party_reference_data_directory_register (command, required idempotencyKey) and
  party_reference_data_directory_retrieve (query, read-only) in the Party folder of RimBank.Mcp, dispatching the
  same RegisterParty and RetrievePartyReferenceDataDirectoryEntry through IMessageBus.
- Results mirror the HTTP bodies with BIAN names plus version (the ETag), proven equal by parity tests.
- [ToolOperation(OperationId)] and RimBank's own call and list filters apply the operation's policy: a caller
  without the scope does not see the tool and gets shared.forbidden, because the SDK's [Authorize] filter
  answers with a JSON-RPC error no filter can map (ADR 0039).
- Tool catalog guard: the tools match the implemented operations, minus the 11 that 1.17 adds.
- ADR 0039; ADR 0021, 0022 and 0038 notes; tech-stack, CONTRIBUTING and roadmap updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KsiProgramming KsiProgramming added stage:1 Roadmap Stage 1: Party Reference Data Directory (first vertical slice) type:feature New business or platform behaviour area:read-models Views, projections and queries (read side) area:mcp Model Context Protocol adapters and tools area:security Authentication, authorisation, PII, threat model context:party Party / Party Reference Data Directory labels Nov 9, 2026
@KsiProgramming KsiProgramming self-assigned this Nov 9, 2026
@KsiProgramming
KsiProgramming merged commit 81a9555 into main Nov 9, 2026
0 of 3 checks passed
@KsiProgramming
KsiProgramming deleted the plan/1.16-party-mcp-register-retrieve branch November 10, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:mcp Model Context Protocol adapters and tools area:read-models Views, projections and queries (read side) area:security Authentication, authorisation, PII, threat model context:party Party / Party Reference Data Directory stage:1 Roadmap Stage 1: Party Reference Data Directory (first vertical slice) type:feature New business or platform behaviour

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1.16 MCP adapter: Register & Retrieve

1 participant