create_tests_from_spec
Compile a hand-edited functional-requirements spec (.3tg.md) into actual Jest/Vitest tests. This is "Flow B" — the user has already authored or reviewed the .3tg.md and is ready to materialise the rows into a runnable test file. Use this *instead of* create_tests when the user wants their hand-cu...
This record as markdown: /tools/dev-3tg-mcp/create-tests-from-spec.md
What create_tests_from_spec does on 3TG Test Generation
AI agents use create_tests_from_spec to create or update resources in 3TG Test Generation, usually the action step of a workflow, after the agent has gathered context. Every call changes real data in your 3TG Test Generation environment.
| Parameter | Type | Required | Description |
|---|---|---|---|
clientId | string | Yes | The 3tg.dev client ID. |
fileName | string | Yes | Path of the source file relative to the user's project root (e.g. "src/foo/bar.ts"). The spec filename is derived as the same path with `.ts` / `.tsx` replaced |
settings | object | — | Subset of .3tg/settings.json relevant to this tool. |
cliConfig | object | — | Optional per-request 3TG CLI config. The agent assembles this from TWO disk locations and merges them (per-source wins on conflict) before forwarding the merged |
moduleType | string | — | Optional Node module type of the consumer project — the value of the `type` field in the project root's `package.json`. The agent reads that one field (only) an |
sourceCode | string | Yes | Full UTF-8 contents of the source file. |
specContent | string | Yes | Full UTF-8 contents of the `.3tg.md` spec — as the user has edited it locally under `.3tg/<sourceDir>/<basename>.3tg.md`. |
Parameters from the server's own tool schema.
Why create_tests_from_spec is rated Medium
This tool creates new test files from specification input. While file creation is a write operation (reversible), the impact is constrained to test artifacts in a development/sandbox context. It does not execute tests, delete data irreversibly, or cause external side effects.
From the tool's definition Tool description states it will "materialise the rows into a runnable test file" and "3TG also writes a `<ba[sename>...` indicating file creation/output generation.
Risk signalsAccepts file system path (fileName) · High parameter count (12 properties) · Admin/system-level operation
Attacks that exploit this kind of access
The rule that runs create_tests_from_spec safely
PolicyLayer is an MCP gateway: it sits between your AI agents and 3TG Test Generation, and checks every tool call against a rule you set before the call runs. Nothing changes on the server itself. For create_tests_from_spec, this is the rule to start with:
create_tests_from_spec stays usable, but capped: an agent stuck in a loop can't make hundreds of changes a minute. Everything else on the server is denied unless you say otherwise.
The button opens the PolicyLayer dashboard: create your workspace, connect 3TG Test Generation, apply this rule, and every create_tests_from_spec call is checked against it from then on.
Questions about create_tests_from_spec
Compile a hand-edited functional-requirements spec (.3tg.md) into actual Jest/Vitest tests. This is "Flow B" — the user has already authored or reviewed the .3tg.md and is ready to materialise the rows into a runnable test file. Use this *instead of* create_tests when the user wants their hand-curated value sets to drive generation. Inputs: the source code plus the spec content (the spec lives at .3tg/<sourceDir>/<basename>.3tg.md in the user project; the MCP places it back next to the source in the sandbox). AI enrichment is NOT run — the spec is authoritative. 3TG also writes a <basename>.md.3tg.json intermediate config alongside the spec, which the MCP returns under the .3tg/ mirror so the user can inspect what the spec compiled to. Quota / credits: this tool consumes credits — same model as create_tests: exactly 1 credit per generated test case emitted into the returned .test.ts / .test.tsx. The number of rows in your .3tg.md table is therefore a reliable upper bound on what the call will cost. Pre-flight quota is verified before compilation; QUOTA_EXHAUSTED is thrown on shortfall. Flow B cliConfig caveat — spec-authoritative keys are STRIPPED. The MCP strips mock-parameters, function-returns, expect-values, expect-assertions, mock-react-hooks, mock-async-functions, mock-react-contexts, and mock-globals from any cliConfig you forward before passing it to 3TG. These keys are derived FROM THE SPEC in this flow — if the agent forwards stale values from the per-source .md.3tg.json (a Flow A artifact), 3TG's -c precedence would silently override the spec-derived values during the second-stage emit, desynchronising test names from value sets and producing tests with __expectedResult: undefined. For Flow B, forward ONLY global/structural config keys (rules.*, creationMode, mockAsFunction, no-rule-default-true, ignore, package.json.type, …) — the spec owns the test-value plan. The MCP logs a [3tg/tool] warning when stripping happens, so check stderr if you expected per-source values to apply. CRITICAL POST-CALL ACTION — write returned files to disk: The MCP server does NOT touch the user's filesystem. It returns the generated file CONTENTS in the response's files array. After this tool returns, you MUST iterate over files and write each entry's content verbatim to its path using your native file-write capability (e.g. Write / edit_file / create_file — whatever your client exposes). Create parent directories as needed. Returned paths are project-root-relative and already translated to the .3tg/ mirror convention where applicable (e.g. specs land under .3tg/<source-path>.3tg.md; tests / mocks travel through unchanged). Write each path verbatim. Do NOT claim "Generated test file: <path>" unless you have actually written the file. The user will assume the MCP wrote it and waste time looking for a non-existent file. If you can't write for some reason (permission denied, no write capability in this client), return the contents inline in your message so the user can copy-paste them. Never report success silently when the write didn't happen. It is categorised as a Write tool in the 3TG Test Generation MCP Server, which means it can create or modify data. Consider rate limits to prevent runaway writes.
create_tests_from_spec accepts 7 parameters: clientId, fileName, settings, cliConfig, moduleType, sourceCode, specContent. Required: clientId, fileName, sourceCode, specContent. The full parameter table on this page comes from the server's own tool schema.
Register the 3TG Test Generation MCP server in PolicyLayer and add a rule for create_tests_from_spec: allow, deny, rate-limit, or require approval. Point your MCP client at the PolicyLayer proxy URL and the rule is enforced on every call, before it reaches 3TG Test Generation. Nothing to install.
create_tests_from_spec is a Write tool with medium risk. Write tools should be rate-limited to prevent accidental bulk modifications.
Yes. Add a rate_limit block to the create_tests_from_spec rule in your PolicyLayer policy. For example, setting max: 10 and window: 60 limits the tool to 10 calls per minute. Rate limits are tracked per agent session and reset automatically.
Set action: deny in the PolicyLayer policy for create_tests_from_spec. The AI agent will receive a policy violation error and cannot call the tool. You can also include a reason field to explain why the tool is blocked.
create_tests_from_spec is provided by the 3TG Test Generation MCP server (https://mcp.3tg.dev/mcp). PolicyLayer sits as a proxy in front of this server to enforce policies before tool calls reach the server.
More on 3TG Test Generation, and thousands of servers like it.
This server
Across the catalogue