proxy_mock_response
Create mock HTTP responses for matched requests to simulate API behavior, test error handling, or develop without live backends.
Instructions
Return a mock response for matched requests. Creates a mock rule.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| method | No | HTTP method to match (optional) | |
| url_pattern | No | URL regex pattern to match (optional) | |
| hostname | No | Hostname to match (optional) | |
| status | Yes | Response status code | |
| body | No | Response body | |
| content_type | No | Content-Type header | application/json |
| priority | No | Rule priority (default: 10, high priority) |
Implementation Reference
- src/tools/modification.ts:98-142 (handler)The handler and registration for the 'proxy_mock_response' tool. It creates a mock rule using the 'proxyManager'.
server.tool( "proxy_mock_response", "Return a mock response for matched requests. Creates a mock rule.", { method: z.string().optional().describe("HTTP method to match (optional)"), url_pattern: z.string().optional().describe("URL regex pattern to match (optional)"), hostname: z.string().optional().describe("Hostname to match (optional)"), status: z.number().describe("Response status code"), body: z.string().optional().default("").describe("Response body"), content_type: z.string().optional().default("application/json").describe("Content-Type header"), priority: z.number().optional().default(10).describe("Rule priority (default: 10, high priority)"), }, async ({ method, url_pattern, hostname, status, body, content_type, priority }) => { try { const matcher: RuleMatcher = {}; if (method) matcher.method = method; if (url_pattern) matcher.urlPattern = url_pattern; if (hostname) matcher.hostname = hostname; const handler: RuleHandler = { type: "mock", status, body: body ?? "", headers: { "content-type": content_type ?? "application/json" }, }; const rule = await proxyManager.addRule({ priority, enabled: true, description: `Mock ${status} for ${method || "ANY"} ${url_pattern || hostname || "*"}`, matcher, handler, }); return { content: [{ type: "text", text: JSON.stringify({ status: "success", rule_id: rule.id, description: rule.description }), }], }; } catch (e) { return { content: [{ type: "text", text: JSON.stringify({ status: "error", error: String(e) }) }] }; } }, );