thunderclient-mcp 1.0.12 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/tools/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAK1D,UAAU,cAAc,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAChF;AAmBD,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;CAwClB,CAAC;AAEX,eAAO,MAAM,KAAK,EAAE,IAAI,EAIrB,CAAC;AAEJ,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;CAExB,CAAC;AAEF,eAAO,MAAM,SAAS,EAEjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5B,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtF,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,QAAQ,IAAI,CAAC,CAAC,KAAK,CAC9C,CAAC,OAAO,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,OAAO,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CACpF,CAAC"}
1
+ {"version":3,"file":"definitions.d.ts","sourceRoot":"","sources":["../../src/tools/definitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,SAAS,EAAE,MAAM,KAAK,CAAC;AACnC,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAG1D,UAAU,cAAc,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAChF;AAuED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4RlB,CAAC;AAqBX,eAAO,MAAM,KAAK,EAAE,IAAI,EAKrB,CAAC;AAEJ,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAExB,CAAC;AAEF,eAAO,MAAM,SAAS,EAEjB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAE5B,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtF,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,QAAQ,IAAI,CAAC,CAAC,KAAK,CAC9C,CAAC,OAAO,eAAe,CAAC,CAAC,OAAO,CAAC,MAAM,OAAO,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CACpF,CAAC"}
@@ -1,61 +1,358 @@
1
1
  import { z } from "zod";
2
2
  import { zodToMCPInputSchema } from "../utils/schema-converter.js";
3
- import { resolve } from "path";
4
- import { execSync } from 'child_process';
5
3
  function defineTool(definition) {
6
4
  return definition;
7
5
  }
8
- // Helper function to resolve project directory
9
- function resolveProjectDir(projectDir) {
10
- if (projectDir === "." || projectDir === "./") {
11
- // Execute pwd command and get the current working directory
12
- const currentDir = execSync('pwd', { encoding: 'utf8' }).trim();
13
- return currentDir;
14
- }
15
- return resolve(projectDir);
16
- }
6
+ // Shared parameter descriptions
7
+ const projectDirDesc = "Absolute path to the project root directory. Example: '/Users/john/my-project'.";
8
+ const authSchema = z.object({
9
+ type: z.enum(["none", "inherit", "basic", "bearer", "oauth2", "ntlm", "aws"])
10
+ .describe("Authentication type. 'inherit' uses the parent collection's auth settings. 'aws' and 'ntlm' are rejected: their credentials must be set in the Thunder Client UI."),
11
+ bearer: z.string().optional()
12
+ .describe("Bearer token value. Required when type is 'bearer'. Supports environment variables e.g. '{{accessToken}}'."),
13
+ basic: z.object({
14
+ username: z.string().describe("Username. Supports environment variables e.g. '{{username}}'."),
15
+ password: z.string().describe("Password. Supports environment variables e.g. '{{password}}'."),
16
+ }).optional()
17
+ .describe("Basic auth credentials. Required when type is 'basic'."),
18
+ oauth2: z.object({
19
+ grantType: z.enum(["client_credentials", "password", "authorization_code", "implicit"])
20
+ .describe("OAuth2 grant type."),
21
+ tokenUrl: z.string()
22
+ .describe("Token endpoint URL. Example: 'https://auth.example.com/oauth/token'"),
23
+ authUrl: z.string().optional()
24
+ .describe("Authorization endpoint URL. Required for 'authorization_code' and 'implicit' grant types. Example: 'https://auth.example.com/oauth/authorize'"),
25
+ clientId: z.string()
26
+ .describe("Client ID. Supports environment variables e.g. '{{clientId}}'."),
27
+ clientSecret: z.string()
28
+ .describe("Client secret. Supports environment variables e.g. '{{clientSecret}}'."),
29
+ username: z.string().optional()
30
+ .describe("Resource owner username. Required for 'password' grant type."),
31
+ password: z.string().optional()
32
+ .describe("Resource owner password. Required for 'password' grant type."),
33
+ scope: z.string().optional()
34
+ .describe("Space-separated list of requested scopes. Example: 'read write'"),
35
+ clientAuth: z.enum(["in-header", "in-body"]).optional()
36
+ .describe("How to send client credentials. Defaults to 'in-header'."),
37
+ }).optional()
38
+ .describe("OAuth2 configuration. Required when type is 'oauth2'. Example: {grantType:'client_credentials',tokenUrl:'https://auth.example.com/token',clientId:'{{clientId}}',clientSecret:'{{clientSecret}}'}"),
39
+ });
40
+ const authExamples = "Examples — bearer: {type:'bearer',bearer:'{{accessToken}}'} | basic: {type:'basic',basic:{username:'{{user}}',password:'{{pass}}'}} | oauth2: {type:'oauth2',oauth2:{grantType:'client_credentials',tokenUrl:'https://auth.example.com/token',clientId:'{{clientId}}',clientSecret:'{{clientSecret}}'}} | inherit: {type:'inherit'}";
41
+ const testsSchema = z.array(z.object({
42
+ type: z.enum(["res-code", "res-body", "res-time", "json-query", "Content-Type", "Content-Length", "custom-header", "set-env-var"])
43
+ .describe("Assertion type. 'res-code'=HTTP status code, 'json-query'=JSON field check, 'res-body'=raw body text, 'res-time'=response time in ms, 'Content-Type'/'Content-Length'=response headers, 'custom-header'=any response header, 'set-env-var'=extract a value to an environment variable."),
44
+ custom: z.string().optional()
45
+ .describe("Path or key for the assertion target. Required for 'json-query', 'set-env-var', and 'custom-header'. JSON path examples: 'json.field', 'json.a.b.c' (nested), 'json[0].field' (array index), 'json[-1].field' (last item), 'json.items[*].id' (all items), 'json.items[name=thunder].id' (filter by field value), 'json[\"key.with.dots\"]' (quoted key). Use bracket notation for array indices — 'json[0].id' is correct, 'json.0.id' is not. For 'custom-header': the header name only, e.g. 'X-Request-Id'. In 'json-query' and 'set-env-var', read a response header with 'header.Content-Type' and a cookie with 'cookie.name'. For raw body: 'text'."),
46
+ action: z.enum(["equal", "notequal", "contains", "notcontains", "istype", "isjson", "setto", "regex", ">", ">=", "<", "<="])
47
+ .describe("Comparison operator. 'istype' checks the value type (string/number/array/object/boolean/null). 'setto' extracts a value and is used with 'set-env-var'. Numeric operators (>, >=, <, <=) apply to 'res-time'."),
48
+ value: z.string().optional()
49
+ .describe("Expected value. For 'res-code': '200'. For 'istype': string/number/array/object/boolean/null. For 'res-time': milliseconds e.g. '500'. For 'set-env-var': must be a {{varName}} placeholder e.g. '{{authToken}}'. For 'regex': the pattern string."),
50
+ }));
51
+ const testsExamples = "Examples — status: {type:'res-code',action:'equal',value:'200'} | JSON field: {type:'json-query',custom:'json.id',action:'istype',value:'number'} | array item: {type:'json-query',custom:'json[0].name',action:'equal',value:'John'} | response time: {type:'res-time',action:'<=',value:'2000'} | extract to env: {type:'set-env-var',custom:'json.token',action:'setto',value:'{{accessToken}}'} | response header: {type:'custom-header',custom:'X-Request-Id',action:'contains',value:'req-'}";
52
+ const preReqSchema = z.object({
53
+ inlineScripts: z.array(z.string()).optional()
54
+ .describe("JavaScript statements to execute before the request is sent. Each array item is one statement. Example: [\"tc.setVar('timestamp', Date.now().toString())\", \"tc.request.setHeader('X-Nonce', tc.getVar('nonce'))\"] — read tc://docs for the full scripting API reference."),
55
+ });
56
+ const postReqSchema = z.object({
57
+ inlineScripts: z.array(z.string()).optional()
58
+ .describe("JavaScript statements to execute after the response is received. Each array item is one statement. Use tc.response.json, tc.response.status, tc.response.headers to read the response. Use tc.setVar() to extract values. Use tc.test(name, bool) to write assertions. Example: [\"tc.test('ok', tc.response.status === 200)\", \"tc.setVar('userId', tc.response.json.id?.toString())\"] — read tc://docs for the full scripting API reference."),
59
+ });
60
+ const docsDesc = "Documentation for this item. Array of markdown strings. Use the field name 'docs' — not 'notes' or 'description'. Example: ['## Create User', 'Creates a new user account.', '**Returns:** the created user id']";
17
61
  export const toolDefinitions = {
62
+ thunder_debug: defineTool({
63
+ name: "debugInfo",
64
+ description: "Returns Thunder Client setup info: CLI version, data path, collection names, and environment names. Run this first before any other tool. Environment variable values are never returned. If no environment exists, ask the user to create one in Thunder Client UI — never create or write environment files directly.",
65
+ schema: z.object({
66
+ projectDir: z.string().min(1, "projectDir is required")
67
+ .describe(projectDirDesc),
68
+ }),
69
+ handler: async (client, args) => client.runDebug(args.projectDir),
70
+ }),
71
+ thunder_list: defineTool({
72
+ name: "listCollections",
73
+ description: "Returns a flat list of all collections, folders, and requests with their _id, name, type, method, and parent info. Use this to discover existing items and obtain IDs before calling other tools. Also returns 'summary', one row per collection as {colId, name, folders, requests}. When the user asks to see or list collections, show 'summary' as a table with the columns #, Collection, Collection ID, Folders, Requests. Set includeActivity to true only when the user explicitly asks to see Activity tab requests.",
74
+ schema: z.object({
75
+ projectDir: z.string().min(1, "projectDir is required")
76
+ .describe(projectDirDesc),
77
+ includeActivity: z.boolean().optional()
78
+ .describe("When true, includes Activity tab requests in the result with type 'activity'. These are recently run requests with colId 'history' that have not been saved to a named collection. To save one, use the Thunder Client UI — right-click the request in the Activity tab and choose 'Add to Collection'. Default: false."),
79
+ }),
80
+ handler: async (client, args) => client.getList(args.projectDir, args.includeActivity ?? false),
81
+ }),
82
+ thunder_list_by_id: defineTool({
83
+ name: "getDetails",
84
+ description: "Returns full details of a single collection, folder, or request by its _id. For a request: returns url, method, headers, params, body, auth, tests, and scripts. Sensitive auth values are masked. For a collection, also returns 'outline': a nested markdown list of its folders and requests. When showing a collection to the user, print only the collection name, its _id and 'outline' exactly as given. Do not show collection settings, folder settings or request URLs, headers, bodies or tests unless the user asks for them. Use listCollections first to obtain the _id. Do not use this to read environment files — environment variable values are never returned.",
85
+ schema: z.object({
86
+ id: z.string().min(1, "id is required")
87
+ .describe("The _id of the collection, folder, or request to retrieve. Obtain from listCollections. Example: 'e63218fb-9f0b-4619-ab3a-bd68d21b4d57'"),
88
+ projectDir: z.string().min(1, "projectDir is required")
89
+ .describe(projectDirDesc),
90
+ }),
91
+ handler: async (client, args) => client.getListById(args.id, args.projectDir),
92
+ }),
93
+ thunder_list_environments: defineTool({
94
+ name: "listEnvironments",
95
+ description: "Returns all Thunder Client environments in the project, including which one is currently active. Environment variable values are never returned — only names and IDs are listed. Use this to verify an active environment exists before running requests that use {{varName}} placeholders. If no environment exists, ask the user to create one in Thunder Client UI — never create or write environment files directly.",
96
+ schema: z.object({
97
+ projectDir: z.string().min(1, "projectDir is required")
98
+ .describe(projectDirDesc),
99
+ }),
100
+ handler: async (client, args) => client.listEnvironments(args.projectDir),
101
+ }),
102
+ thunder_create_collection: defineTool({
103
+ name: "createCollection",
104
+ description: "Creates a new collection in Thunder Client, and optionally a folder inside it. If the collection already exists, returns success without error. After creation, use updateCollectionSettings to configure baseUrl, shared auth, or default headers.",
105
+ schema: z.object({
106
+ projectDir: z.string().min(1, "projectDir is required")
107
+ .describe(projectDirDesc),
108
+ collection: z.string().min(1, "collection is required")
109
+ .describe("Name of the collection to create. Example: 'Payments API'"),
110
+ folder: z.string().optional()
111
+ .describe("Name of a top-level folder to create inside the collection. Omit to create the collection only. Example: 'Auth'"),
112
+ }),
113
+ handler: async (client, args) => {
114
+ const projectDir = args.projectDir;
115
+ const colResult = await client.createCollection({ projectDir, collectionName: args.collection });
116
+ if (!colResult.success && !(colResult.error || "").includes("already exists")) {
117
+ return colResult;
118
+ }
119
+ if (args.folder) {
120
+ return client.createFolder({ projectDir, collectionName: args.collection, folderName: args.folder });
121
+ }
122
+ return colResult.success ? colResult : { success: true, message: `Collection '${args.collection}' already exists.` };
123
+ },
124
+ }),
125
+ thunder_create_folder: defineTool({
126
+ name: "createFolder",
127
+ description: "Creates a folder inside an existing Thunder Client collection. Supports one level of nesting — provide parentFolderName to create a subfolder inside an existing top-level folder. Use listCollections to confirm collection and parent folder names before calling.",
128
+ schema: z.object({
129
+ projectDir: z.string().min(1, "projectDir is required")
130
+ .describe(projectDirDesc),
131
+ collectionName: z.string().min(1, "collectionName is required")
132
+ .describe("Name of the collection to create the folder in. Must match an existing collection name (case-insensitive)."),
133
+ folderName: z.string().min(1, "folderName is required")
134
+ .describe("Name of the new folder. Example: 'Users'"),
135
+ parentFolderName: z.string().optional()
136
+ .describe("Name of an existing top-level folder to nest the new folder inside. Omit to create a top-level folder. Example: 'Users' to create 'Users > Admin'."),
137
+ }),
138
+ handler: async (client, args) => client.createFolder({ ...args, projectDir: args.projectDir }),
139
+ }),
18
140
  thunder_curl: defineTool({
19
- name: "tc_create",
20
- description: "Create API endpoints to Thunder Client, automatically creating collections and folders if they do not already exist.",
21
- keywords: ["thunder client", "thunder client mcp", "tc mcp", "thunder mcp", "thunderclient"],
22
- schema: z
23
- .object({
24
- curlInput: z
25
- .string()
26
- .min(5, { message: "curlInput must be at least 5 characters long" })
27
- .refine(val => val.trim().toLowerCase().startsWith("curl "), {
28
- message: "curlInput must start with 'curl '",
29
- }),
30
- name: z.string().min(2, { message: "Name must be at least 2 characters" }),
31
- collection: z.string().optional(),
32
- folder: z.string().optional(),
33
- projectDir: z.string()
34
- .min(1, "projectDir is required")
35
- .describe("Get the full path to the project's directory (use process.cwd() and get it)."),
36
- })
37
- .refine(data => !(data.folder && !data.collection), {
38
- message: "If 'folder' is provided, you must also provide 'collection'.",
39
- path: ["collection"],
40
- }),
41
- handler: async (client, args) => client.runCurl({ ...args, projectDir: resolveProjectDir(args.projectDir.trim()) }),
141
+ name: "createRequest",
142
+ description: "Creates a new API request in Thunder Client from a curl command string. Use this for new requests only — to modify an existing request, use updateRequest instead. The curl string is parsed to extract URL, method, headers, and body. Optionally saves into a collection and folder. If no collection is provided, the request is saved to Activity only.",
143
+ schema: z.object({
144
+ projectDir: z.string().min(1, "projectDir is required")
145
+ .describe(projectDirDesc),
146
+ curlInput: z.string().min(1, "curlInput is required")
147
+ .describe("A valid curl command string. Must start with 'curl '. Include query parameters directly in the URL — e.g. 'curl https://api.example.com/posts?postId=1&limit=5'. Example: \"curl https://api.example.com/users -X POST -H 'Content-Type: application/json' -d '{\\\"name\\\":\\\"John\\\"}'\""),
148
+ name: z.string().min(1, "name is required")
149
+ .describe("Display name for the request. Example: 'Create User'"),
150
+ collection: z.string().optional()
151
+ .describe("Name of the collection to save the request into. If omitted, the request is saved to Activity only."),
152
+ folder: z.string().optional()
153
+ .describe("Name of the folder within the collection to save the request into. Requires collection to be set."),
154
+ auth: authSchema.optional()
155
+ .describe("Authentication configuration. Omit if the Authorization header is already present in the curl command. " + authExamples),
156
+ tests: testsSchema.optional()
157
+ .describe("Test assertions to run after the response. " + testsExamples),
158
+ preReq: preReqSchema.optional()
159
+ .describe("Pre-request script. Runs before the request is sent."),
160
+ postReq: postReqSchema.optional()
161
+ .describe("Post-request script. Runs after the response is received. Use tc.setVar() here to extract values to environment variables."),
162
+ docs: z.array(z.string()).optional()
163
+ .describe(docsDesc),
164
+ }),
165
+ handler: async (client, args) => client.createRequest({ ...args, projectDir: args.projectDir }),
42
166
  }),
43
- thunder_debug: defineTool({
44
- name: "tc_debug",
45
- description: "Runs the Thunder Client debug command and display the result.",
46
- keywords: ["thunder client", "thunder client mcp", "tc mcp", "thunder mcp", "thunderclient"],
167
+ thunder_edit_request: defineTool({
168
+ name: "updateRequest",
169
+ description: "Updates an existing Thunder Client request by its ID. Only the fields provided are modified — omitted fields retain their current values. To rename only, provide reqId and name. Moving a request to a different collection or folder is not supported — use Thunder Client UI for that.",
170
+ schema: z.object({
171
+ reqId: z.string().min(1, "reqId is required")
172
+ .describe("The _id of the request to update. Obtain from listCollections. Example: 'e63218fb-9f0b-4619-ab3a-bd68d21b4d57'"),
173
+ projectDir: z.string().min(1, "projectDir is required")
174
+ .describe(projectDirDesc),
175
+ name: z.string().optional()
176
+ .describe("New display name for the request. Example: 'Create User'"),
177
+ url: z.string().optional()
178
+ .describe("Request URL. If the collection has a baseUrl set in settings, provide the path only e.g. '/users/{{userId}}'. Otherwise provide the full URL. Do not use '{{baseUrl}}' as a prefix — Thunder Client prepends the baseUrl automatically."),
179
+ method: z.string().optional()
180
+ .describe("HTTP method. Accepted values: GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS."),
181
+ headers: z.array(z.object({
182
+ name: z.string().describe("Header name. Example: 'Content-Type'"),
183
+ value: z.string().describe("Header value. Example: 'application/json'"),
184
+ isDisabled: z.boolean().optional().describe("When true, the header is saved but not sent."),
185
+ })).optional()
186
+ .describe("Request headers. Replaces all existing headers — include every header that should be present. Example: [{name:'Content-Type',value:'application/json'},{name:'X-Api-Key',value:'{{apiKey}}'}]"),
187
+ params: z.array(z.object({
188
+ name: z.string().describe("Parameter name."),
189
+ value: z.string().describe("Parameter value. Supports environment variables e.g. '{{userId}}'."),
190
+ isPath: z.boolean().optional().describe("When true, treated as a path parameter. The URL must use {name} token syntax, e.g. url '/users/{id}' with param name 'id'. When false or omitted, treated as a query parameter."),
191
+ isDisabled: z.boolean().optional().describe("When true, the parameter is saved but not sent."),
192
+ })).optional()
193
+ .describe("Query or path parameters. Replaces all existing parameters. Example: [{name:'page',value:'1'},{name:'limit',value:'10'}]"),
194
+ body: z.object({
195
+ type: z.enum(["none", "json", "text", "xml", "formdata", "formencoded", "graphql", "binary"])
196
+ .describe("Body content type. 'json'=JSON payload (use raw field), 'text'=plain text (use raw field), 'xml'=XML (use raw field), 'graphql'=GraphQL query (use raw field), 'formencoded'=URL-encoded form (use form field), 'formdata'=multipart form (use form field), 'none'=no body, 'binary'=binary file (not supported via MCP)."),
197
+ raw: z.string().optional()
198
+ .describe("Raw body string. Used for json, text, xml, and graphql body types. Supports environment variables. Example for JSON: '{\"name\":\"John\",\"age\":30}'. Example for GraphQL: '{\"query\":\"{ users { id name } }\"}'."),
199
+ form: z.array(z.object({
200
+ name: z.string(),
201
+ value: z.string(),
202
+ })).optional()
203
+ .describe("Form fields. Used for formdata and formencoded body types. Example: [{name:'username',value:'{{username}}'},{name:'password',value:'{{password}}'}]"),
204
+ }).optional()
205
+ .describe("Request body. Examples — JSON: {type:'json',raw:'{\"title\":\"Hello\"}'} | form: {type:'formencoded',form:[{name:'email',value:'{{email}}'}]} | GraphQL: {type:'graphql',raw:'{\"query\":\"{ me { id } }\"}'}"),
206
+ auth: authSchema.optional()
207
+ .describe("Authentication configuration. Replaces the existing auth setting. " + authExamples),
208
+ tests: testsSchema.optional()
209
+ .describe("Test assertions. Replaces all existing tests. " + testsExamples),
210
+ preReq: preReqSchema.optional()
211
+ .describe("Pre-request script. Replaces the existing pre-request script."),
212
+ postReq: postReqSchema.optional()
213
+ .describe("Post-request script. Replaces the existing post-request script."),
214
+ docs: z.array(z.string()).optional()
215
+ .describe(docsDesc),
216
+ }),
217
+ handler: async (client, args) => client.editRequest({ ...args, projectDir: args.projectDir }),
218
+ }),
219
+ thunder_set_settings: defineTool({
220
+ name: "updateCollectionSettings",
221
+ description: "Sets or updates settings on a Thunder Client collection or folder. Settings are inherited by all requests inside — use this to configure shared auth, default headers, base URL, and run options. Only the fields provided are updated; existing settings are preserved. Pass createIfNotExists to auto-create the collection if it does not exist. Pass newName to rename the collection or folder — can be combined with settings changes or used alone.",
222
+ schema: z.object({
223
+ projectDir: z.string().min(1, "projectDir is required")
224
+ .describe(projectDirDesc),
225
+ collectionName: z.string().min(1, "collectionName is required")
226
+ .describe("Name of the collection to update. Must match an existing collection name."),
227
+ folderName: z.string().optional()
228
+ .describe("Name of the folder to update settings on. Omit to apply settings at the collection level."),
229
+ newName: z.string().optional()
230
+ .describe("Renames the collection or folder. When folderName is provided, renames that folder; otherwise renames the collection. Can be used alone or combined with settings changes."),
231
+ createIfNotExists: z.boolean().optional()
232
+ .describe("When true, creates the collection if it does not already exist. Default: false."),
233
+ settings: z.object({
234
+ auth: authSchema.optional()
235
+ .describe("Default authentication inherited by all requests in this collection or folder that have auth type 'inherit'. " + authExamples),
236
+ headers: z.array(z.object({
237
+ name: z.string(),
238
+ value: z.string(),
239
+ isDisabled: z.boolean().optional(),
240
+ })).optional()
241
+ .describe("Default headers added to every request. Example: [{name:'X-Api-Key',value:'{{apiKey}}'}]"),
242
+ tests: testsSchema.optional()
243
+ .describe("Default tests applied to every request in this collection or folder. " + testsExamples),
244
+ envId: z.string().optional()
245
+ .describe("ID of the environment to associate with this collection."),
246
+ docs: z.array(z.string()).optional()
247
+ .describe("Documentation for this collection or folder. Array of markdown strings."),
248
+ options: z.object({
249
+ baseUrl: z.string().optional()
250
+ .describe("Base URL prepended to all request URLs in this collection. Example: 'https://api.example.com'. Once set, request URLs should be paths only e.g. '/users'."),
251
+ }).optional()
252
+ .describe("Collection-level options."),
253
+ preReq: preReqSchema.optional()
254
+ .describe("Pre-request script applied before every request in this collection or folder."),
255
+ postReq: postReqSchema.optional()
256
+ .describe("Post-request script applied after every request in this collection or folder."),
257
+ runOptions: z.object({
258
+ iterations: z.number().optional()
259
+ .describe("Number of times to repeat the collection run. Default: 1."),
260
+ delay: z.number().optional()
261
+ .describe("Delay in milliseconds between requests. Default: 0."),
262
+ dataFilePath: z.string().optional()
263
+ .describe("Relative path to a CSV data file for parameterised runs. Example: 'data/users.csv'"),
264
+ stopOnFail: z.boolean().optional()
265
+ .describe("When true, stops the run after the first failed request."),
266
+ concurrent: z.number().optional()
267
+ .describe("Number of requests to run concurrently. Default: 1 (sequential)."),
268
+ runType: z.string().optional()
269
+ .describe("Run mode. Use 'performance' for load testing."),
270
+ vusers: z.number().optional()
271
+ .describe("Number of virtual users for performance runs."),
272
+ duration: z.number().optional()
273
+ .describe("Duration in minutes for performance runs."),
274
+ perfType: z.string().optional()
275
+ .describe("Performance run type e.g. 'fixed'."),
276
+ }).optional()
277
+ .describe("Default run options for the collection runner. Example: {iterations:3,delay:500,stopOnFail:true}"),
278
+ }).optional()
279
+ .describe("Settings to apply. Omit entirely when using only newName to rename."),
280
+ }),
281
+ handler: async (client, args) => client.setSettings({ ...args, projectDir: args.projectDir }),
282
+ }),
283
+ thunder_run: defineTool({
284
+ name: "runRequest",
285
+ description: "Executes a single Thunder Client request by name or ID and returns the response. Automatically uses the active environment — omit env unless a specific override is needed. Returns the raw CLI output including status code, response body, and test results.",
286
+ schema: z.object({
287
+ nameOrId: z.string().min(1, "nameOrId is required")
288
+ .describe("Name or _id of the request to execute. Obtain from listCollections."),
289
+ projectDir: z.string().min(1, "projectDir is required")
290
+ .describe(projectDirDesc),
291
+ env: z.string().optional()
292
+ .describe("Environment name to use for this run. Omit to use the active environment automatically. Example: 'staging'"),
293
+ }),
294
+ handler: async (client, args) => client.runRequest({ ...args, projectDir: args.projectDir }),
295
+ }),
296
+ thunder_run_collection: defineTool({
297
+ name: "runCollection",
298
+ description: "Runs all requests in a Thunder Client collection (or a specific folder) and returns the full test report. Automatically uses the active environment. Returns per-request pass/fail results, test assertion details, response times, and a summary with total / passed / failed / skipped counts for iterations and requests, plus test assertion counts. When showing the result, always end with a section headed '**Summary Report**' containing a markdown table with columns 'Name', 'Total', 'Passed', 'Failed', 'Skipped' and exactly two rows: 'Total Iterations' from summary.iterations and 'Total Requests' from summary.requests.",
47
299
  schema: z.object({
48
- projectDir: z.string()
49
- .min(1, "projectDir is required")
50
- .describe("Get the full path to the project's directory (use process.cwd() and get it)."),
300
+ projectDir: z.string().min(1, "projectDir is required")
301
+ .describe(projectDirDesc),
302
+ collectionName: z.string().min(1, "collectionName is required")
303
+ .describe("Name of the collection to run. Obtain the exact name from listCollections."),
304
+ folderName: z.string().optional()
305
+ .describe("Name of a folder within the collection to run. Omit to run all requests in the collection."),
306
+ env: z.string().optional()
307
+ .describe("Environment name to use for this run. Omit to use the active environment automatically."),
308
+ stopOnFail: z.boolean().optional()
309
+ .describe("When true, stops the run after the first failed request. Default: false."),
310
+ iterations: z.number().int().min(1).optional()
311
+ .describe("Number of times to repeat the full collection run. Default: 1."),
312
+ delay: z.number().int().min(0).optional()
313
+ .describe("Delay in milliseconds between requests. Default: 0."),
314
+ concurrent: z.number().int().min(1).optional()
315
+ .describe("Number of requests to run concurrently. Default: 1 (sequential)."),
316
+ report: z.array(z.enum(["html", "json", "xml", "nunit", "csv"])).optional()
317
+ .describe("Report file formats to save in the project's thunder-reports folder. Omit to save no report files — the run result is returned either way. Example: ['html']"),
51
318
  }),
52
- handler: async (client, args) => client.runDebug(resolveProjectDir(args.projectDir.trim())),
319
+ handler: async (client, args) => client.runCollection({ ...args, projectDir: args.projectDir }),
53
320
  }),
321
+ thunder_delete_request: defineTool({
322
+ name: "deleteRequest",
323
+ description: "Permanently deletes a Thunder Client request by its ID. This action cannot be undone. Returns the deleted request's name, method, and URL on success. Use listCollections to obtain the request ID before calling.",
324
+ schema: z.object({
325
+ reqId: z.string().min(1, "reqId is required")
326
+ .describe("The _id of the request to delete. Obtain from listCollections. Example: 'e63218fb-9f0b-4619-ab3a-bd68d21b4d57'"),
327
+ projectDir: z.string().min(1, "projectDir is required")
328
+ .describe(projectDirDesc),
329
+ }),
330
+ handler: async (client, args) => client.deleteRequest(args.reqId, args.projectDir),
331
+ }),
332
+ };
333
+ // Tool annotations — signals to the MCP client how to handle each tool
334
+ // readOnlyHint: true — never writes data
335
+ // destructiveHint: true — action cannot be undone; client should prompt for confirmation
336
+ // idempotentHint: true — safe to retry; same result if called multiple times
337
+ const toolAnnotations = {
338
+ debugInfo: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, title: "Debug Info" },
339
+ listCollections: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, title: "List Collections" },
340
+ getDetails: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, title: "Get Details" },
341
+ listEnvironments: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, title: "List Environments" },
342
+ createCollection: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, title: "Create Collection" },
343
+ createFolder: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, title: "Create Folder" },
344
+ createRequest: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, title: "Create Request" },
345
+ updateRequest: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, title: "Update Request" },
346
+ updateCollectionSettings: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, title: "Update Collection Settings" },
347
+ runRequest: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, title: "Run Request" },
348
+ runCollection: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, title: "Run Collection" },
349
+ deleteRequest: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, title: "Delete Request" },
54
350
  };
55
351
  export const tools = Object.values(toolDefinitions).map(def => ({
56
352
  name: def.name,
57
353
  description: def.description.trim(),
58
354
  inputSchema: zodToMCPInputSchema(def.schema),
355
+ ...(toolAnnotations[def.name] && { annotations: toolAnnotations[def.name] }),
59
356
  }));
60
357
  export const toolHandlers = Object.fromEntries(Object.values(toolDefinitions).map(def => [def.name, def]));
61
358
  export const toolNames = Object.fromEntries(Object.entries(toolDefinitions).map(([key, def]) => [key.toUpperCase(), def.name]));
@@ -1,8 +1,4 @@
1
+ import { Tool } from "@modelcontextprotocol/sdk/types.js";
1
2
  import { z } from "zod";
2
- export declare function zodToMCPInputSchema(schema: z.ZodSchema): {
3
- type: "object";
4
- properties?: Record<string, any>;
5
- required?: string[];
6
- description?: string;
7
- };
3
+ export declare function zodToMCPInputSchema(schema: z.ZodSchema): Tool["inputSchema"];
8
4
  //# sourceMappingURL=schema-converter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema-converter.d.ts","sourceRoot":"","sources":["../../src/utils/schema-converter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG;IACtD,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB,CAuDA"}
1
+ {"version":3,"file":"schema-converter.d.ts","sourceRoot":"","sources":["../../src/utils/schema-converter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oCAAoC,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,CAAC,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,CAwB5E"}
@@ -1,51 +1,23 @@
1
- import { zodToJsonSchema } from "zod-to-json-schema";
2
1
  export function zodToMCPInputSchema(schema) {
3
2
  try {
4
- const jsonSchema = zodToJsonSchema(schema, {
5
- target: "jsonSchema7",
6
- $refStrategy: "none",
7
- definitions: {},
8
- });
9
- let actualSchema = jsonSchema;
10
- // If it has a $ref, extract the actual schema from definitions
11
- if (typeof jsonSchema === "object" && jsonSchema !== null) {
12
- if ("$ref" in jsonSchema && jsonSchema.definitions) {
13
- const refPath = jsonSchema.$ref;
14
- const definitionKey = refPath.replace("#/definitions/", "");
15
- if (jsonSchema.definitions[definitionKey]) {
16
- actualSchema = jsonSchema.definitions[definitionKey];
17
- }
18
- }
19
- }
20
- // Ensure it's an object schema (MCP requirement)
21
- if (typeof actualSchema === "object" &&
22
- actualSchema !== null &&
23
- actualSchema.type === "object") {
24
- const objectSchema = actualSchema;
3
+ // Zod v4 has toJSONSchema() built in — use it directly
4
+ const jsonSchema = schema.toJSONSchema?.();
5
+ if (jsonSchema && jsonSchema.type === "object") {
25
6
  return {
26
7
  type: "object",
27
- properties: objectSchema.properties || {},
28
- required: Array.isArray(objectSchema.required)
29
- ? objectSchema.required
30
- : [],
31
- ...(objectSchema.description && {
32
- description: objectSchema.description,
33
- }),
8
+ properties: jsonSchema.properties || {},
9
+ required: Array.isArray(jsonSchema.required) ? jsonSchema.required : [],
10
+ ...(jsonSchema.description && { description: jsonSchema.description }),
34
11
  };
35
12
  }
36
- // Fallback for non-object schemas
37
- return {
38
- type: "object",
39
- properties: {},
40
- required: [],
41
- };
13
+ // Fallback if schema is wrapped (e.g. ZodEffects from .refine())
14
+ // Extract the inner schema's JSON and return it
15
+ if (jsonSchema) {
16
+ return jsonSchema;
17
+ }
42
18
  }
43
19
  catch (error) {
44
- console.warn(`Failed to convert schema for tool, using fallback:`, error);
45
- return {
46
- type: "object",
47
- properties: {},
48
- required: [],
49
- };
20
+ console.warn("Failed to convert schema:", error);
50
21
  }
22
+ return { type: "object", properties: {}, required: [] };
51
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "thunderclient-mcp",
3
- "version": "1.0.12",
3
+ "version": "2.0.1",
4
4
  "description": "Thunder Client MCP Server",
5
5
  "main": "dist/index.js`",
6
6
  "types": "dist/index.d.ts",
@@ -12,6 +12,7 @@
12
12
  ],
13
13
  "scripts": {
14
14
  "build": "tsc",
15
+ "watch": "tsc --watch",
15
16
  "prepublishOnly": "rimraf dist && tsc",
16
17
  "postinstall": "npm install -g @thunderclient/cli@latest"
17
18
  },
@@ -19,7 +20,7 @@
19
20
  "thunderclient-mcp": "dist/index.js"
20
21
  },
21
22
  "author": "Thunder Client Limited",
22
- "homepage": "https://www.thunderclient.com",
23
+ "homepage": "https://docs.thunderclient.com/mcp",
23
24
  "license": "MIT",
24
25
  "repository": {
25
26
  "type": "git",
@@ -1,7 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(npm run build)"
5
- ]
6
- }
7
- }
Binary file