Skip to main content
The MCP server declares the tools and resources that ChatGPT discovers and invokes during a conversation.
1

Define your data types

Define the shared types that both your server and widgets use. The Product shape is app-specific—adapt it to your domain.
The TypeScript widgets have their own shared types file that adds CatalogData, CartData, and CheckoutData—the contract for the structuredContent that flows from each tool to its widget.
2

Define your product catalog

Create the canonical source of truth for product names and pricing. The checkout tool looks up prices from this catalog rather than trusting values from ChatGPT or the widget.
3

Create the HTTP server

ChatGPT sends requests to a single /mcp endpoint. Your server needs to handle POST (tool calls), GET (SSE streams), and DELETE (session cleanup), plus manage per-conversation session state:
Each ChatGPT conversation gets its own MCP session. The first POST /mcp creates a session ID; subsequent requests include it in the mcp-session-id header:
Handle GET /mcp (SSE streaming) and DELETE /mcp (session cleanup):
Add any additional endpoints and start the server:
4

Register tools and resources

Start with imports, widget URIs, and a helper to load the widget HTML files from disk.
The ui:// URIs are identifiers connecting a tool’s _meta.openai/outputTemplate to a registered resource. The text/html+skybridge MIME type tells ChatGPT this is an embeddable widget.
Register widget resourcesRegister each widget with a name, URI, MIME type, and a handler that returns the HTML:
Register the list_products toolEach tool has a name, a configuration (description, input schema, annotations, and _meta pointing to the widget), and a handler:
For a small catalog, returning all products and filtering client-side gives instant, responsive interactions without round-tripping through ChatGPT. The initialFilters field pre-selects filters based on the user’s request while still allowing free exploration. For larger catalogs, push filtering to the server.
Register the show_cart toolReceives cart items and passes them to the shopping cart widget:
Register the start_checkout toolThis tool handles server-side price validation and embed token generation:
With the server complete, continue to build the widgets.