Skip to content

Commit 1f4d35f

Browse files
fix: properly handle object type parameters in tools
- Add special handling for object type parameters - Parse JSON input for object parameters - Maintain raw input if JSON parsing fails - Fixes modelcontextprotocol#110 Co-Authored-By: [email protected] <[email protected]>
1 parent eb70539 commit 1f4d35f

File tree

1 file changed

+41
-8
lines changed

1 file changed

+41
-8
lines changed

client/src/components/ToolsTab.tsx

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@ const ToolsTab = ({
159159
{key}
160160
</Label>
161161
{
162-
/* @ts-expect-error value type is currently unknown */
162+
// @ts-expect-error Tool schema types are not fully typed
163163
value.type === "string" ? (
164164
<Textarea
165165
id={key}
166166
name={key}
167-
// @ts-expect-error value type is currently unknown
168-
placeholder={value.description}
167+
placeholder={
168+
// @ts-expect-error Tool schema types are not fully typed
169+
value.description
170+
}
169171
onChange={(e) =>
170172
setParams({
171173
...params,
@@ -174,19 +176,50 @@ const ToolsTab = ({
174176
}
175177
className="mt-1"
176178
/>
179+
) :
180+
// @ts-expect-error Tool schema types are not fully typed
181+
value.type === "object" ? (
182+
<Textarea
183+
id={key}
184+
name={key}
185+
placeholder={
186+
// @ts-expect-error Tool schema types are not fully typed
187+
value.description
188+
}
189+
onChange={(e) => {
190+
try {
191+
const parsed = JSON.parse(e.target.value);
192+
setParams({
193+
...params,
194+
[key]: parsed,
195+
});
196+
} catch (err) {
197+
// If invalid JSON, store as string - will be validated on submit
198+
setParams({
199+
...params,
200+
[key]: e.target.value,
201+
});
202+
}
203+
}}
204+
className="mt-1"
205+
/>
177206
) : (
178207
<Input
179-
// @ts-expect-error value type is currently unknown
180-
type={value.type === "number" ? "number" : "text"}
208+
type={
209+
// @ts-expect-error Tool schema types are not fully typed
210+
value.type === "number" ? "number" : "text"
211+
}
181212
id={key}
182213
name={key}
183-
// @ts-expect-error value type is currently unknown
184-
placeholder={value.description}
214+
placeholder={
215+
// @ts-expect-error Tool schema types are not fully typed
216+
value.description
217+
}
185218
onChange={(e) =>
186219
setParams({
187220
...params,
188221
[key]:
189-
// @ts-expect-error value type is currently unknown
222+
// @ts-expect-error Tool schema types are not fully typed
190223
value.type === "number"
191224
? Number(e.target.value)
192225
: e.target.value,

0 commit comments

Comments
 (0)