Skip to content

feat(mcp): standardise all contract tools to integer contract_id#68

Draft
sd-gh-bot wants to merge 1 commit into
mainfrom
feat/integer-contract-id
Draft

feat(mcp): standardise all contract tools to integer contract_id#68
sd-gh-bot wants to merge 1 commit into
mainfrom
feat/integer-contract-id

Conversation

@sd-gh-bot
Copy link
Copy Markdown
Contributor

@sd-gh-bot sd-gh-bot commented May 13, 2026

User description

Summary

Closes the inconsistency raised in Slack: some MCP contract tools required a composite ID (e.g. T-123 or H-456) while others required a plain integer. This polluted the agent-facing contract with an internal implementation detail and caused errors when agents mixed up the two formats.

After this PR, every contract tool accepts a single contract_id integer. The T-/H- prefix resolution is handled entirely inside the tool layer via a new shared utility.


What changed

New utility — src/utils/contract_id.ts

withCompositeId(client, contractId, apiFn) wraps any API call that requires a composite ID:

  1. Tries apiFn("T-{contractId}") first (template contracts — the common case).
  2. If the upstream returns HTTP 404, retries with apiFn("H-{contractId}") (historic/uploaded contracts).
  3. Any other error is re-thrown immediately without a second attempt.

This is deterministic: each integer maps to exactly one prefix per workspace.

Tools updated (composite string → integer)

Tool Old param New param
get_contract_status composite_id: string contract_id: integer
get_contract_content composite_id: string contract_id: integer
get_contract_download_link composite_id: string contract_id: integer
get_contract_key_pointers contract_id: string (T-/H- format) contract_id: integer
get_contract_approvals contract_id: string (T-/H- format) contract_id: integer
create_contract_approvals contract_id: string (T-/H- format) contract_id: integer
send_contract_to_counterparties contract_id: string (T-/H- format) contract_id: integer

Tools unchanged (already integer)

add_contract_comment, get_contract_activity_log, upload_contract_version

Other changes

  • get_contract_list description updated: agents should strip the T-/H- prefix from the response id field before passing to other tools.
  • compact_responses.ts: compactContractKeyPointers now handles numeric contract_id (coerces to string).
  • AGENTS.md files updated to document the new semantics and the utility.

Testing

npm test  →  29/29 pass
  • 4 new unit tests for withCompositeId (test/contract-id-resolution.test.mjs):
    • T-first success path
    • H-fallback when T returns 404
    • Non-404 errors are not retried
    • Both-miss (404 from H- also) propagates to caller
  • All 25 pre-existing tests continue to pass.

Live API validation was not run in this sandbox (no credentials). The resolution logic follows the same T-then-H pattern already used in the SpotDraft backend's own fallback code (get_contract_v3_from_historic_contract_id).


Generated description

Below is a concise technical summary of the changes proposed in this PR:
Standardize contract tooling so every endpoint accepts the integer contract_id returned by get_contract_list and let the new withCompositeId helper resolve the T- or H- prefixes before calling v2.1 APIs. Document the new semantics in the AGENTS guides and adjust helpers like compactContractKeyPointers so downstream agents stay aligned with the streamlined identifier flow.

TopicDetails
ID resolution flow Implement withCompositeId, its tests, and documentation updates so integer contract_id inputs can transparently resolve to the required T-/H- composite strings and compact responses keep emitting string IDs.
Modified files (4)
  • src/utils/AGENTS.md
  • src/utils/compact_responses.ts
  • src/utils/contract_id.ts
  • test/contract-id-resolution.test.mjs
Latest Contributors(2)
UserCommitDate
neo@spotdraft.comfeat(mcp): standardise...May 13, 2026
pranavpandey2511@gmail...Mcp response compactio...May 05, 2026
Contract tools Update every contract tool and the agent-facing contracts guide so they now accept the plain integer contract_id, defer composite prefix resolution to withCompositeId, and explain how get_contract_list filters still use the composite format while responses drop the prefix.
Modified files (9)
  • src/tools/contracts/AGENTS.md
  • src/tools/contracts/create_contract_approvals.ts
  • src/tools/contracts/get_contract_approvals.ts
  • src/tools/contracts/get_contract_content.ts
  • src/tools/contracts/get_contract_download_link.ts
  • src/tools/contracts/get_contract_key_pointers.ts
  • src/tools/contracts/get_contract_list.ts
  • src/tools/contracts/get_contract_status.ts
  • src/tools/contracts/send_contract_to_counterparties.ts
Latest Contributors(2)
UserCommitDate
neo@spotdraft.comfeat(mcp): standardise...May 13, 2026
pranavpandey2511@gmail...Mcp response compactio...May 05, 2026
Review this PR on Baz | Customize your next review

All MCP contract tools that previously required a composite ID (T-123 or
H-456) now accept a plain integer contract_id.  The T-/H- prefix is
resolved deterministically inside the tool layer so agents never need to
know about this implementation detail.

Resolution algorithm (src/utils/contract_id.ts – withCompositeId):
  1. Call the upstream API with the T-{n} composite ID.
  2. If the API returns HTTP 404, retry with H-{n}.
  3. Any other error is re-thrown immediately.

This is deterministic: each integer maps to at most one prefix per
workspace.  T contracts (created from templates) are tried first because
they are the common case; historic/uploaded contracts (H) only incur one
extra API call.

Changed tools (composite string → integer):
  • get_contract_status        (composite_id → contract_id: integer)
  • get_contract_content       (composite_id → contract_id: integer)
  • get_contract_download_link (composite_id → contract_id: integer)
  • get_contract_key_pointers  (contract_id: string → integer)
  • get_contract_approvals     (contract_id: string → integer)
  • create_contract_approvals  (contract_id: string → integer)
  • send_contract_to_counterparties (contract_id: string → integer)

Unchanged tools (already integer):
  • add_contract_comment
  • get_contract_activity_log
  • upload_contract_version

Other changes:
  • get_contract_list description updated to clarify agents strip T-/H-
    prefix from the response 'id' field before passing to other tools.
  • compact_responses.ts: compactContractKeyPointers handles numeric
    contract_id (coerces to string for the contract_id field in response).
  • 4 new unit tests for withCompositeId covering T-first success,
    H-fallback on 404, non-404 error propagation, and both-miss case.

Co-authored-by: Jaskaran Bhatia <jaskaran@spotdraft.com>
@sachin-spotdraft sachin-spotdraft added the size/m < 500 lines of changes label May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m < 500 lines of changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants