Skip to content

Commit 072f5c4

Browse files
committed
add test for insiders mode handling in ServerTool schema
1 parent 2d186da commit 072f5c4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

pkg/inventory/registry_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"testing"
88

9+
"github.com/google/jsonschema-go/jsonschema"
910
"github.com/modelcontextprotocol/go-sdk/mcp"
1011
"github.com/stretchr/testify/require"
1112
)
@@ -1832,3 +1833,51 @@ func TestWithTools_DeprecatedAliasAndFeatureFlag(t *testing.T) {
18321833
t.Errorf("Flag ON: Expected new_tool (via alias), got %s", availableOn[0].Tool.Name)
18331834
}
18341835
}
1836+
1837+
func TestWithInsidersMode(t *testing.T) {
1838+
// Create a tool with a jsonschema.Schema that has show_ui
1839+
toolWithShowUI := NewServerToolFromHandler(
1840+
mcp.Tool{
1841+
Name: "test_tool",
1842+
InputSchema: &jsonschema.Schema{
1843+
Type: "object",
1844+
Properties: map[string]*jsonschema.Schema{
1845+
"show_ui": {
1846+
Type: "boolean",
1847+
Description: "Show UI",
1848+
},
1849+
"owner": {
1850+
Type: "string",
1851+
Description: "Owner",
1852+
},
1853+
},
1854+
},
1855+
},
1856+
testToolsetMetadata("test"),
1857+
func(_ any) mcp.ToolHandler {
1858+
return func(_ context.Context, _ *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
1859+
return nil, nil
1860+
}
1861+
},
1862+
)
1863+
1864+
tools := []ServerTool{toolWithShowUI}
1865+
1866+
// Test with insiders mode disabled - show_ui should be stripped
1867+
regNoInsiders := mustBuild(t, NewBuilder().SetTools(tools).WithInsidersMode(false))
1868+
toolsNoInsiders := regNoInsiders.AllTools()
1869+
require.Len(t, toolsNoInsiders, 1)
1870+
schema, ok := toolsNoInsiders[0].Tool.InputSchema.(*jsonschema.Schema)
1871+
require.True(t, ok, "Schema should be *jsonschema.Schema")
1872+
require.Nil(t, schema.Properties["show_ui"], "show_ui should be stripped when insiders mode is disabled")
1873+
require.NotNil(t, schema.Properties["owner"], "owner should still exist")
1874+
1875+
// Test with insiders mode enabled - show_ui should remain
1876+
regWithInsiders := mustBuild(t, NewBuilder().SetTools(tools).WithInsidersMode(true))
1877+
toolsWithInsiders := regWithInsiders.AllTools()
1878+
require.Len(t, toolsWithInsiders, 1)
1879+
schemaInsiders, ok := toolsWithInsiders[0].Tool.InputSchema.(*jsonschema.Schema)
1880+
require.True(t, ok, "Schema should be *jsonschema.Schema")
1881+
require.NotNil(t, schemaInsiders.Properties["show_ui"], "show_ui should remain when insiders mode is enabled")
1882+
require.NotNil(t, schemaInsiders.Properties["owner"], "owner should still exist")
1883+
}

0 commit comments

Comments
 (0)