Custom Tool Configuration Error in Embedded Sanity Studio Setup

14 replies
Last updated: Aug 10, 2023
Hi
user Q
,
I am back with a small help for the error which I am getting. I am trying to create a custom tool by following this documentations.


https://www.sanity.io/docs/studio-tools
And I am getting this error, I think it is because I am not using the configuration where the studio runs on port 3333, I am running studio on localhost:3000/studio/desk configurations.

current config file


export default defineConfig({

studio: {

components: {

toolMenu: (props) => {

const {tools, renderDefault} = props

return renderDefault({

...props,

tools: [...tools,myCustomTool()],

})

},

},

},

//other items

})
AI Update

I can see the issue in your code! You're trying to add a custom tool through studio.components.toolMenu, but that's not the correct approach. The toolMenu component is for customizing how the tool menu renders, not for adding new tools themselves.

The correct way is to add your custom tool directly to the tools array at the root level of your config, not through studio.components.

Here's how to fix it:

First, define your custom tool (as an object, not a function):

import { Card, Text } from '@sanity/ui'

const MyCustomComponent = () => {
  return (
    <Card padding={4}>
      <Text>My custom tool content</Text>
    </Card>
  )
}

export const myCustomTool = {
  name: 'my-custom-tool',
  title: 'My Custom Tool',
  component: MyCustomComponent,
  icon: () => '🔧', // optional icon
}

Then add it to your config's tools array:

import { defineConfig } from 'sanity'
import { myCustomTool } from './myCustomTool'

export default defineConfig({
  // ... other config like projectId, dataset, etc.
  
  tools: [
    myCustomTool,
    // other default tools will still be included
  ],
  
  // ... rest of your config
})

Or if you want to preserve all existing tools and add yours:

export default defineConfig({
  tools: (prev) => [...prev, myCustomTool],
  // ... other config
})

Key points:

  • Remove the studio.components.toolMenu customization entirely
  • myCustomTool should be an object with name, title, and component properties (not a function call like myCustomTool())
  • Add it to the tools array at the root of defineConfig(), not inside studio.components

This approach works regardless of whether your Studio runs on port 3333 or at /studio on localhost:3000 - the routing configuration doesn't affect how you define tools.

For more details, check out the official Studio tools documentation and the Tool API reference.

Show original thread
14 replies
you’re not following the configuration correctly
try doing exactly like they showed you first
so you need to create
myCustomTool()
from the first example and pass it into the
tools
prop. the error im seeing here makes me think you dont have
title: 'My Custom Tool',
name: 'my-custom-tool', // localhost:3333/my-custom-tool
declared in your tool. it needs those props to set the navigation of the tool
Hi
user J
I have that created -

const myCustomTool = () =&gt; {
return {
title: 'My Custom Tool',
name: 'my-custom-tool', // localhost:3333/my-custom-tool
icon: Card,
component: (props) =&gt; (
&lt;div&gt;
fefef
&lt;/div&gt;
),
}
}
Entire file
ok but you are pulling the myCustomTool() into the wrong key. that bit they are talking about is only to order the navigation. and you’re doing it wrong based on the example shown. get this working first before you dive into navigation ordering. https://share.cleanshot.com/fB3X84l8
you dont need
studio: ….
to get the tool working
that bit you’re doing doesn’t make sense anyway because it already orders the navigation in that exact order.
I see what you mean!
Thank you!
just remove
studio:
entirely and use the config shown in the example. you also need to have all that other config to make sanity work like dataset and projectid
it is resolved now!
Yes perfect!
@(Removed Name), great -- looks
user J
got you tuned in on this well -- and, it works, always good 🙂
Cheers to both,
(Removed Name)

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?