-
Notifications
You must be signed in to change notification settings - Fork 0
Mdk 456: Auth'd MCP Tools #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
+432
−1
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b1b9683
feat(api-contract): add shared schemas for MCP API
npslaney d8d1d50
feat(api-contract): add MCP contracts for CRUD operations
npslaney 2aededc
fix: address biome linting issues
npslaney 57b490d
fix(api-contract): use typed schemas for OrderSchema status and currency
npslaney da51598
fix: format export statement per biome rules
npslaney 6d00698
fix(api-contract): document NEVER→null normalization for recurringInt…
npslaney 37216cc
feat(api-contract): add list method to checkout contract
npslaney cc0b6da
feat(api-contract): add CRUD methods to products contract
npslaney 01db391
feat(api-contract): add customer contract
npslaney 05c871c
feat(api-contract): add order contract
npslaney 1653e90
refactor(api-contract): remove mcpContract, use unified contract
npslaney 1d8ac06
feat(api-contract): add SDK and MCP-specific contract exports
npslaney 7d4ed27
refactor: deduplicate schemas per PR review
npslaney f479993
fix: correct import order in checkout.ts
npslaney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { oc } from "@orpc/contract"; | ||
| import { z } from "zod"; | ||
| import { CustomerSchema } from "../schemas/customer"; | ||
| import { | ||
| PaginationInputSchema, | ||
| PaginationOutputSchema, | ||
| } from "../schemas/pagination"; | ||
|
|
||
| const ListCustomersInputSchema = PaginationInputSchema; | ||
| const ListCustomersOutputSchema = PaginationOutputSchema.extend({ | ||
| customers: z.array(CustomerSchema), | ||
| }); | ||
|
|
||
| const GetCustomerInputSchema = z.object({ id: z.string() }); | ||
|
|
||
| const CreateCustomerInputSchema = z.object({ | ||
| name: z.string().min(1), | ||
| email: z.string().email(), | ||
| }); | ||
|
|
||
| const UpdateCustomerInputSchema = z.object({ | ||
| id: z.string(), | ||
| name: z.string().optional(), | ||
| email: z.string().email().optional(), | ||
| userMetadata: z.record(z.string(), z.string()).optional(), | ||
| }); | ||
|
|
||
| const DeleteCustomerInputSchema = z.object({ id: z.string() }); | ||
|
|
||
| export const listCustomersContract = oc | ||
| .input(ListCustomersInputSchema) | ||
| .output(ListCustomersOutputSchema); | ||
|
|
||
| export const getCustomerContract = oc | ||
| .input(GetCustomerInputSchema) | ||
| .output(CustomerSchema); | ||
|
|
||
| export const createCustomerContract = oc | ||
| .input(CreateCustomerInputSchema) | ||
| .output(CustomerSchema); | ||
|
|
||
| export const updateCustomerContract = oc | ||
| .input(UpdateCustomerInputSchema) | ||
| .output(CustomerSchema); | ||
|
|
||
| export const deleteCustomerContract = oc | ||
| .input(DeleteCustomerInputSchema) | ||
| .output(z.object({ ok: z.literal(true) })); | ||
|
|
||
| export const customer = { | ||
| list: listCustomersContract, | ||
| get: getCustomerContract, | ||
| create: createCustomerContract, | ||
| update: updateCustomerContract, | ||
| delete: deleteCustomerContract, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { oc } from "@orpc/contract"; | ||
| import { z } from "zod"; | ||
| import { CustomerSchema } from "../schemas/customer"; | ||
| import { OrderItemSchema, OrderSchema } from "../schemas/order"; | ||
| import { | ||
| PaginationInputSchema, | ||
| PaginationOutputSchema, | ||
| } from "../schemas/pagination"; | ||
|
|
||
| // Order with related data for list and get views | ||
| const OrderWithRelationsSchema = OrderSchema.extend({ | ||
| customer: CustomerSchema.nullable(), | ||
| orderItems: z.array(OrderItemSchema), | ||
| }); | ||
|
|
||
| const ListOrdersInputSchema = PaginationInputSchema.extend({ | ||
| customerId: z.string().optional(), | ||
| status: z.string().optional(), // Prisma uses String type for status | ||
| }); | ||
|
|
||
| const ListOrdersOutputSchema = PaginationOutputSchema.extend({ | ||
| orders: z.array(OrderWithRelationsSchema), | ||
| }); | ||
|
|
||
| export const listOrdersContract = oc | ||
| .input(ListOrdersInputSchema) | ||
| .output(ListOrdersOutputSchema); | ||
|
|
||
| export const getOrderContract = oc | ||
| .input(z.object({ id: z.string() })) | ||
| .output(OrderWithRelationsSchema); | ||
|
|
||
| export const order = { | ||
| list: listOrdersContract, | ||
| get: getOrderContract, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| /** | ||
| * Customer schema for MCP API responses. | ||
| * Represents a customer in the organization. | ||
| * Note: Uses modifiedAt to match Prisma schema naming. | ||
| */ | ||
| export const CustomerSchema = z.object({ | ||
| id: z.string(), | ||
| name: z.string().nullable(), | ||
| email: z.string().nullable(), | ||
| emailVerified: z.boolean(), | ||
| externalId: z.string().nullable(), | ||
| userMetadata: z.record(z.string(), z.any()).nullable(), | ||
| organizationId: z.string(), | ||
| createdAt: z.date(), | ||
| modifiedAt: z.date().nullable(), | ||
| }); | ||
|
|
||
| export type Customer = z.infer<typeof CustomerSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { z } from "zod"; | ||
| import { CurrencySchema } from "./currency"; | ||
|
|
||
| /** | ||
| * Order status enum matching Prisma OrderStatus. | ||
| * Note: Prisma uses String type, so we validate against known values. | ||
| */ | ||
| export const OrderStatusSchema = z.enum([ | ||
| "PENDING", | ||
| "PAID", | ||
| "REFUNDED", | ||
| "CANCELLED", | ||
| ]); | ||
|
|
||
| export type OrderStatus = z.infer<typeof OrderStatusSchema>; | ||
|
|
||
| /** | ||
| * Order item schema representing a line item in an order. | ||
| * Note: Uses modifiedAt to match Prisma schema naming. | ||
| */ | ||
| export const OrderItemSchema = z.object({ | ||
| id: z.string(), | ||
| orderId: z.string(), | ||
| productPriceId: z.string().nullable(), | ||
| label: z.string(), | ||
| amount: z.number(), | ||
| createdAt: z.date(), | ||
| modifiedAt: z.date().nullable(), | ||
| }); | ||
|
|
||
| export type OrderItem = z.infer<typeof OrderItemSchema>; | ||
|
|
||
| /** | ||
| * Order schema for MCP API responses. | ||
| * Note: Uses modifiedAt to match Prisma schema naming. | ||
| * Note: Order doesn't have totalAmount directly - it's calculated from subtotalAmount + taxAmount. | ||
| */ | ||
| export const OrderSchema = z.object({ | ||
| id: z.string(), | ||
| organizationId: z.string(), | ||
| customerId: z.string().nullable(), | ||
| status: OrderStatusSchema, | ||
| currency: CurrencySchema, | ||
| subtotalAmount: z.number(), | ||
| taxAmount: z.number(), | ||
| userMetadata: z.record(z.string(), z.any()).nullable(), | ||
| createdAt: z.date(), | ||
| modifiedAt: z.date().nullable(), | ||
| }); | ||
|
|
||
| export type Order = z.infer<typeof OrderSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { z } from "zod"; | ||
|
|
||
| /** | ||
| * Pagination input schema for list operations. | ||
| * Uses cursor-based pagination for efficient large dataset traversal. | ||
| */ | ||
| export const PaginationInputSchema = z.object({ | ||
| limit: z.number().int().min(1).max(100).default(50), | ||
| cursor: z.string().optional(), | ||
| }); | ||
|
|
||
| export type PaginationInput = z.infer<typeof PaginationInputSchema>; | ||
|
|
||
| /** | ||
| * Pagination output schema for list operations. | ||
| * Returns a cursor for the next page, or null if no more results. | ||
| */ | ||
| export const PaginationOutputSchema = z.object({ | ||
| nextCursor: z.string().nullable(), | ||
| }); | ||
|
|
||
| export type PaginationOutput = z.infer<typeof PaginationOutputSchema>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have metadata defined on many schemas but in many different ways. I think we should have a single Metadata schema that gets re-used. Can be a future ticket as it is probably an existing problem