Tutorials
Four ways to turn a source you already have — a live URL, a JSON Schema, an OpenAPI spec or a TypeScript type — into a working mock. Each one is a prompt for a coding agent connected to this platform over MCP, not a file you upload: the agent calls createApi and createEndpoint for you.
- 1. Issue an API key
- Create one from API keys — it is what authenticates your agent to the MCP server, never your mock URLs themselves.
- 2. Connect your coding agent
- Add the ghostmock MCP server to opencode, Claude Code, or any MCP-capable agent, using that key. Full setup for both is in Docs → Coding agents.
- 3. Paste a tutorial's prompt
- Each recipe below gives the agent both the source material and a prompt describing what to build with it.
No agent connected yet?
Generate a mock from a live URL
Point your agent at a real endpoint and let it rebuild the same response as a mock.
The source
A real, public JSON endpoint whose path carries a parameter — the postId segment changes what comes back.
[
{
"postId": 1,
"id": 1,
"name": "id labore ex et quam laborum",
"email": "Eliseo@gardner.biz",
"body": "laudantium enim quasi est quidem magnam voluptate ipsam eos\ntempora quo necessitatibus\ndolor quam autem quasi\nreiciendis et nam sapiente accusantium"
},
{
"postId": 1,
"id": 2,
"name": "quo vero reiciendis velit similique earum",
"email": "Jayne_Kuhic@sydney.com",
"body": "est natus enim nihil est dolore omnis voluptatem numquam\net omnis occaecati quod ullam at\nvoluptatem error expedita pariatur\nnihil sint nostrum voluptatem reiciendis et"
}
][
{
"postId": 2,
"id": 6,
"name": "et fugit eligendi deleniti quidem qui sint nihil autem",
"email": "Presley.Mueller@myrl.com",
"body": "doloribus at sed quis culpa deserunt consectetur qui praesentium\naccusamus fugiat dicta\nvoluptatem rerum ut voluptate autem\nvoluptatem repellendus aspernatur dolorem in"
},
{
"postId": 2,
"id": 7,
"name": "repellat consequatur praesentium vel minus molestias voluptatum",
"email": "Dallas@ole.me",
"body": "maiores sed dolores similique labore et inventore et\nquasi temporibus esse sunt id et\neos voluptatem aliquam\naliquid ratione corporis molestiae mollitia quia et magnam dolor"
}
]The prompt
Fetch https://jsonplaceholder.typicode.com/posts/1/comments and https://jsonplaceholder.typicode.com/posts/2/comments and compare them:
1. postId in the path is a path parameter of the real API — 1 and 2 return
different comments, not the same ones. Do not hardcode the 1 you happened
to fetch first.
2. Call createApi with name "comments" and prefix "jsonplaceholder".
3. Call createEndpoint on that API with method GET, path
"posts/:postId/comments" — this platform's own path-parameter syntax —
statusCode 200, and the JSON array you fetched for postId 1 as the body.
This mock cannot vary its response by the requested postId (see Docs → Path
parameters): every value you send down that segment returns the same saved
body. Pick one real response and save that.What your agent does
- createApi
- name: "comments", prefix: "jsonplaceholder".
- createEndpoint
- method: GET, path: "posts/:postId/comments", statusCode: 200, body: the fetched array for postId 1, unmodified.
- Result
- GET {server}/m/{apiId}/jsonplaceholder/posts/1/comments and .../posts/999/comments both reach that endpoint and return the same five comments — matching the real API's shape, though no longer its per-post content.
A path parameter is not a template variable
Works for any JSON endpoint
Generate a mock from a JSON Schema
A schema only describes the shape of the data — your agent invents believable values that satisfy it.
The source
A draft-07 JSON Schema describing an array of comments — it fixes the shape, not the values.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Generated schema for Root",
"type": "array",
"items": {
"type": "object",
"properties": {
"postId": {
"type": "number"
},
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"body": {
"type": "string"
}
},
"required": [
"postId",
"id",
"name",
"email",
"body"
]
}
}The prompt
Here is a JSON Schema describing an array of comments:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Generated schema for Root",
"type": "array",
"items": {
"type": "object",
"properties": {
"postId": {
"type": "number"
},
"id": {
"type": "number"
},
"name": {
"type": "string"
},
"email": {
"type": "string"
},
"body": {
"type": "string"
}
},
"required": [
"postId",
"id",
"name",
"email",
"body"
]
}
}
Use it to build a mock:
1. Call createApi with name "comments-from-schema".
2. Invent 3 to 5 example objects that satisfy the schema exactly — every
required field present, and each value matching its declared type
(postId and id are numbers, the rest are strings). Use plausible fake
text, not placeholders like "string" or "TODO".
3. Call createEndpoint with method GET, path "comments", statusCode 200, and
your generated array as the body.What your agent does
- createApi
- name: "comments-from-schema".
- createEndpoint
- method: GET, path: comments, statusCode: 200, body: an array of invented objects that satisfy the schema.
- Result
- GET {server}/m/{apiId}/comments returns fake but shape-correct data — every object has the five required fields, with the right types.
A schema has no opinion on values
Generate a mock from an OpenAPI spec
One spec can describe several operations — your agent creates one endpoint per operation it finds.
The source
An OpenAPI 3.0 spec covering the same data as the JSON Schema tutorial, this time as two documented operations.
openapi: 3.0.3
info:
title: Comments API
version: "1.0.0"
paths:
/comments:
get:
summary: List comments for a post
responses:
"200":
description: A list of comments
content:
application/json:
schema:
type: array
items:
type: object
required: [postId, id, name, email, body]
properties:
postId:
type: number
id:
type: number
name:
type: string
email:
type: string
body:
type: string
/comments/{id}:
get:
summary: Get a single comment
parameters:
- name: id
in: path
required: true
schema:
type: number
responses:
"200":
description: One comment
content:
application/json:
schema:
type: object
required: [postId, id, name, email, body]
properties:
postId:
type: number
id:
type: number
name:
type: string
email:
type: string
body:
type: stringThe prompt
Here is an OpenAPI spec with two operations:
openapi: 3.0.3
info:
title: Comments API
version: "1.0.0"
paths:
/comments:
get:
summary: List comments for a post
responses:
"200":
description: A list of comments
content:
application/json:
schema:
type: array
items:
type: object
required: [postId, id, name, email, body]
properties:
postId:
type: number
id:
type: number
name:
type: string
email:
type: string
body:
type: string
/comments/{id}:
get:
summary: Get a single comment
parameters:
- name: id
in: path
required: true
schema:
type: number
responses:
"200":
description: One comment
content:
application/json:
schema:
type: object
required: [postId, id, name, email, body]
properties:
postId:
type: number
id:
type: number
name:
type: string
email:
type: string
body:
type: string
Use it to build a mock:
1. Call createApi with name "comments-api".
2. For each path + method in the spec, call createEndpoint once:
- GET /comments → statusCode 200, body: an array of 3 example comments
matching the response schema.
- GET /comments/{id} → path "comments/:id", statusCode 200, body: one
example comment matching the response schema.
3. Reuse the same example values across both endpoints where the shape
overlaps, so the mock reads as one consistent dataset.What your agent does
- createApi
- name: "comments-api".
- createEndpoint (1 of 2)
- method: GET, path: comments, statusCode: 200, body: an example array.
- createEndpoint (2 of 2)
- method: GET, path: comments/:id — the spec's {id} becomes a path parameter — statusCode: 200, body: one example object.
- Result
- Two working endpoints from one spec: a list and a by-id lookup, each answering with data shaped exactly as documented.
A spec's {param} is the platform's :param
Generate a mock from a TypeScript type
No schema at all: your agent reads the type declaration and infers the same shape from it.
The source
No schema, no sample data — just a TypeScript type your agent already understands.
export interface Comment {
postId: number;
id: number;
name: string;
email: string;
body: string;
}The prompt
Here is a TypeScript type, with no schema or sample data attached:
export interface Comment {
postId: number;
id: number;
name: string;
email: string;
body: string;
}
Use it to build a mock:
1. Infer the JSON shape the type describes — one object per Comment, with
postId and id as numbers and the rest as strings.
2. Call createApi with name "comments-from-code".
3. Call createEndpoint with method GET, path "comments", statusCode 200, and
an array of 3 example objects matching the interface as the body.What your agent does
- createApi
- name: "comments-from-code".
- createEndpoint
- method: GET, path: comments, statusCode: 200, body: an array of invented objects matching the interface's fields and types.
- Result
- The same recipe as the JSON Schema tutorial, starting one step earlier — there was never a schema to validate against, only a type declaration to read.
Works for the type your editor already shows you