Docs/Début
Guide source3 min read

Adopt ContractSpec in an existing codebase

Wrap one behavior you already own, preserve its observable behavior, and expand from evidence.

Download Markdown ↓
Source and verification context ⌄

Source-guided

Examiner la source ↗

Repository links may require access. Source inspection is separate from a clean public-package installation.

AN INTERACTIVE READING MAP

Get the shape of this guide.

Move through the ideas, inspect their relationships, or make a focused reading path. The complete guide stays below.

SÉQUENCE DE LECTUREComprendre les liens entre les idées
Choose a point to look closer
01 / Section du guide

Select a small adoption seam

Choose a function or endpoint that already has a clear owner and useful tests. Prefer a contained read or a reversible local action for your first exercise. A workflow that spans several providers, jobs and billing decisions makes it difficult to tell whether a problem comes from your application or the integration.

Lire le contexte à l’appui

Write down the behavior callers depend on before changing the boundary: accepted inputs, returned data, error cases, authorization and externally visible effects. This is your compatibility checklist.

Explore a section, then continue with the complete article below.

1 / 4

Select a small adoption seam

Choose a function or endpoint that already has a clear owner and useful tests. Prefer a contained read or a reversible local action for your first exercise. A workflow that spans several providers, jobs and billing decisions makes it difficult to tell whether a problem comes from your application or the integration.

Write down the behavior callers depend on before changing the boundary: accepted inputs, returned data, error cases, authorization and externally visible effects. This is your compatibility checklist.

Existing concernContractSpec responsibilityApplication responsibility
Request shapeDescribe and validate the operation inputMap the existing request into that shape
Business logicBind the operation to a handlerKeep the implementation and domain invariants
Identity and permissionsCarry requirements and decision contextAuthenticate the caller and provide trusted policy decisions
HTTP behaviorProject through a chosen adapterPreserve intended routes, status semantics and clients
Choose an evaluation that can teach you something.Explore a situation · 3 ways to look closer

Keep the existing application. Make one operation explicit, then decide what the next useful proof would be.

Which situation sounds closest?
UNE SITUATION CONCRÈTE

Start with behavior you can compare.

An existing account lookup already returns a useful result to an API consumer.

Ce qui change

The operation gains an explicit input, result, errors and ownership boundary.

Ce qui reste explicite

Its business implementation can remain in place.

SUIVRE LA CONSÉQUENCE

Compare the current route with the new binding using the same valid and invalid cases. Widen the scope only after the difference is understood.

Where this explanation comes from

An authored situation, grounded in the linked source guides. Choosing a case explores its expected responsibilities; it does not execute an operation.

Wrap the implementation before replacing it

Define a contract that reflects the behavior you intend to support. Bind the existing service function through a small handler rather than moving the entire service into the contract declaration. Make input and output translations explicit.

Register the exact contract version and attach the handler to that registration. A declaration without a bound handler is discoverable information, not a runnable operation. Keep database clients and provider secrets in host-owned code.

Compare at the boundary

Run the same representative requests against the old boundary and the new one in a disposable environment. Compare meaningful values and failures rather than incidental timestamps. Include a denied or malformed request and prove it cannot invoke the protected effect.

When transport names or response envelopes change, treat the difference as an API change. Add a deliberate compatibility mapping or update consumers together; do not assume shared types preserve a wire protocol.

Expand when the first seam pays off

A useful next step is a second interface to the same registered behavior, such as a human form and an MCP tool. You can then see which rules stopped being duplicated and which responsibilities remain in the host.

Importer output can help inventory a larger system, but inferred contracts still need review. Existing code can reveal shape and routing while missing the business reason for a policy or the scope of an approval. Make those decisions explicit before expanding.

See it in an example.

Contracts / Beginner

Write your first contract

Define an operation

Follow user.create from an email schema to a typed handler. Start with the smallest maintained example.

  1. Describe the input
  2. Name the operation
  3. Follow the handler

Ce que montre la sourceThe maintained source declares user.create with a required email input and a typed output.

Ne démontre pasA database account is created or an email is sent.

Inspect the walkthroughBehavior · proof and limits · source checks

Follow the source behavior

A small user.create command accepts one required email address. Its current handler returns the same email. This gives you a compact place to understand the contract and handler boundary before adding storage or authentication.

  1. Describe the input

    Read UserInput in src/contracts/user.ts. The schema has one required EmailAddress field. The command uses the schema for both input and output.

  2. Name the operation

    Inspect the user.create key, version 1.0.0, owner, goal, and anonymous authentication policy. These describe the operation and its boundary.

  3. Follow the handler

    Open src/handlers/user-input.handler.ts. HandlerForOperationSpec derives the handler shape from CreateUser. The implementation returns input.email; it does not create a persisted account.

  4. Inspect and adapt the starter

    Read the package smoke fixture and validation script. Replace the echo handler with your own behavior, then test that behavior and the contract boundary together.

What this example establishes
Ce que montre la source
  • The maintained source declares user.create with a required email input and a typed output.
  • The handler is typed from the operation specification.
  • A source smoke fixture checks starter metadata and feature registration.
Ne démontre pas
  • A database account is created or an email is sent.
  • This example exposes an MCP tool: its manifest disables MCP.
  • This starter implements an approval gate, persistence, or production authentication.
Reproduce the source checks

The smoke fixture checks metadata and feature wiring; validation checks the contract. Neither is an account-creation integration test.

Répertoire de travail examples/minimal

bun run smoke
bun run validate

Commands and source inspected; not executed here.

Continue from here.

Début

Read your first operation

3 min read

Trace a maintained contract from its input schema to its deliberately small handler.

Look inside the guideOpening context · complete reading path

What this walkthrough demonstrates

The maintained minimal example declares an operation named user.create. It accepts an email and returns the same email. Despite the operation's name, the shown handler does not create a persistent account, send a message or call a provider.

Work through the guide
Guides

Expose one operation through API and MCP

3 min read

Share the registered behavior while keeping authentication, transport formats and evidence explicit.

Look inside the guideOpening context · complete reading path

Start from one registry

Register the operation and bind its handler once. The REST createFetchHandler and MCP registerMcpTools implementations both call OperationSpecRegistry.executeResult. That shared invocation path is the useful connection between an API request and an agent tool call.

Work through the guide
Operations

Test the promise at the boundary

3 min read

Choose checks that establish meaningful behavior, including denied effects and real consumer imports.

Look inside the guideOpening context · complete reading path

Give each test one question

An operation has several boundaries, and one green check cannot answer every question about them. Separate declaration validity, business behavior, adapter behavior and external consumption so failures tell you where to look.

Work through the guide
Next: Contracts, handlers and adapters →
Votre vue

Make room for your context.

Shape the presentation around this moment. You can change it whenever you need.

Votre contexte

The different parts of you

Choose a starting point

Un mélange utile de contexte, de visuels et de guidage discret.

Tune each dimension
Each dimension can change independently. Product permissions and available actions stay unchanged.

Support the way you begin and return

Tune your support

Confort de lecture

Choisir votre langue

La langue de l’interface change uniquement le texte. Les marchés, les prix et les parcours conservent leurs propres paramètres.

Couverture des traductions

Une partie du contenu est affichée en anglais.

Navigation151
Graphe616
Catégories378
Portfolio833
Exemples2 035
Aperçu de la source1 542

D’autres traductions seront ajoutées à mesure que le contenu sera relu.

Cette préférence est enregistrée dans ce navigateur.

Rechercher sur le site

Des points de départ utiles

Aucun résultat. Essayez une expression plus courte, un nom d’opération ou un autre périmètre de recherche.

UN PEU DE PLACE POUR EXPLORER

Trouvez quelque chose à explorer.

Ouvrez un aperçu détaillé sur cette page, essayez une autre perspective ou suivez le détail vers sa propre page.

Fonctionnement des aperçus et des commandes
01

Regarder avant de partir

Survolez un lien ou sélectionnez-le avec Tab pour voir un aperçu. Cliquer sur le lien d’origine ou appuyer sur Entrée ouvre toujours sa destination.

02

Rester dans le contexte

Entrez dans l’aperçu pour explorer ses sections. Depuis un lien sélectionné, utilisez Alt + ↓ pour y entrer au clavier. Échap le ferme.

03

Ouvrir les possibilités

Les lignes dépliables, les choix de perspective et les commandes mises en évidence révèlent davantage. Votre vue adapte le confort de lecture et le contexte exploré.

Un bouton séparé pour voir de plus près

Affichez de petits boutons d’aperçu à côté des liens quand l’espace le permet. Touchez l’œil pour examiner ou le lien pour y aller directement. Ce choix reste dans cet onglet.

Aucun historique de navigation n’est collecté. La réduction des animations suit votre appareil et Votre vue.