Skip to content

Commit 874ed1a

Browse files
committed
docs(readme): update
1 parent 543dcb7 commit 874ed1a

File tree

1 file changed

+51
-47
lines changed

1 file changed

+51
-47
lines changed

README.md

Lines changed: 51 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,66 @@ Mock MCP Server - AI-generated mock data based on your **OpenAPI JSON Schema** d
2525

2626
1. **Install the package.** Add mock-mcp as a dev dependency inside your project.
2727

28-
```bash
29-
npm install -D mock-mcp
30-
```
28+
```bash
29+
npm install -D mock-mcp
30+
# or
31+
yarn add -D mock-mcp
32+
# or
33+
pnpm add -D mock-mcp
34+
```
3135

3236
2. **Configure the Model Context Protocol server.** For example, Claude Desktop can launch the binary through npx:
3337

34-
```json
35-
{
36-
"mock-mcp": {
37-
"command": "npx",
38-
"args": ["-y", "mock-mcp@latest"]
39-
}
40-
}
41-
```
38+
```json
39+
{
40+
"mock-mcp": {
41+
"command": "npx",
42+
"args": ["-y", "mock-mcp@latest"]
43+
}
44+
}
45+
```
4246

4347
3. **Connect from your tests.** Use `connect` to retrieve a mock client and request data for intercepted calls.
4448

45-
```ts
46-
import { render, screen, fireEvent } from "@testing-library/react";
47-
import { connect } from "mock-mcp";
48-
49-
const userSchema = {
50-
summary: "Fetch the current user",
51-
response: {
52-
type: "object",
53-
required: ["id", "name"],
54-
properties: {
55-
id: { type: "number" },
56-
name: { type: "string" },
57-
},
58-
},
59-
};
60-
61-
it("example", async () => {
62-
const mockClient = await connect();
63-
const metadata = {
64-
schemaUrl: "https://example.com/openapi.json#/paths/~1user/get",
65-
schema: userSchema,
66-
instructions: "Respond with a single user described by the schema.",
67-
};
68-
69-
fetchMock.get("/user", () =>
70-
mockClient.requestMock("/user", "GET", { metadata })
71-
);
72-
73-
const result = await fetch("/user");
74-
const data = await result.json();
75-
expect(data).toEqual({ id: 1, name: "Jane" });
76-
}); // 10 minute timeout for AI interaction
77-
```
49+
```ts
50+
import { render, screen, fireEvent } from "@testing-library/react";
51+
import { connect } from "mock-mcp";
52+
53+
const userSchema = {
54+
summary: "Fetch the current user",
55+
response: {
56+
type: "object",
57+
required: ["id", "name"],
58+
properties: {
59+
id: { type: "number" },
60+
name: { type: "string" },
61+
},
62+
},
63+
};
64+
65+
it("example", async () => {
66+
const mockClient = await connect();
67+
const metadata = {
68+
schemaUrl: "https://example.com/openapi.json#/paths/~1user/get",
69+
schema: userSchema,
70+
instructions: "Respond with a single user described by the schema.",
71+
};
72+
73+
fetchMock.get("/user", () =>
74+
mockClient.requestMock("/user", "GET", { metadata })
75+
);
76+
77+
const result = await fetch("/user");
78+
const data = await result.json();
79+
expect(data).toEqual({ id: 1, name: "Jane" });
80+
}); // 10 minute timeout for AI interaction
81+
```
7882

7983
4. **Run with MCP enabled.** Prompt your AI client to run the persistent test command and provide mocks through the tools.
8084

81-
```
82-
Please run the persistent test: `MOCK_MCP=true npm test test/example.test.tsx` and mock fetch data with mock-mcp
83-
```
85+
```
86+
Please run the persistent test: `MOCK_MCP=true npm test test/example.test.tsx` and mock fetch data with mock-mcp
87+
```
8488

8589
## Why Mock MCP
8690

0 commit comments

Comments
 (0)