Skip to content

Conversation

gregnr
Copy link
Collaborator

@gregnr gregnr commented Apr 7, 2025

When defining a tool call, you can give a param a default value but it doesn't actually use it if the param was omitted. This fixes that.

const server = createMcpServer({
  name: 'test-server',
  version: '0.0.0',
  tools: {
    search: tool({
      description: 'Search text',
      parameters: z.object({
        query: z.string(),
        caseSensitive: z.boolean().default(false),
      }),
      execute: async (args) => {
        return args;
      },
    }),
  },
});

// Call the tool without the optional parameter
const result = await callTool({
  name: 'search',
  arguments: {
    query: 'hello',
  },
});

expect(result).toEqual({
  query: 'hello',
  caseSensitive: false,
});

@gregnr gregnr changed the title fix: tool param set to default value when omitted fix: tool param not set to default value when omitted Apr 7, 2025
@gregnr gregnr merged commit db35622 into main Apr 7, 2025
1 check passed
GQAdonis pushed a commit to skytok-net/supabase-mcp that referenced this pull request Aug 14, 2025
…tool-default-values

fix: tool param not set to default value when omitted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants